Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use regular expression in fetching data from graphite?

Tags:

ruby

graphite

I want to fetch data from different counters from graphite in one single request like:-

summarize(site.testing_server_2.triggers_unknown.count,'1hour','sum')&format=json

summarize(site.testing_server_2.requests_failed.count,'1hour','sum')&format=json

summarize(site.testing_server_2.core_network_bad_soap.count,'1hour','sum')&format=json

and so on.. 20 more.

But I don't want to fetch

summarize(site.testing_server_2.module_xyz_abc.count,'1hour','sum')&format=json

in that request how can i do that?

This is what I tried:

summarize(site.testing_server_2.*.count,'1hour','sum')&format=json&from=-24hour

It gets json data for 'module_xyz_abc' too, but that i don't want.

like image 528
Sachin Singh Avatar asked Oct 18 '13 19:10

Sachin Singh


1 Answers

You can't use regular expressions per se, but you can use some similar (in concept and somewhat in format) matching techniques available within the Graphite Render URL API. There are a few ways you can "match" within a target's "bucket" (i.e. between the dots).

Target Matching

Asterisk * match

The asterisk can be used to match ANY -zero or more- character(s). It can be used to replace the entire bucket (site.*.test) or within the bucket (site.w*t.test). Here is an example:

site.testing_server_2.requests_*.count

This would match site.testing_server_2.requests_failed.count, site.testing_server_2.requests_success.count, site.testing_server_2.requests_blah123.count, and so forth.

Character range [a-z0-9] match

The character range match is used to match on a single character (site.w[0-9]t.test) in the target's bucket and is specified as a range or list. For example:

site.testing_server_[0-4].requests_failed.count

This would match on site.testing_server_0.requests_failed.count, site.testing_server_1.requests_failed.count, site.testing_server_2.requests_failed.count, and so forth.

Value list (group capture) {blah, test, ...} match

The value list match can be used to match anything in the list of values, in the specified portion of the target's bucket.

site.testing_server_2.{triggers_unknown,requests_failed,core_network_bad_soap}.count

This would match site.testing_server_2.triggers_unknown.count, site.testing_server_2.requests_failed.count, and site.testing_server_2.core_network_bad_soap.count. But nothing else, so site.testing_server_2.module_xyz_abc.count would not match.

Answer

Without knowing all of your bucket values it is difficult to be surgical with the approach (perhaps with a combination of the matching options), so I'll recommend just going with a value list match. This should allow you to get all of the values in one -somewhat long- request. For example (and keep in mind you'd need to include all of your values):

summarize(site.testing_server_2.{triggers_unknown,requests_failed,core_network_bad_soap}.count,'1hour','sum')&format=json&from=-24hour

For more, see Graphite Paths and Wildcards

like image 122
Matt Self Avatar answered Sep 24 '22 23:09

Matt Self