1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package com.att.dmf.mr.service.impl;
24 import java.io.IOException;
26 import org.json.JSONObject;
27 import org.springframework.stereotype.Component;
29 import com.att.dmf.mr.CambriaApiException;
30 import com.att.dmf.mr.backends.MetricsSet;
31 import com.att.dmf.mr.beans.DMaaPContext;
32 import com.att.dmf.mr.service.MetricsService;
33 import com.att.dmf.mr.utils.DMaaPResponseBuilder;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36 import com.att.nsa.metrics.CdmMeasuredItem;
41 * This will provide all the generated metrics details also it can provide the
45 * @author nilanjana.maity
50 public class MetricsServiceImpl implements MetricsService {
53 private static final EELFLogger LOG = EELFManager.getInstance().getLogger(MetricsService.class);
66 public void get(DMaaPContext ctx) throws IOException {
67 LOG.info("Inside : MetricsServiceImpl : get()");
68 final MetricsSet metrics = ctx.getConfigReader().getfMetrics();
69 DMaaPResponseBuilder.setNoCacheHeadings(ctx);
70 final JSONObject result = metrics.toJson();
71 DMaaPResponseBuilder.respondOk(ctx, result);
72 LOG.info("============ Metrics generated : " + result.toString() + "=================");
86 * @throws CambriaApiException
90 public void getMetricByName(DMaaPContext ctx, String name) throws IOException, CambriaApiException {
91 LOG.info("Inside : MetricsServiceImpl : getMetricByName()");
92 final MetricsSet metrics = ctx.getConfigReader().getfMetrics();
94 final CdmMeasuredItem item = metrics.getItem(name);
96 * check if item is null
99 throw new CambriaApiException(404, "No metric named [" + name + "].");
102 final JSONObject entry = new JSONObject();
103 entry.put("summary", item.summarize());
104 entry.put("raw", item.getRawValueString());
106 DMaaPResponseBuilder.setNoCacheHeadings(ctx);
108 final JSONObject result = new JSONObject();
109 result.put(name, entry);
111 DMaaPResponseBuilder.respondOk(ctx, result);
112 LOG.info("============ Metrics generated : " + entry.toString() + "=================");