shivcena
shivcena

Reputation: 2053

How to get sum of instance for grafana query

In my grafana I am tracking the running instance of node exporter and process exporter. In that i have used the query

namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary"}

For this query I am getting multiple process running instance for node exporter and process exporter. For example for the above query i am getting the result like,

namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary",groupname="processexporter",job="processexporter"} 45678
namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary",groupname="processexporter",job="processexporter"} 98767
namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary",groupname="nodeexporter",job="nodeexporter"} 64835
namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary",groupname="nodeexporter",job="nodeexporter"} 36217

I want to alter the query to display the sum of total running instace like,

namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary",groupname="processexporter",job="processexporter"} 144445
namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary",groupname="nodeexporter",job="nodeexporter"} 101052 

Kindly assist me on how to achieve the sum value of running instance

Upvotes: 4

Views: 22040

Answers (2)

Ramin
Ramin

Reputation: 11

You can pass instance name as label to the counter and then you get sum of each instance by running:

sum by (instance) (metric_name_total)

For more information check link below:

https://community.grafana.com/t/sum-values-grup-by-instance/62414

Upvotes: 0

shivcena
shivcena

Reputation: 2053

I achieved by running the query

sum by (groupname) (namedprocess_namegroup_context_switches_total{ctxswitchtype="voluntary"})

We can use any of tags inside the sum by (use any tag) such as job, groupname, ctxswitchtype to filter

Upvotes: 11

Related Questions