Reputation: 342
I have Kubernetes running (K3s on TrueNAS scale). I've deployed Prometheus and Grafana and am able to access the metrics in Grafana. I now want to create a stacked line chart that shows memory usage by namespace and total memory used by Kubenetes.
I got it working without the total with this query: sum (container_memory_working_set_bytes{namespace!=""}) by(namespace)
(see screen shot 1).
I needed to add the {namespace!=""}
or it would add an entry with the same name as the query (see screen shot 2). Don't understand what that value represents, but its not the total I'm after!
How can I include a total of the memory used in the tooltip (without it appearing as a line in the chart)?
Upvotes: 5
Views: 4916
Reputation: 342
I think I figured it out. I still have the query sum (container_memory_working_set_bytes {namespace!=""} ) by(namespace)
.
Then added a transformation "Add field from calculation", again with the defaults. I thought this would only work for the properties listed at the time of creating the transformation/query, but spinning up a new container did get it automatically added to the chart.
Mode = Reduce row
Field name = all selected
Calculation = Total
Alias = Total
Replace all fields = False
Then in the panel on the right, configure these settings:
Graph styles > Style: Lines
Graph styles > Fill opacity: 40
Graph styles > Stack series: Normal
Standard options > Unit: Byte(IEC)
Finally, also in the panel on the right, add an override (see Grafana query screen shot):
Add field override > Fields with name: Total
Add override property > Graph styles > Stack series: 100%
Upvotes: 7