graphite-project / carbon

Carbon is one of the components of Graphite, and is responsible for receiving metrics over the network and writing them down to disk using a storage backend.
http://graphite.readthedocs.org/
Apache License 2.0
1.5k stars 490 forks source link

[Q] Is it possible to filter series by timestamp #921

Closed bartekpokerbartek closed 3 years ago

bartekpokerbartek commented 3 years ago

Hello, I would like to ask question about multiple series: Let's assume that I have them three.

Those are metrics generated on different concurrently working servers, but they relate to same metric (which is count from external DB). What I would like to display on my Grafana panel is the only one series which contains values with greatest timestamp of this three (last that changed). I tried using groupByNode(7, 'last'), but it selects just one serie out of those three, but not with latest timestamp. Can you help/redirect me somehow?

To visualize better let's assume that I have this three series: image

and what I would like to have is one instead which would look like (last that changed): image

zivillian commented 3 years ago

This seems not to be related to carbon but to graphite, so it would be better to ask at graphite-web.

Anyway I was interested in this problem and proved that it is possible: grafik

The details may vary, depending on your setup, metrics, value distribution and requirements, but here's what I've done:

Let's assume three series with the pattern demo.921.[0-2]. By using changed we get three series with mostly 0 but whenever one of the series changes its value we get a 1. changed(demo.921.*) grafik

This can be grouped with our original series demo.921.* using the callback multiply to get the original values for each time when one of our series changed. groupByNode(group(changed(demo.921.*), demo.921.*), 2, 'multiply') grafik

To get rid of all the zeros, we can modify our first query to keep only the ones when a value changed by applying removeBelowValue(1) groupByNode(group(removeBelowValue(changed(demo.921.*), 1), demo.921.*), 2, 'multiply') grafik

The last steps are to combine those 3 sparse series into one (I chose maxSeries), closing the gaps by keepLastValue(9999) and assigning a reasonable alias. alias(keepLastValue(maxSeries(groupByNode(group(removeBelowValue(changed(demo.921.*), 1), demo.921.*), 2, 'multiply')), 9999), 'result')

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.