why can't I / how do I compute the derivative of an expression?

4,145 views
Skip to first unread message

JI Ioannidis

unread,
Apr 22, 2017, 5:19:34 PM4/22/17
to Prometheus Users
Best to use an example; this is only an example, I'm not looking for workarounds for this particular query!

I am recording the (accumulated) user CPU time (utime, field 14 in /proc/$PID/stat on Linux machines) in a metric I call iproc_utime, which has several dimensions. I can thus plot the total CPU utilization for all processes named "foo"  with the query:

sum(rate(iproc_utime{cmd="foo"} [5m])))

So far so good. This works fine in the built-in Prometheus grapher, and in Grafana. 

Now, I'm observing that the cpu utilization is sometimes climbing, and sometimes falling, so I want to compute its derivative. If I try 

deriv(sum(rate(iproc_utime{cmd="foo"} [5m]))))

I get: Error executing query: parse error at char 52: expected type range vector in call to function "deriv", got instant vector

How do I compute the derivative? Why can't the derivative of an instant vector be computed?

Thanks,

/ji

Ben Kochie

unread,
Apr 22, 2017, 5:28:35 PM4/22/17
to JI Ioannidis, Prometheus Users
The problem is that sum always returns an instant vector, and it's not possible to do nested sub queries.

However, you can record a new metric and take the deriv of that.  For example:

In a rules file:

cmd:iproc_utime:rate5m = sum by (cmd)(rate(iproc_utime[5m]))

Then you can query it later:

deriv(cmd:iproc_utime:rate5m[5m])

Notice how we're now applying two range-vector specification.  The query engine only allows direct metric names to get range-vector [5m] specifications.  This is to avoid needing to recursive sub-query evaluations.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/d145502b-26f6-4494-8224-e5d8914f03e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages