How can I make Arithmetic operations (division) on label values for one Metric

325 Views Asked by At

I would like to use a label value in order to calculate the throughput of one file

I receive the messages on pushgateway as follow

avg_treatment_duration{"treatment_name":"A","step":"E1","length":"1000","fileName"="file1"} 0.3s
avg_treatment_duration{"treatment_name":"A","step":"E2","length":"1000","fileName"="file1"} 0.6s
avg_treatment_duration{"treatment_name":"B","step":"E3","length":"1000","fileName"="file1"} 0.8s
avg_treatment_duration{"treatment_name":"B","step":"E4","length":"1000","fileName"="file1"} 0.6s

avg_treatment_duration{"treatment_name":"A","step":"E1","length":"3000","fileName"="file2"} 0.7s
avg_treatment_duration{"treatment_name":"A","step":"E2","length":"3000","fileName"="file2"} 0.6s
avg_treatment_duration{"treatment_name":"B","step":"E3","length":"3000","fileName"="file2"} 0.3s
avg_treatment_duration{"treatment_name":"B","step":"E4","length":"3000","fileName"="file2"} 0.6s

The values corresponds to the duration of treatment.

The operations are as follow

  1. sum of the duration per file
  2. ratio : length / sum of the duration per file (but how can I get the label value length )
  3. average of the result of step 2

For the moment, I supposed that I receive the ratio on values, so the query is

avg(sum by(fileName) (avg_treatment_duration{}))

Is it possible to get the label value for one metric per file and do arithmetic operations on it?

Thank you !

1

There are 1 best solutions below

0
markalex On

AFAIK, you can't. If you need to use labels as arguments for some arithmetic operations, you'd better expose them as separate metrics.

treatment_length{"fileName"="file1"} 1000
treatment_length{"fileName"="file2"} 3000

and later you could use query

avg(treatment_length / sum by(fileName) (avg_treatment_duration))