use of com.codahale.metrics.Histogram in project dropwizard by dropwizard.
the class BootstrapTest method bringsYourOwnMetricRegistry.
@Test
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");
}
use of com.codahale.metrics.Histogram in project infrautils by opendaylight.
the class MetricsFileReporter method report.
@Override
public void report(@SuppressWarnings("rawtypes") SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
try {
Calendar calendar = Calendar.getInstance();
int hourOfTheDay = calendar.get(Calendar.HOUR_OF_DAY);
int dayOfTheWeek = calendar.get(Calendar.DAY_OF_WEEK);
// retains one week worth of counters
rotateLastWeekFile(dayOfTheWeek, hourOfTheDay);
boolean append = true;
File file = createFile(dayOfTheWeek, hourOfTheDay);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, append), DEFAULT_ENCODING));
pw.print("date,");
pw.print(new Date());
pw.println();
pw.println("Counters:");
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
Counter newCounter = entry.getValue();
// avoid unnecessary write to report file
// report the counter only if there is a change
Long oldCounterObj = oldCounters.get(entry.getKey());
long oldCounter = oldCounterObj != null ? oldCounterObj.longValue() : 0;
if (newCounter.getCount() != oldCounter) {
pw.print(entry.getKey());
printWithSeparator(pw, "count", entry.getValue().getCount());
printWithSeparator(pw, "diff", entry.getValue().getCount() - oldCounter);
pw.println();
}
}
pw.println("Gauges:");
for (@SuppressWarnings("rawtypes") Map.Entry<String, Gauge> entry : gauges.entrySet()) {
pw.print(entry.getKey());
pw.println(entry.getValue().getValue());
}
pw.println("Histograms:");
for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
pw.print(entry.getKey());
printWithSeparator(pw, "count", entry.getValue().getCount());
printSampling(pw, entry.getValue());
pw.println();
}
pw.println("Meters:");
for (Map.Entry<String, Meter> entry : meters.entrySet()) {
pw.print(entry.getKey());
printMeter(pw, entry.getValue());
}
pw.println("Timers:");
for (Map.Entry<String, Timer> entry : timers.entrySet()) {
pw.print(entry.getKey());
printSampling(pw, entry.getValue());
printMeter(pw, entry.getValue());
}
pw.close();
} catch (IOException e) {
LOG.error("Failed to report counters to files", e);
}
counters.forEach((key, value) -> oldCounters.put(key, value.getCount()));
}
Aggregations