简体   繁体   中英

Extract specific label value in Prometheus and set this as query result value

I have a query which return resultant value in Prometheus output query and in value it return 1. I tried to google a bit but unfortunately didn't succeed in getting the required answer.

My use case is as below.

I executed following query => hrMemorySize{job="snmp-moxa"} in prometheus query browser

it give me following result ->
Element hrMemorySize{hrMemorySize="125072",instance="1.1.1.1",job="snmp-moxa"}
value 1

my requirement is to get this hrMemorySize in value or is there any way I can parse this and set output into this hrMemorySize as value.

I know in grafana we can use label_values but I am not using grafana for visualization instead we have custom build application which is using these queries.

Currently prometheus metrics types include counter, gauge, histogram, and summary. They are all numeric types.

But Prometheus labels are always Strings, so I think should be no functions to transform metric labels to metric values.

Prometheus doesn't provide functionality for converting label value to time series value. If you really need this functionality, then take a look at label_value() function provided by VictoriaMetrics - this is a Prometheus-like monitoring solution I work on.

Important note : it isn't recommended using Prometheus labels for storing potentially unbound number of unique values such as hrMemorySize in the label above, since this may lead to high cardinality issues because every unique label value generates new time series . It is much better to store the hrMemorySize label value as the metric value itself, eg hrMemorySize{instance="1.1.1.1",job="snmp-moxa"} 125072

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM