2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.metricservice.metric.impl;
28 import java.text.SimpleDateFormat;
29 import java.util.Calendar;
30 import java.util.HashMap;
31 import java.util.TimeZone;
32 import java.util.concurrent.atomic.AtomicLong;
34 import org.onap.appc.metricservice.metric.DispatchingFuntionMetric;
35 import org.onap.appc.metricservice.metric.MetricType;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
40 public class DispatchingFuntionMetricImpl implements DispatchingFuntionMetric {
42 private MetricType metricType;
43 private AtomicLong acceptedRequested = new AtomicLong();
44 private AtomicLong rejectedRequest = new AtomicLong();
46 private final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd");
47 private final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("YYYY-MM-dd:HH:mm:ss");
49 private String lastResetTime = dateTimeFormat.format(Calendar.getInstance().getTime());
50 private static final EELFLogger logger = EELFManager.getInstance().getLogger(DispatchingFuntionMetricImpl.class);
52 public DispatchingFuntionMetricImpl(String name, MetricType metricType, long acceptedRequested,
53 long rejectedRequest) {
55 this.metricType = metricType;
56 this.acceptedRequested.set(acceptedRequested);
57 this.rejectedRequest.set(rejectedRequest);
61 public void incrementAcceptedRequest() {
62 this.acceptedRequested.incrementAndGet();
66 public void incrementRejectedRequest() {
67 this.rejectedRequest.incrementAndGet();
71 public String value() {
72 logger.debug("Value is getting calculated for metric :" + this.name);
74 Calendar cal = Calendar.getInstance();
75 cal.setTimeZone(TimeZone.getTimeZone("UTC"));
76 String date = dateFormat.format(cal.getTime());
77 String value = date + "[" + acceptedRequested.get() + "," + rejectedRequest.get() + "]" + "@"
78 + (acceptedRequested.get() + rejectedRequest.get());
79 logger.debug("Current value of the metric " + this.name + " :" + value);
82 } catch (Exception e) {
83 logger.debug("Cant format the date.", e);
90 public String name() {
96 this.acceptedRequested.set(0);
97 this.rejectedRequest.set(0);
98 Calendar cal = Calendar.getInstance();
99 lastResetTime = dateTimeFormat.format(cal.getTime());
103 public MetricType type() {
104 return this.metricType;
108 public HashMap<String, String> getMetricsOutput() {
109 HashMap<String, String> dispatcherMetricResult = new HashMap<>();
110 dispatcherMetricResult.put("Total Received messages",
111 Long.toString(acceptedRequested.get() + rejectedRequest.get()));
112 dispatcherMetricResult.put("Total Rejected messages", Long.toString(rejectedRequest.get()));
113 return dispatcherMetricResult;
117 public String toString() {
122 public String getLastModified() {
123 return lastResetTime;