How to express a "show top N values" as a percentage

Asked by Charles Henrich

I'd like to take an expression like os:

highestMax(somestats*,10)

and have it instead of displaying the top 10 values, allow me to have each value represented as a percentage of the whole
(so if I did a stack graph it would sum to 100% and each band would be the percentage of each stat that was selected for the valuation).

Is this possible at all ?

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

Yea you should be able to achieve that by using areaMode=stacked and wrapping each metric in an asPercent(my.metrics.*, total_max_value) where total_max_value is the sum all of the metrics should add up to. asPercent yields values from 0-100 so if you want it on a different scale then wrap it in a scale() call as well.

Revision history for this message
chrismd (chrismd) said :
#2

btw total_max_value would be a literal number, ie. asPercent(foo.bar.*, 42)

Revision history for this message
Charles Henrich (charles-henrich) said :
#3

Unfortunately I don't know the total_max_value. I would like it to compute it by the values being plotted for that timeslice. The use case is essentially if you're looking at a rate per second and subdividing it into components (user types, geolocation, whatever) it would be awesome to be able to see the percentage of traffic that that subdivision represents. As the max changes every timeslice there's no way to do this as a percent right now. Any chance you could add a max_value() as a parameter that could be used instead of the constant?

Thanks!

Revision history for this message
chrismd (chrismd) said :
#4

Ah sorry I had assumed you meant percentages of some constant. Yes it actually does this too, the second argument can be a literal number or a series expression that serves as a max value that can vary over time. The sumSeies function is a good way to get the maximum over time.

areaMode=stacked&target=asPercent(my.counters.*, sumSeries(my.counters.*))

Revision history for this message
Charles Henrich (charles-henrich) said :
#5

When I try using asPercent on any * expansion I get the following assert:

 assert len(seriesList1) == 1, "asPercent series arguments must reference *exactly* 1 series"
AssertionError: asPercent series arguments must reference *exactly* 1 series

Against this: (I've also tried without the highestAverage in there)

 highestAverage(a.b.c.d[A-Z]*.metric,10)

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

Revision history for this message
chrismd (chrismd) said :
#6

Sorry I forgot that is a quirk of how asPercent() works, the first argument has to be a literal series without globs. So if your pattern foo.* matches foo.bar and foo.baz, you would have to do: areaMode=stacked&target=asPercent(foo.bar,sumSeries(foo.*))&target=asPercent(foo.baz,sumSeries(foo.*))

That should work.

Can you help with this problem?

Provide an answer of your own, or ask Charles Henrich for more information if necessary.

To post a message you must log in.