Search in sources :

Example 1 with DataObject

use of org.commonjava.indy.metrics.zabbix.sender.DataObject in project indy by Commonjava.

the class IndyZabbixReporter method report.

@SuppressWarnings("rawtypes")
@Override
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
    final long clock = System.currentTimeMillis() / 1000;
    List<DataObject> dataObjectList = new LinkedList<DataObject>();
    for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
        DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getValue()), clock);
        dataObjectList.add(dataObject);
    }
    for (Map.Entry<String, Counter> entry : counters.entrySet()) {
        DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getCount()), clock);
        dataObjectList.add(dataObject);
    }
    for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
        Histogram histogram = entry.getValue();
        Snapshot snapshot = histogram.getSnapshot();
        addSnapshotDataObject(entry.getKey(), snapshot, clock, dataObjectList);
    }
    for (Map.Entry<String, Meter> entry : meters.entrySet()) {
        Meter meter = entry.getValue();
        addMeterDataObject(entry.getKey(), meter, clock, dataObjectList);
    }
    for (Map.Entry<String, Timer> entry : timers.entrySet()) {
        Timer timer = entry.getValue();
        addMeterDataObject(entry.getKey(), timer, clock, dataObjectList);
        addSnapshotDataObjectWithConvertDuration(entry.getKey(), timer.getSnapshot(), clock, dataObjectList);
    }
    try {
        SenderResult senderResult = indyZabbixSender.send(dataObjectList, clock);
        if (!senderResult.success()) {
            logger.warn("report metrics to zabbix not success!" + senderResult);
        } else if (logger.isDebugEnabled()) {
            logger.info("report metrics to zabbix success. " + senderResult);
        }
    } catch (IOException e) {
        logger.error("report metrics to zabbix error! " + e);
        e.printStackTrace();
    } catch (IndyMetricsException e) {
        logger.error("Indy metrics config error " + e);
        e.printStackTrace();
    } catch (IndyHttpException e) {
        logger.error("Indy http client error " + e);
        e.printStackTrace();
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) IndyHttpException(org.commonjava.indy.subsys.http.IndyHttpException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Gauge(com.codahale.metrics.Gauge) Snapshot(com.codahale.metrics.Snapshot) DataObject(org.commonjava.indy.metrics.zabbix.sender.DataObject) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Map(java.util.Map) SortedMap(java.util.SortedMap) SenderResult(org.commonjava.indy.metrics.zabbix.sender.SenderResult) IndyMetricsException(org.commonjava.indy.metrics.exception.IndyMetricsException)

Aggregations

Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1 Snapshot (com.codahale.metrics.Snapshot)1 Timer (com.codahale.metrics.Timer)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 IndyMetricsException (org.commonjava.indy.metrics.exception.IndyMetricsException)1 DataObject (org.commonjava.indy.metrics.zabbix.sender.DataObject)1 SenderResult (org.commonjava.indy.metrics.zabbix.sender.SenderResult)1 IndyHttpException (org.commonjava.indy.subsys.http.IndyHttpException)1