yamlprometheussnmpexporter

How to merge labels from different metrics into one specific metric in Prometheus


I am trying to merge labels from different oid's into one for each location ( if its possible a custom named one ) there is common value between all of the oid-s.

So instead of this massive thing i would get

# HELP pd_RG RG name - 1.3.6.1.4.1.22274.1.2.1.1.3
# TYPE pd_RG gauge
pd_RG{pd_RG="Pool_01_SSD",pd_location="1"} 1
pd_RG{pd_RG="Pool_01_SSD",pd_location="2"} 1
pd_RG{pd_RG="Pool_01_SSD",pd_location="3"} 1
# HELP pd_command_queuing command queuing - 1.3.6.1.4.1.22274.1.2.1.1.13
# TYPE pd_command_queuing gauge
pd_command_queuing{pd_command_queuing="Enabled",pd_location="1"} 1
pd_command_queuing{pd_command_queuing="Enabled",pd_location="10"} 1
pd_command_queuing{pd_command_queuing="Enabled",pd_location="11"} 1
# HELP pd_location PD location - 1.3.6.1.4.1.22274.1.2.1.1.1
# TYPE pd_location gauge
pd_location{pd_location="0"} 1
pd_location{pd_location="1"} 1
pd_location{pd_location="10"} 1
pd_location{pd_location="11"} 1
# HELP pd_performance PD performance (size:KB) - 1.3.6.1.4.1.22274.1.2.1.1.14
# TYPE pd_performance gauge
pd_performance{pd_location="1",pd_performance="2496"} 1
pd_performance{pd_location="10",pd_performance="8148"} 1
pd_performance{pd_location="11",pd_performance="12748"} 1
# HELP pd_readahead readahead enable - 1.3.6.1.4.1.22274.1.2.1.1.12
# TYPE pd_readahead gauge
pd_readahead{pd_location="1",pd_readahead="Enabled"} 1
pd_readahead{pd_location="10",pd_readahead="Enabled"} 1
pd_readahead{pd_location="11",pd_readahead="Enabled"} 1
# HELP pd_serial serial number - 1.3.6.1.4.1.22274.1.2.1.1.8
# TYPE pd_serial gauge
pd_serial{pd_location="1",pd_serial="843IPLHT"} 1
pd_serial{pd_location="10",pd_serial="5KKLY7KGT"} 1
pd_serial{pd_location="11",pd_serial="6UHYGKGT"} 1
# HELP pd_size Size(GB) - 1.3.6.1.4.1.22274.1.2.1.1.2
# TYPE pd_size gauge
pd_size{pd_location="1",pd_size="3575"} 1
pd_size{pd_location="10",pd_size="16762"} 1
pd_size{pd_location="11",pd_size="16762"} 1
# HELP pd_standby standby timeout - 1.3.6.1.4.1.22274.1.2.1.1.11
# TYPE pd_standby gauge
pd_standby{pd_location="1",pd_standby="Disabled"} 1
pd_standby{pd_location="10",pd_standby="Disabled"} 1
pd_standby{pd_location="11",pd_standby="Disabled"} 1
# HELP pd_status status - 1.3.6.1.4.1.22274.1.2.1.1.4
# TYPE pd_status gauge
pd_status{pd_location="1",pd_status="Online"} 1
pd_status{pd_location="10",pd_status="Online"} 1
pd_status{pd_location="11",pd_status="Online"} 1
# HELP pd_status_health health - 1.3.6.1.4.1.22274.1.2.1.1.5
# TYPE pd_status_health gauge
pd_status_health{pd_location="1",pd_status_health="Good"} 1
pd_status_health{pd_location="10",pd_status_health="Good"} 1
pd_status_health{pd_location="11",pd_status_health="Good"} 1
# HELP pd_status_usage usage - 1.3.6.1.4.1.22274.1.2.1.1.6
# TYPE pd_status_usage gauge
pd_status_usage{pd_location="1",pd_status_usage="RD"} 1
pd_status_usage{pd_location="10",pd_status_usage="RD"} 1
pd_status_usage{pd_location="11",pd_status_usage="RD"} 1
# HELP pd_type type - 1.3.6.1.4.1.22274.1.2.1.1.9
# TYPE pd_type gauge
pd_type{pd_location="1",pd_type=""} 1
pd_type{pd_location="10",pd_type=""} 1
pd_type{pd_location="11",pd_type=""} 1
# HELP pd_vendor vendor - 1.3.6.1.4.1.22274.1.2.1.1.7
# TYPE pd_vendor gauge
pd_vendor{pd_location="1",pd_vendor="SAMSUNG"} 1
pd_vendor{pd_location="10",pd_vendor="WDC"} 1
pd_vendor{pd_location="11",pd_vendor="WDC"} 1
# HELP pd_write_cache write cache enable - 1.3.6.1.4.1.22274.1.2.1.1.10
# TYPE pd_write_cache gauge
pd_write_cache{pd_location="1",pd_write_cache="Enabled"} 1
pd_write_cache{pd_location="10",pd_write_cache="Enabled"} 1
pd_write_cache{pd_location="11",pd_write_cache="Enabled"} 1

Short example how should look. I did not enter all of the labels in the example but i thing this is enough to show what i would like to be.

pd_info_loc_1{pd_RG="Pool_01_SSD",pd_location="1",pd_command_queuing="Enabled",pd_performance="2496",pd_readahead="Enabled",pd_serial="843IPLHT", pd_size="3575",pd_status_health="Good"} 1  
pd_info_loc_10{pd_RG="Pool_01_SSD",pd_location="10",pd_command_queuing="Enabled",pd_performance="8148",pd_readahead="Enabled",pd_serial="5KKLY7KGT", pd_size="16762",pd_status_health="Good"} 1  
pd_info_loc_11{pd_RG="Pool_01_SSD",pd_location="11",pd_command_queuing="Enabled",pd_performance="12748",pd_readahead="Enabled",pd_serial="6UHYGKGT", pd_size="16762",pd_status_health="Good"} 1

Solution

  • This is what i was looking for.

    sum(pd_status) by (pd_location) 
      * on(pd_location) group_left(pd_RG) 
        pd_RG 
      * on(pd_location) group_left(pd_command_queuing) 
        pd_command_queuing
      * on(pd_location) group_left(pd_performance) 
        pd_performance
      * on(pd_location) group_left(pd_readahead) 
        pd_readahead
      * on(pd_location) group_left(pd_serial) 
        pd_serial
      * on(pd_location) group_left(pd_size) 
        pd_size
      * on(pd_location) group_left(pd_standby) 
        pd_standby
      * on(pd_location) group_left(pd_status) 
        pd_status
      * on(pd_location) group_left(pd_status_health) 
        pd_status_health
      * on(pd_location) group_left(pd_status_usage) 
        pd_status_usage 
      * on(pd_location) group_left(pd_type) 
        pd_type
      * on(pd_location) group_left(pd_vendor) 
        pd_vendor
      * on(pd_location) group_left(pd_write_cache) 
        pd_write_cache
    

    Grafana query options

    Grafana query options should be like this