How to show top 10 hosts by cpu

Hi im using telegraf to get winperfmon counters form various machines. The data is getting stored in inflxud db which is then presented.hooked to grafana on the front end side.

Im trying to only show my top 10 hosts by CPU or memory for example but struggling to do so.
Is this something i have to take care in influx or can be done in grafana easily.

Given the value is not a tag so i cannot use a where clause.


Any help will be much appreciated

Hi @zaeem_mansoor,

Would top() work for you? https://v2.docs.influxdata.com/v2.0/reference/flux/functions/built-in/transformations/selectors/top/

Hi sam im not using flux at the moment so not sure how to use that. I beleive flux is in the alpha release at the moment which im not using. Ideally all my data points are written to influx db on a 10 second interval. I have 100 servers where metrics like cpu and memory are recorded and others

I can easily graph them on grafana but when it comes to showing top n by cpu, im struggling there
Sorry im a newbie here so dont know much about Flux at all.

This is what top n gives me on grafana . Is there a way to use sub queries and what would be the syntax for it.

Oh okay, this post was tagged as InfluxDB 2 which would be using Flux by default. I think the InfluxQL implementation of top() (https://docs.influxdata.com/influxdb/v1.7/query_language/functions/#top) should still work for you.

Side note: if you’re using OSS 1.7+ or Enterprise 1.8+, you can enable Flux there as well. Note that this should be for testing/learning only. Flux is in “feature stage” and, therefore, has not gone through optimizations yet which means it hasn’t been deemed production-ready yet.

sorry apologies. yes using open source version. Will check InfluxQL implementation to see if it works

Im trying to use the below query

SELECT percentile(“Percent_Processor_Time”, 95) FROM “win_cpu” WHERE $timeFilter GROUP BY time($__interval), “host” fill(none)

From here i should be able to limit it to the top 10 host where Percent_Processor_Time >70% but cant seem to find the required sub query syntax with Top clause

I don’t think it makes sense to use top() on a percentile() as that returns only one value. Top would simply return the same value as percentile() did.

@Sam agreed but if you want to get top 10 out of 100 servers and plot there points on a graph, this query wont do the job. (unless im missing something)

The use case for me is that i have 100 servers that are plotted for a given interval.
20 of them have their Percent_Processor_Time>70%. I want to only get those servers where Percent_Processor_Time breached that threshold, get the host names and then plot them on the graph

Let me experiment a bit more. Seems like i might need to use continuous query or some other way to present that data

Below is just for illustration purposes but graphically i wont to plot something similar for Percent_Processor_Time for top 10 consumers/hosts where Percent_Processor_Time >70%

@Sam Something like below seems to be working but getting it to plot on grafana is perhaps not supported but on a graph. Thanks alot for your assistance on the matter

select PercentProcessorTime,host from (select TOP(Percent_Processor_Time,1) as PercentProcessorTime,host from win_cpu where time > now() -1m and Percent_Processor_Time > 70 group by host)

You’re right. Bottom query in the below screenshot should work (showing output of nested query to make sense of it):

Flux would look like this:

Can you see those images okay?

@Sam yes i can see the images. Flux seems much easier and cleaner. Waiting for the next version to get hands on it. thanks for your help. For now i think i’m good

@zaeem_mansoor, sounds good! Remember, you can try out Flux now against InfluxDB OSS v1.7+.

Sam