英文:
Prometheus - How to include comments in metrics
问题
我想在度量指标中添加动态注释,以提供有关服务的一些信息,例如操作系统版本、内核版本等。我该如何在Gauge度量类型中包含这些信息呢?
我能够添加HELP和TYPE,但无法添加操作系统版本。
**操作系统版本为xxxx**
# HELP http_request_duration_seconds 请求持续时间的直方图。
# TYPE http_request_duration_seconds 直方图
英文:
I want to add dynamic comments to metrics which gives some info on the service. Something like OS version, kernel version etc. How can I include this in the Guage metric type.
I am able to add HELP and TYPE but not the OS version.
**OS version is xxxx**
# HELP http_request_duration_seconds A histogram of the request duration.
# TYPE http_request_duration_seconds histogram
答案1
得分: 2
无论您想要在指标上添加的附加信息是什么,都可以将其作为维度(在Prometheus术语中称为标签)添加。这样,相同的指标可以在整个基础架构中使用,但您可以按照任何方式对其进行切片。例如,可以使用'cloud_zone'维度来丰富CPU_usage_percent指标,以指定它属于哪个云:
CPU_usage_percent{cloud_zone:"NYC", application_name:"video-server"}, 5, 1487578310 //来自NYC区域的指标示例
然后,您可以在Prometheus中使用以下查询对其进行切片:
CPU_usage_percent{cloud_zone="NYC"}
并且只获取您想要的指标,或者它们的总和/平均值等。从某种意义上说,这些是自我记录的。
我无耻地向您指出了我的文章,其中更详细地解释了这一点。
一种稍微不同的方法是,而不是向现有指标添加维度,您可以将其导出为新的指标,并使用虚假值(值限制为数值)在维度中编码该值。
kernel_version 0 {ip_addr:"1.1.1.1", version:"实际内核值"}
编辑:如何使用golang_client添加维度:
请参考此代码-它展示了如何添加标签,然后填充它们(第68行)- https://github.com/prometheus/client_golang/blob/master/prometheus/examples_test.go#L51
英文:
Whatever additional info you want to slap on top of the metric, add it as dimensions (labels, in Prometheus's lingo). That way the same metrics can be used across your entire infrastructure, but you can slice them anyway you want. for example,
the CPU_usage_percent metric can be enriched with the 'cloud_zone' dimension to specify which cloud it belongs to:
CPU_usage_percent{cloud_zone:”NYC”, application_name:”video-server”}, 5, 1487578310 //example of a metric from zone NYC
and then you can slice it in Prometheus with queries like:
CPU_usage_percent{cloud_zone="NYC"}
and get only the metrics you want. or their sum/average/etc.
in sense, these are self-documenting.
I shamelessly point you to my article which explains this in more detail.
An somewhat alternative approach - ie rather than adding a dimension to an existing metric - you could just export these as new metrics, with bogus values (values are limited to numeric values) and encode the value in a dimension.
kernel_version 0 {ip_addr:”1.1.1.1”, version:"the actual kernel value"}
EDIT: how to add dimensions with the golang_client:
refer to this code - it shows how to add labels and then populate them (in line 68)- https://github.com/prometheus/client_golang/blob/master/prometheus/examples_test.go#L51
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论