aboutsummaryrefslogtreecommitdiffstats
path: root/appc-metric/appc-metric-bundle
diff options
context:
space:
mode:
Diffstat (limited to 'appc-metric/appc-metric-bundle')
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java9
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java7
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java15
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java47
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java70
-rw-r--r--appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java60
6 files changed, 151 insertions, 57 deletions
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java
index b75ca2a30..83ff1f7e4 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/MetricService.java
@@ -22,8 +22,17 @@
package org.openecomp.appc.metricservice;
+import java.util.Map;
+
public interface MetricService {
MetricRegistry registry(String name);
MetricRegistry createRegistry(String name);
void dispose();
+
+ /**
+ * This API will be used to get the Map of all the registered Registry for the Metric Service
+ * @return Map<String,MetricRegistry> where String will be the name of the Metric Registry
+ * and MetricRegistry will be the actual object for that Registry
+ */
+ Map<String,MetricRegistry> getAllRegistry();
}
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java
index 6e5ca9d10..128110e91 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/impl/MetricServiceImpl.java
@@ -21,6 +21,7 @@
package org.openecomp.appc.metricservice.impl;
+import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -43,6 +44,12 @@ public class MetricServiceImpl implements MetricService {
}
@Override
+ public Map<String,MetricRegistry> getAllRegistry(){
+ return Collections.unmodifiableMap(concurrentRegistryMap);
+
+ }
+
+ @Override
public void dispose() {
//TODO
}
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java
index 10b8daacf..625d3218e 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/Metric.java
@@ -21,6 +21,8 @@
package org.openecomp.appc.metricservice.metric;
+import java.util.HashMap;
+
/**
*
* a measure of system parameter at the current moment. Each metric is identified by name.
@@ -34,4 +36,17 @@ public interface Metric {
String name();
void reset();
MetricType type();
+ /**
+ * This API will be used to get all the running Metrics Output.
+ * @return HashMap <String,String> in which
+ * the First String(Key) will be the name of the KPI property
+ * and another String(Value of the Key) will be the Value of
+ * that property for that KPI
+ */
+ HashMap<String,String> getMetricsOutput();
+ /**
+ * Return last modified date for KPI in string format
+ * @return - last modified date for KPI
+ */
+ String getLastModified();
}
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java
index c41def981..71c601c0a 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DefaultPrimitiveCounter.java
@@ -24,20 +24,28 @@ package org.openecomp.appc.metricservice.metric.impl;
import org.openecomp.appc.metricservice.metric.MetricType;
import org.openecomp.appc.metricservice.metric.PrimitiveCounter;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.concurrent.atomic.AtomicLong;
-public class DefaultPrimitiveCounter implements PrimitiveCounter{
- private String name;
- private MetricType metricType;
- private long counter;
+
+public class DefaultPrimitiveCounter implements PrimitiveCounter {
+ private String name;
+ private MetricType metricType;
+ private AtomicLong counter = new AtomicLong();
+
+ private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
+ private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
public DefaultPrimitiveCounter(String name, MetricType metricType, long counter) {
this.name = name;
this.metricType = metricType;
- this.counter = counter;
+ this.counter.set(counter);
}
public DefaultPrimitiveCounter(String name, MetricType metricType) {
- this.counter=0;
+ this.counter.set(0);
this.name = name;
this.metricType = metricType;
}
@@ -49,7 +57,7 @@ public class DefaultPrimitiveCounter implements PrimitiveCounter{
@Override
public void increment(long value) {
- this.counter+=value;
+ this.counter.incrementAndGet();
}
@Override
@@ -59,12 +67,12 @@ public class DefaultPrimitiveCounter implements PrimitiveCounter{
@Override
public void decrement(long value) {
- this.counter-=value;
+ this.counter.decrementAndGet();
}
@Override
public long value() {
- return this.counter;
+ return this.counter.get();
}
@Override
@@ -74,20 +82,29 @@ public class DefaultPrimitiveCounter implements PrimitiveCounter{
@Override
public void reset() {
- this.counter=0 ;
+ this.counter.set(0);
+ Calendar cal = Calendar.getInstance();
+ lastResetTime = dateTimeFormat.format(cal.getTime());
}
@Override
public String toString() {
- return "DefaultPrimitiveCounter{" +
- "name='" + name + '\'' +
- ", metricType=" + metricType +
- ", counter=" + counter +
- '}';
+ return "DefaultPrimitiveCounter{" + "name='" + name + '\'' + ", metricType=" + metricType + ", counter="
+ + counter.get() + '}';
}
@Override
public MetricType type() {
return this.metricType;
}
+
+ @Override
+ public HashMap<String, String> getMetricsOutput() {
+ return new HashMap<>();
+ }
+
+ @Override
+ public String getLastModified() {
+ return lastResetTime;
+ }
}
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java
index 0dd3b97bf..c41fab61f 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DispatchingFuntionMetricImpl.java
@@ -23,8 +23,9 @@ package org.openecomp.appc.metricservice.metric.impl;
import java.text.SimpleDateFormat;
import java.util.Calendar;
-import java.util.Date;
+import java.util.HashMap;
import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicLong;
import org.openecomp.appc.metricservice.metric.DispatchingFuntionMetric;
import org.openecomp.appc.metricservice.metric.MetricType;
@@ -33,45 +34,51 @@ import com.att.eelf.configuration.EELFManager;
public class DispatchingFuntionMetricImpl implements DispatchingFuntionMetric {
- private String name;
- private MetricType metricType;
- private long acceptedRequested;
- private long rejectedRequest;
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapRequestCounterMetricImpl.class);
-
- public DispatchingFuntionMetricImpl(String name, MetricType metricType, long acceptedRequested, long rejectedRequest) {
+ private String name;
+ private MetricType metricType;
+ private AtomicLong acceptedRequested = new AtomicLong();
+ private AtomicLong rejectedRequest = new AtomicLong();
+
+ private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
+ private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
+
+ private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(DispatchingFuntionMetricImpl.class);
+
+ public DispatchingFuntionMetricImpl(String name, MetricType metricType, long acceptedRequested,
+ long rejectedRequest) {
this.name = name;
this.metricType = metricType;
- this.acceptedRequested = acceptedRequested;
- this.rejectedRequest = rejectedRequest;
+ this.acceptedRequested.set(acceptedRequested);
+ this.rejectedRequest.set(rejectedRequest);
}
@Override
public void incrementAcceptedRequest() {
- this.acceptedRequested+=1;
+ this.acceptedRequested.incrementAndGet();
}
@Override
public void incrementRejectedRequest() {
- this.rejectedRequest+=1;
+ this.rejectedRequest.incrementAndGet();
}
@Override
public String value() {
logger.debug("Value is getting calculated for metric :" + this.name);
- try{
+ try {
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
- String date=dateFormat.format(cal.getTime());
- String value=date+"["+acceptedRequested+","+rejectedRequest+"]"+"@"+(acceptedRequested+rejectedRequest);
- logger.debug("Current value of the metric "+this.name+" :"+value);
- return value ;
+ String date = dateFormat.format(cal.getTime());
+ String value = date + "[" + acceptedRequested.get() + "," + rejectedRequest.get() + "]" + "@"
+ + (acceptedRequested.get() + rejectedRequest.get());
+ logger.debug("Current value of the metric " + this.name + " :" + value);
+ return value;
- }catch (Exception e){
- logger.debug("Cant format the date.");
+ } catch (Exception e) {
+ logger.debug("Cant format the date.",e);
}
- return null;
+ return null;
}
@@ -82,16 +89,33 @@ public class DispatchingFuntionMetricImpl implements DispatchingFuntionMetric {
@Override
public void reset() {
- this.acceptedRequested=0;
- this.rejectedRequest=0;
+ this.acceptedRequested.set(0);
+ this.rejectedRequest.set(0);
+ Calendar cal = Calendar.getInstance();
+ lastResetTime = dateTimeFormat.format(cal.getTime());
}
@Override
public MetricType type() {
return this.metricType;
}
+
+ @Override
+ public HashMap<String, String> getMetricsOutput() {
+ HashMap<String, String> dispatcherMetricResult = new HashMap<>();
+ dispatcherMetricResult.put("Total Received messages",
+ Long.toString(acceptedRequested.get() + rejectedRequest.get()));
+ dispatcherMetricResult.put("Total Rejected messages", Long.toString(rejectedRequest.get()));
+ return dispatcherMetricResult;
+ }
+
@Override
public String toString() {
return this.value();
}
+
+ @Override
+ public String getLastModified() {
+ return lastResetTime;
+ }
}
diff --git a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java
index 877fa6e31..dd0588afb 100644
--- a/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java
+++ b/appc-metric/appc-metric-bundle/src/main/java/org/openecomp/appc/metricservice/metric/impl/DmaapRequestCounterMetricImpl.java
@@ -23,8 +23,9 @@ package org.openecomp.appc.metricservice.metric.impl;
import java.text.SimpleDateFormat;
import java.util.Calendar;
-import java.util.Date;
+import java.util.HashMap;
import java.util.TimeZone;
+import java.util.concurrent.atomic.AtomicLong;
import org.openecomp.appc.metricservice.metric.MetricType;
import org.openecomp.appc.metricservice.metric.DmaapRequestCounterMetric;
@@ -34,41 +35,47 @@ import com.att.eelf.configuration.EELFManager;
public class DmaapRequestCounterMetricImpl implements DmaapRequestCounterMetric {
- private String name;
- private MetricType metricType;
- private long recievedMessage;
- private long publishedMessage;
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
+ private String name;
+ private MetricType metricType;
+ private AtomicLong recievedMessage = new AtomicLong();
+ private AtomicLong publishedMessage = new AtomicLong();
+
+ private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
+ private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
+
+ private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
private static final EELFLogger logger = EELFManager.getInstance().getLogger(DmaapRequestCounterMetricImpl.class);
- public DmaapRequestCounterMetricImpl(String name, MetricType metricType, long recievedMessage, long publishedMessage) {
+
+ public DmaapRequestCounterMetricImpl(String name, MetricType metricType, long recievedMessage,
+ long publishedMessage) {
this.name = name;
this.metricType = metricType;
- this.recievedMessage = recievedMessage;
- this.publishedMessage=publishedMessage;
+ this.recievedMessage.set(recievedMessage);
+ this.publishedMessage.set(publishedMessage);
}
@Override
public void incrementRecievedMessage() {
- this.recievedMessage+=1;
+ this.recievedMessage.incrementAndGet();
}
@Override
public void incrementPublishedMessage() {
- this.publishedMessage+=1;
+ this.publishedMessage.incrementAndGet();
}
@Override
public String value() {
logger.debug("Value is getting calculated for metric :" + this.name);
- try{
+ try {
Calendar cal = Calendar.getInstance();
cal.setTimeZone(TimeZone.getTimeZone("UTC"));
- String date=dateFormat.format(cal.getTime());
- String value=date+"["+recievedMessage+"],["+publishedMessage+"]";
- logger.debug("Current value of the metric "+this.name+" :"+value);
+ String date = dateFormat.format(cal.getTime());
+ String value = date + "[" + recievedMessage.get() + "],[" + publishedMessage.get() + "]";
+ logger.debug("Current value of the metric " + this.name + " :" + value);
return value;
- }catch (Exception e){
- logger.debug("Cant format the date.");
+ } catch (Exception e) {
+ logger.debug("Cant format the date.",e);
}
return null;
}
@@ -80,8 +87,10 @@ public class DmaapRequestCounterMetricImpl implements DmaapRequestCounterMetric
@Override
public void reset() {
- this.recievedMessage=0;
- this.publishedMessage=0;
+ this.recievedMessage.set(0);
+ this.publishedMessage.set(0);
+ Calendar cal = Calendar.getInstance();
+ lastResetTime = dateTimeFormat.format(cal.getTime());
}
@Override
@@ -90,7 +99,20 @@ public class DmaapRequestCounterMetricImpl implements DmaapRequestCounterMetric
}
@Override
+ public HashMap<String, String> getMetricsOutput() {
+ HashMap<String, String> dmaapMetricResult = new HashMap<>();
+ dmaapMetricResult.put("Total Received messages", Long.toString(recievedMessage.get()));
+ dmaapMetricResult.put("Total Published messages", Long.toString(publishedMessage.get()));
+ return dmaapMetricResult;
+ }
+
+ @Override
public String toString() {
return this.value();
}
+
+ @Override
+ public String getLastModified() {
+ return lastResetTime;
+ }
}