<p>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.</p>
<p>I got it working without the total with this query: <code>sum (container_memory_working_set_bytes{namespace!=&quot;&quot;}) by(namespace)</code> (see screen shot 1).</p>
<p>I needed to add the <code>{namespace!=&quot;&quot;}</code> 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!</p>
<p>How can I include a total of the memory used in the tooltip (without it appearing as a line in the chart)?</p>
<p><a href="https://i.stack.imgur.com/cKErH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cKErH.png" alt="Screen shot 1 of query" /></a>
<a href="https://i.stack.imgur.com/Cgenj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cgenj.png" alt="Screen shot 2 of query not filtered with namespace!=&quot;&quot;" /></a></p>

Whiskey
<p>I think I figured it out. I still have the query <code>sum (container_memory_working_set_bytes {namespace!=&quot;&quot;} ) by(namespace)</code>.</p>
<p>Then added a transformation &quot;Add field from calculation&quot;, 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.</p>
<pre><code>Mode = Reduce row
Field name = all selected
Calculation = Total
Alias = Total
Replace all fields = False
</code></pre>
<p>Then in the panel on the right, configure these settings:</p>
<pre><code>Graph styles &gt; Style: Lines
Graph styles &gt; Fill opacity: 40
Graph styles &gt; Stack series: Normal
Standard options &gt; Unit: Byte(IEC)
</code></pre>
<p>Finally, also in the panel on the right, add an override (see Grafana query screen shot):</p>
<pre><code>Add field override &gt; Fields with name: Total
Add override property &gt; Graph styles &gt; Stack series: 100%
</code></pre>
<p><strong>End Result</strong>
<a href="https://i.stack.imgur.com/FJVvu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FJVvu.png" alt="End result" /></a></p>
<p><strong>Grafana query</strong>
<a href="https://i.stack.imgur.com/hfuwP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hfuwP.png" alt="Grafana query" /></a></p>
<p><strong>Grafana transformations</strong>
<a href="https://i.stack.imgur.com/xwM5w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xwM5w.png" alt="Grafana transformations" /></a></p>
