metrics-csv-table-reporter
Capture metrics to a single csv table.
Usage
Add the following dependency to your build.sbt
:
libraryDependencies += "com.github.gchudnov" %% "metrics-csv-table-reporter" % "1.0.1"
Optionally, add github credentials and package repository resolver to build.sbt
:
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
resolvers += Resolver.url("GitHub Package Registry", url("https://maven.pkg.github.com/gchudnov/metrics-csv-table-reporter"))
// cat ~/.sbt/.credentials
// realm=GitHub Package Registry
// host=maven.pkg.github.com
// user=USER
// password=TOKEN
In your code, import com.github.gchudnov.metrics.CsvTableReporter
, construct and start the reporter:
import java.io.FileOutputStream
import com.codahale.metrics.MetricRegistry
import com.github.gchudnov.metrics.CsvTableReporter
val registry = new MetricRegistry
val outStream = new FileOutputStream("/some/path/report.csv", true)
val reporter = CsvTableReporter
.forRegistry(registry)
.outputTo(out)
.build()
reporter.writeHeader()
reporter.start(1.second.toSeconds, TimeUnit.SECONDS)
add meters, histograms to the registry
. When running, metrics output will be appended to the provided output stream.
Quick Reference
CsvTableReporter
.forRegistry(registry: MetricRegistry) // A registry to build a reporter for.
.shutdownExecutorOnStop(shutdownExecutorOnStop: Boolean) // Whether reporting executor stopped at the same time as reporter.
.scheduleOn(executor: ScheduledExecutorService) // The executor to use while scheduling reporting of metrics.
.outputTo(output: OutputStream = System.out) // Write to the given OutputStream.
.withSeparator(separator: String = ";") // Delimiter to separate the values.
.formattedFor(locale: Locale = Locale.getDefault()) // Format numbers using the given Locale.
.withClock(clock: Clock = Clock.defaultClock()) // Clock to use to get the time.
.formattedFor(timeZone: TimeZone = TimeZone.getDefault) // Format time using the given TimeZone.
.convertRatesTo(rateUnit: TimeUnit = TimeUnit.SECONDS) // Convert rates to the given time unit.
.convertDurationsTo(durationUnit: TimeUnit = TimeUnit.MILLISECONDS) // Convert durations to the given time unit.
.filter(filter: MetricFilter = MetricFilter.ALL) // Report only metrics that match the given filter.
.enabledColumns(Set[Column] = Columns.All) // Enable only specified columns in the output.
Output Fields
The output contains the following columns:
name
- name of the metric.kind
- type of the metric. one of the:gauge
,counter
,histogram
,meter
,timer
.ts
- timestamp.value
- measured value at the given time. Used bygauge
.count
- number of events which have been marked. Used bycounter
,histogram
,meter
ortimer
.max
- max value.mean
- average value.min
- min value.stddev
- standard deviation -- how measurements are spread out from the average (mean) value.p50
- median.p75
- 75th percentile.p95
- 95th percentile.p98
- 98th percentile.p99
- 99th percentile.p999
- 99.9th percentile.m1_rate
- 1-minute exponentially-weighted moving average rate, converted to[1/rate_unit]
.m5_rate
- 5-minute exponentially-weighted moving average rate, converted to[1/rate_unit]
.m15_rate
- 15-minute exponentially-weighted moving average rate, converted to[1/rate_unit]
.mean_rate
- mean rate, converted to[1/rate_unit]
.rate_unit
- time unit used to measure the rate, e.g.second
.duration_unit
- time unit used to measure the duration, e.g.milliseconds
.
Rates m1_rate
, m5_rate
, m15_rate
, mean_rate
define the throughput; - how many units (events) where processed per rate_unit
.
Metric-related columns
| kind | value | count | max | mean | min | stddev | p50 | p75 | p95 | p98 | p99 | p999 | m1_rate | m5_rate | m15_rate | mean_rate |
| --------- | ----- | ----- | --- | ---- | --- | ------ | --- | --- | --- | --- | --- | ---- | ------- | ------- | -------- | --------- |
| gauge | x | | | | | | | | | | | | | | | |
| counter | | x | | | | | | | | | | | | | | |
| histogram | | x | x | x | x | x | x | x | x | x | x | x | | | | |
| meter | | x | | | | | | | | | | | r | r | r | r |
| timer | | x | d | d | d | d | d | d | d | d | d | d | r | r | r | r |
where:
x
is a plain value.d
represents a duration in duration_units.r
represents a rate in rate_units.
Example
name;kind;ts;value;count;max;mean;min;stddev;p50;p75;p95;p98;p99;p999;m1_rate;m5_rate;m15_rate;mean_rate;rate_unit;duration_unit
as.node.ignore.left.demand;counter;1572730123847;;1;;;;;;;;;;;;;;;second;milliseconds
as.node.ignore.left.downstream-finish;counter;1572730123847;;0;;;;;;;;;;;;;;;second;milliseconds
Contact
License
Distributed under the The MIT License (MIT).