Applying math functions to targets

Asked by Pete Emerson

Is there a way with the existing functions to add (or multiply) a constant to all values in a series?

Right now, I have a target:

instance.cpu_idle

which is a value between 0 and 100.

I'd like to flip that upside down (create cpu_nonidle, essentially) and turn it into a fraction, so

(100-instance.cpu_idle) / 100

Can this be done with any of the existing functions, or do I need to write my own?

Once I've got this value I want to multiply two series together to create a capacity graph:

instance.requests_per_sec / (100-instance.cpu_idle) / 100)

In this way, if requests_per_sec is 300 and cpu_idle is at 50%, on the graph I see a capacity of 600 requests_per_sec (although in reality I'd give a buffer, as running a cpu pegged at 100% is asking for trouble).

Is this second part doable given the (100-instance.cpu_idle)/100 problem is solved, or is this another custom function I'd need to write?

Pete

Question information

Language:
English Edit question
Status:
Answered
For:
Graphite Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
chrismd (chrismd) said :
#1

Yes you can do this with the offset() function (grab the latest trunk code).

For (100 - instance.cpu_idle) / 100 you would do something like this:

target=scale(offset(scale(instance.cpu_idle,-1),100),0.01)

The result would be a series whose values range from 0.0 to 1.0 indicating the percentage of non-idle cpu.

As for multiplying two series there is not currently a function implemented that supports this but it would be pretty easy to do. Look in $GRAPHITE_ROOT/webapp/web/render/functions.py if your are interested.

One thing I would note about your example of calculating capacity. This would only be accurate if there is a linear relationship between cpu use and requests per second (which may not be possible to assert if you have more than one instance per machine & uneven load balancing, or multi-core machines & a threaded application, etc...). Then again, it may turn out that it works fine in practice. Plus it might still be a useful metric even if it does not exactly represent remaining capacity in requests per second. It is definitely an interesting idea.

Can you help with this problem?

Provide an answer of your own, or ask Pete Emerson for more information if necessary.

To post a message you must log in.