@Override public void processTimer(MetricName name, Timer timer, List<DataObject> dataObjectList) throws Exception { addMeterDataObject(name, timer, dataObjectList); addSnapshotDataObjectWithConvertDuration(name, timer, dataObjectList); }
@Override public void processHistogram(MetricName name, Histogram histogram, List<DataObject> dataObjectList) throws Exception { addSnapshotDataObject(name, histogram, dataObjectList); }
private void addMeterDataObject(MetricName key, Metered meter, List<DataObject> dataObjectList) { dataObjectList.add(toDataObject(key, ".count", meter.count())); dataObjectList.add(toDataObject(key, ".meanRate", convertRate(meter.meanRate()))); dataObjectList.add(toDataObject(key, ".1-minuteRate", convertRate(meter.oneMinuteRate()))); dataObjectList.add(toDataObject(key, ".5-minuteRate", convertRate(meter.fiveMinuteRate()))); dataObjectList.add(toDataObject(key, ".15-minuteRate", convertRate(meter.fifteenMinuteRate()))); }
private void addSnapshotDataObjectWithConvertDuration(MetricName key, Timer timer, List<DataObject> dataObjectList) { Snapshot snapshot = timer.getSnapshot(); dataObjectList.add(toDataObject(key, ".min", convertDuration(timer.min()))); dataObjectList.add(toDataObject(key, ".max", convertDuration(timer.max()))); dataObjectList.add(toDataObject(key, ".mean", convertDuration(timer.mean()))); dataObjectList.add(toDataObject(key, ".stddev", convertDuration(timer.stdDev()))); dataObjectList.add(toDataObject(key, ".median", convertDuration(snapshot.getMedian()))); dataObjectList.add(toDataObject(key, ".75th", convertDuration(snapshot.get75thPercentile()))); dataObjectList.add(toDataObject(key, ".95th", convertDuration(snapshot.get95thPercentile()))); dataObjectList.add(toDataObject(key, ".98th", convertDuration(snapshot.get98thPercentile()))); dataObjectList.add(toDataObject(key, ".99th", convertDuration(snapshot.get99thPercentile()))); dataObjectList.add(toDataObject(key, ".99.9th", convertDuration(snapshot.get999thPercentile()))); }
@Override public boolean enable() { if (!isClassAvailable(SENDER_CLASS)) { log.error("Tried to enable Zabbix Reporter, but class {} was not found", SENDER_CLASS); return false; } if (hostName == null) hostName = System.getenv("COMPUTERNAME"); if (hostName == null) hostName = System.getenv("HOSTNAME"); if (hostName == null) hostName = "localhost"; // note: don't go via InetAddress.getLocalHost() as that may return unexpected results or // take a long time (DNS roundtrips/timeouts) or even an exception being throws, for (HostPort hostPort : getFullHostList()) { ZabbixSender sender = new ZabbixSender(hostPort.getHost(), hostPort.getPort(), connectTimeout, socketTimeout); ZabbixReporter reporter = new ZabbixReporter(sender, hostName, prefix, name, getRealRateunit(), getRealDurationunit(), MetricPredicateTransformer.generatePredicate(getPredicate()), Clock.defaultClock()); reporter.start(getPeriod(), getRealTimeunit()); } return true; }
@Override public void processCounter(MetricName name, Counter counter, List<DataObject> dataObjectList) throws Exception { dataObjectList.add(toDataObject(name, "", counter.count())); }
@Override public void processMeter(MetricName name, Metered meter, List<DataObject> dataObjectList) throws Exception { addMeterDataObject(name, meter, dataObjectList); }
@Override public void run() { final Set<Map.Entry<MetricName, Metric>> metrics = getMetricsRegistry().allMetrics().entrySet(); try { List<DataObject> dataObjectList = new ArrayList<DataObject>(); for (Map.Entry<MetricName, Metric> entry : metrics) { final MetricName metricName = entry.getKey(); final Metric metric = entry.getValue(); if (predicate.matches(metricName, metric)) { metric.processWith(this, entry.getKey(), dataObjectList); } } SenderResult senderResult = sender.send(dataObjectList); if (!senderResult.success()) { log.warn("metrics reporting to zabbix {} unsuccessful: {}", sender.getHost(), sender.getPort(), senderResult); } else if (log.isDebugEnabled()) { log.debug("metrics reported to zabbix {} {}: {}", sender.getHost(), sender.getPort(), senderResult); } } catch (Exception e) { log.error("failed to report metrics to " + sender.getHost() + ':' + sender.getPort(), e); } } }
private void addSnapshotDataObject(MetricName key, Histogram histogram, List<DataObject> dataObjectList) { Snapshot snapshot = histogram.getSnapshot(); dataObjectList.add(toDataObject(key, ".min", histogram.min())); dataObjectList.add(toDataObject(key, ".max", histogram.max())); dataObjectList.add(toDataObject(key, ".mean", histogram.mean())); dataObjectList.add(toDataObject(key, ".stddev", histogram.stdDev())); dataObjectList.add(toDataObject(key, ".median", snapshot.getMedian())); dataObjectList.add(toDataObject(key, ".75th", snapshot.get75thPercentile())); dataObjectList.add(toDataObject(key, ".95th", snapshot.get95thPercentile())); dataObjectList.add(toDataObject(key, ".98th", snapshot.get98thPercentile())); dataObjectList.add(toDataObject(key, ".99th", snapshot.get99thPercentile())); dataObjectList.add(toDataObject(key, ".99.9th", snapshot.get999thPercentile())); }
public void processGauge(MetricName name, Gauge<?> gauge, List<DataObject> dataObjectList) throws Exception { dataObjectList.add(toDataObject(name, "", gauge.value())); }