Read Kubernetes labels values in Prometheus

134 views Asked by At

As far as I understand, Prometheus does NOT natively support reading the values of k8s metadata.labels

This seems to be supported by Grafana tho - label_values()

Now let's say I do NOT have Grafana, and wanna run a promql query or run my own implemntation to get the label value

e.g.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1 
  template:
    metadata:
      labels:
        app: nginx
        app_version: "2"
...

I wanna run a promql query which returns the value of app_version -> 2 (integer if possible!)

I think with promql you can only filter the label, which ends up returning 1 - since that label exists

I'm thinking that I might need to write my own custom exporter - which exposes that metric

Is this a good idea?

(I haven't been able to find any custom exporters which reads the custom labels and returns the string yet ... please let me know if you have any suggestions)

0

There are 0 answers