use of com.codahale.metrics.Histogram in project gerrit by GerritCodeReview.
the class MetricJson method init.
private void init(Metric metric, ImmutableMap<String, String> atts) {
if (metric instanceof BucketedMetric) {
BucketedMetric m = (BucketedMetric) metric;
if (m.getTotal() != null) {
init(m.getTotal(), atts);
}
Field<?>[] fieldList = m.getFields();
fields = new ArrayList<>(fieldList.length);
for (Field<?> f : fieldList) {
fields.add(new FieldJson(f));
}
buckets = makeBuckets(fieldList, m.getCells(), atts);
} else if (metric instanceof Counter) {
Counter c = (Counter) metric;
count = c.getCount();
} else if (metric instanceof Gauge) {
Gauge<?> g = (Gauge<?>) metric;
value = g.getValue();
} else if (metric instanceof Meter) {
Meter m = (Meter) metric;
count = m.getCount();
rate_1m = m.getOneMinuteRate();
rate_5m = m.getFiveMinuteRate();
rate_15m = m.getFifteenMinuteRate();
} else if (metric instanceof Timer) {
Timer m = (Timer) metric;
Snapshot s = m.getSnapshot();
count = m.getCount();
rate_1m = m.getOneMinuteRate();
rate_5m = m.getFiveMinuteRate();
rate_15m = m.getFifteenMinuteRate();
double div = Description.getTimeUnit(atts.get(Description.UNIT)).toNanos(1);
p50 = s.getMedian() / div;
p75 = s.get75thPercentile() / div;
p95 = s.get95thPercentile() / div;
p98 = s.get98thPercentile() / div;
p99 = s.get99thPercentile() / div;
p99_9 = s.get999thPercentile() / div;
min = s.getMin() / div;
max = s.getMax() / div;
std_dev = s.getStdDev() / div;
} else if (metric instanceof Histogram) {
Histogram m = (Histogram) metric;
Snapshot s = m.getSnapshot();
count = m.getCount();
p50 = s.getMedian();
p75 = s.get75thPercentile();
p95 = s.get95thPercentile();
p98 = s.get98thPercentile();
p99 = s.get99thPercentile();
p99_9 = s.get999thPercentile();
min = (double) s.getMin();
avg = (double) s.getMean();
max = (double) s.getMax();
sum = s.getMean() * m.getCount();
std_dev = s.getStdDev();
}
}
use of com.codahale.metrics.Histogram 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();
}
}
use of com.codahale.metrics.Histogram in project ddf by codice.
the class SourceMetricsImplTest method assertMetricCount.
private void assertMetricCount(String sourceId, String metricName, int expectedCount) {
String key = sourceId + "." + metricName;
SourceMetric sourceMetric = sourceMetrics.metrics.get(key);
if (sourceMetric.isHistogram()) {
Histogram histogram = (Histogram) sourceMetric.getMetric();
assertThat(histogram.getCount(), is((long) expectedCount));
} else {
Meter meter = (Meter) sourceMetric.getMetric();
assertThat(meter.getCount(), is((long) expectedCount));
}
}
use of com.codahale.metrics.Histogram in project ddf by codice.
the class SourceMetricsImpl method createMetric.
private void createMetric(String sourceId, String mbeanName, MetricType type) {
// Create source-specific metrics for this source
// (Must be done prior to creating metrics collector so that
// JMX MBean exists for collector to detect).
String key = sourceId + "." + mbeanName;
// as the local catalog provider).
if (!metrics.containsKey(key)) {
if (type == MetricType.HISTOGRAM) {
Histogram histogram = metricsRegistry.histogram(MetricRegistry.name(sourceId, mbeanName));
RrdJmxCollector collector = createGaugeMetricsCollector(sourceId, mbeanName);
metrics.put(key, new SourceMetric(histogram, collector, true));
} else if (type == MetricType.METER) {
Meter meter = metricsRegistry.meter(MetricRegistry.name(sourceId, mbeanName));
RrdJmxCollector collector = createCounterMetricsCollector(sourceId, mbeanName);
metrics.put(key, new SourceMetric(meter, collector));
} else {
LOGGER.debug("Metric {} not created because unknown metric type {} specified.", key, type);
}
} else {
LOGGER.debug("Metric {} already exists - not creating again", key);
}
}
use of com.codahale.metrics.Histogram in project dropwizard by dropwizard.
the class BootstrapTest method bringsYourOwnMetricRegistry.
@Test
public void bringsYourOwnMetricRegistry() {
final MetricRegistry newRegistry = new MetricRegistry() {
@Override
public Histogram histogram(String name) {
Histogram existed = (Histogram) getMetrics().get(name);
return existed != null ? existed : new Histogram(new UniformReservoir());
}
};
bootstrap.setMetricRegistry(newRegistry);
bootstrap.registerMetrics();
assertThat(newRegistry.getNames()).contains("jvm.buffers.mapped.capacity", "jvm.threads.count", "jvm.memory.heap.usage", "jvm.attribute.vendor", "jvm.classloader.loaded", "jvm.filedescriptor");
}
Aggregations