Jimdo / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
281 stars 213 forks source link

Allow setting value of counter metrics #68

Closed leedm777 closed 6 years ago

leedm777 commented 6 years ago

I have the need for counter metrics that are set explicitly, instead of being incremented. I don't have access to the system tracking the metric, I only have whatever the current value is. One good example of this is to provide an uptime metric.

$u = getCurrentUptime();
$uptime = $registry->registerCounter($ns, 'uptime_seconds_total', 'Current uptime in seconds');
$uptime->set($u);
bracki commented 6 years ago

You wouldn't use a Counter but rather a Gauge for that type of thing.

$gauge = $registry->getOrRegisterGauge('test', 'some_gauge', 'it sets', ['type']);
$gauge->set(2.5, ['blue']);