Я новичок в мониторинге показателей.
Если мы хотим записать продолжительность запросов, я думаю, мы должны использовать gauge
, но на практике кто-то будет использовать histogram
.
например, в grpc-ecosystem/go-grpc-prometheus
они предпочитают использовать histogram
для записи продолжительности. Существуют ли согласованные передовые методы использования типов метрик? Или это просто их собственные предпочтения.
// ServerMetrics represents a collection of metrics to be registered on a
// Prometheus metrics registry for a gRPC server.
type ServerMetrics struct {
serverStartedCounter *prom.CounterVec
serverHandledCounter *prom.CounterVec
serverStreamMsgReceived *prom.CounterVec
serverStreamMsgSent *prom.CounterVec
serverHandledHistogramEnabled bool
serverHandledHistogramOpts prom.HistogramOpts
serverHandledHistogram *prom.HistogramVec
}
Спасибо~
Я новичок в этом, но позвольте мне попытаться ответить на ваш вопрос. Так что отнеситесь к моему ответу с долей скепсиса или, может быть, кто-то с опытом использования метрик для наблюдения за их системами.
как указано в https://prometheus.io/docs/concepts/metric_types/
A gauge is a metric that represents a single numerical value that can arbitrarily go up and down. So if your goal would be to display the current value (duration time of requests) you could use a gauge. But I think the goal of using metrics is to find problems within your system or generate alerts if and when certain vaules aren't in a predefined range or getting a performance value (like the Apdex score) for your system.
Из https://prometheus.io/docs/concepts/metric_types/#histogram
Use the histogram_quantile() function to calculate quantiles from histograms or even aggregations of histograms. A histogram is also suitable to calculate an Apdex score.
От https://en.wikipedia.org/wiki/Апдекс
Apdex (Application Performance Index) is an open standard developed by an alliance of companies for measuring performance of software applications in computing. Its purpose is to convert measurements into insights about user satisfaction, by specifying a uniform way to analyze and report on the degree to which measured performance meets user expectations.
Ознакомьтесь с квантилями и вычислениями в гистограммах и сводках https://prometheus.io/docs/practices/histograms/#quantiles
Два эмпирических правила:
Или как сказал Адам Вудбек в своей книге «Сетевое программирование на Go»:
The general advice is to use summaries when you don’t know the range of expected values, but I’d advise you to use histograms whenever possible so that you can aggregate histograms on the metrics server.