<p>I am looking at this article. It mentions below query with below description.</p>
<blockquote>
<p>It is even more interesting monitoring the error rate vs the total
amount of requests, this way you get the magnitude of the errors for
the Kubernetes API server requests.</p>
</blockquote>
<pre><code>sum(rate(apiserver_request_total{job=&quot;kubernetes-apiservers&quot;,code=~&quot;[45]..&quot;}[5m]))*100/sum(rate(apiserver_request_total{job=&quot;kubernetes-apiservers&quot;}[5m]))
</code></pre>
<p>What I don't understand is why can we just compute below? Moreover, what is the purpose of applying sum function after rate? My understanding is rate is the average change per second, why sums the changes up? Can I get help on understanding the above query, it would be great to have an concrete example. Thanks in advance!</p>
<pre><code>count(apiserver_request_total{job=&quot;kubernetes-apiservers&quot;,code=~&quot;[45]..&quot;})/count(apiserver_request_total{job=&quot;kubernetes-apiservers&quot;})
</code></pre>

bunny
<p><code>rate</code> calculates per-second estimation of increase of your counter. <code>sum</code> than sums up all time series produced by <code>rate</code> into one.</p>
<p>Consider <a href="https://prometheus.demo.do.prometheus.io/graph?g0.expr=node_cpu_seconds_total&amp;g0.tab=1&amp;g0.stacked=0&amp;g0.range_input=1h&amp;g1.expr=rate(node_cpu_seconds_total%5B1m%5D)&amp;g1.tab=1&amp;g1.stacked=0&amp;g1.range_input=1h&amp;g2.expr=sum(rate(node_cpu_seconds_total%5B1m%5D))&amp;g2.tab=1&amp;g2.stacked=0&amp;g2.range_input=1h" rel="nofollow noreferrer">this demo</a>. Notice how <code>rate</code> produces eight time series (same as number of &quot;input&quot; series), while <code>sum</code> - only one.</p>
<p>Please notice also <a href="https://stackoverflow.com/a/76009728/21363224">difference between <code>sum</code> and <code>sum_over_time</code></a>, as it is often reason of confusion.</p>
<hr />
<p><code>count</code> returns number of time series within inner query. It's result more or less constant over time.</p>
<p>For demo linked above count will always return <code>vector(8)</code>, as there are always 8 modes of memory.</p>
