I'm trying to play with summary metrics and not quiet understand where do I put summary.observe call? Here is prom-client example (you can find on npm):
const client = require('prom-client');
const summary = new client.Summary({
name: 'metric_name',
help: 'metric_help'
});
summary.observe(10);
but there is no enough info how to use it.
what does observe(10) mean?
where do I put that summary.observe(10) call? Just right after summary metric declaration or at the end of function/endpoint call like:
const client = require('prom-client');
const summary = new client.Summary({
name: 'metric_name',
help: 'metric_help'
});
summary.observe(10); // do I put it here?
async myFunc(){
await this.serviceCall();
summary.observe(10); // or here?
}
Does anybody have a good example/explanation of summary observe?
A summary is a metric type in Prometheus that can be used to monitor latencies (or other distributions like request sizes). For example, when you monitor a REST endpoint you can use a summary and configure it to provide the 95th percentile of the latency.
A summary metric is essentially a shortcut to a subtotal. It allows you to select the function to use to calculate the subtotal (that is, a summary). If you use a metric from a dataset report rather than a summary metric, the default subtotal function is used to subtotal the metric.
Prometheus has four primary metric types to query for via PromQL: counters, gauges, histograms, and summaries. These metric types fulfill the needs or requirements for most use cases, and are found in Prometheus' official client libraries: Go, Java, Ruby, and Python.
First, let's clarify what an summary is: a summary metric captures individual observations from an event and summarizes them into a number of related metric:
Taking an example: if you are measuring the response time of a service:
first, you create a summary metrics providing
foobar_request_duration_seconds
for each request, you will compute the response time of a request - this is an observation
when Prometheus scrapes you end-point, metrics are computed from the response time measures observed
foobar_request_duration_seconds_sum
: total number of seconds consumed by requestsfoobar_request_duration_seconds_count
: number of requests (note you can compute average with sum)foobar_request_duration_seconds_seconds{quantile="0.1"}
: response time 10% (... same for all configured quantiles)I hope this should help you understand the prom-client documentation:
The first example shows how to indicate the quantiles to compute
new client.Summary({
name: 'metric_name',
help: 'metric_help',
percentiles: [0.01, 0.1, 0.9, 0.99]
});
The second how to limit the window of measurements; here, measure are computed over the last 10 minutes (using 5 buckets - this impacts smoothing of values):
new client.Summary({
name: 'metric_name',
help: 'metric_help',
maxAgeSeconds: 600,
ageBuckets: 5
});
Coming back to your question, the observe()
method should be called on what you are observing.
If you want to measure some data returned by serviceCall()
, you feed it to the summary
number_bytes_exchanged = await this.serviceCall();
summary.observe(number_bytes_exchanged);
If you want to measure the time taken by service call
const observe_response_time = summary.startTimer();
await this.serviceCall();
observe_response_time();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With