Nipun
Nipun

Reputation: 4319

Showing percentage in the Grafana graph histogram

I have a use case in grafana. I have a speed vs Time graph. I would like to show a histogram in grafana with 15 buckets each. The 'Y' axis instead of showing the count, should show the percentage of the total count.

How is this possible?

Upvotes: 4

Views: 11464

Answers (2)

user11889291
user11889291

Reputation:

I don't know what database you are using but lets assume you are using Prometheus and your promql is similar to below:

sum (rate (container_cpu_usage_seconds_total{id!="/",namespace=~"$Namespace",pod_name=~"^$Deployment.*$"}[1m])) by (pod_name)

This gives you the cpu usage of pods in milliunite which is 1/1000 of a cpu capacity. For changing it to percent I just need to multiply it by 100 and for that I will add * 100 to the end of query.

Now the solution to your answer: if q is your current query then you can get the percent by changing the query like this: ((q)/total) * 100

At the end as @Phil said change the units to percent.

Upvotes: 1

Phil
Phil

Reputation: 3746

In the graph panel go into the metrics pane and do the following:

  1. Set the draw mode to bar
  2. Under Axes/Left Y select Units
  3. From the Units drop-down select Misc > percent (0-100)

This will display the left Y axis in percent.

Upvotes: 1

Related Questions