Skip to content

Commit 99a5e6e

Browse files
committedFeb 19, 2012
Add test_aggregator_rules script to contrib
https://bugs.launchpad.net/graphite/+bug/893762
1 parent cef613e commit 99a5e6e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
 

‎contrib/test_aggregator_rules.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
from os.path import dirname, join, abspath
3+
4+
# Figure out where we're installed
5+
ROOT_DIR = dirname(dirname(abspath(__file__)))
6+
7+
# Make sure that carbon's 'lib' dir is in the $PYTHONPATH if we're running from source.
8+
LIB_DIR = join(ROOT_DIR, 'graphite', 'lib')
9+
sys.path.insert(0, LIB_DIR)
10+
11+
from carbon.aggregator.rules import RuleManager
12+
13+
### Basic usage
14+
if len(sys.argv) != 3:
15+
print "Usage: %s 'aggregator rule' 'line item'" % (__file__)
16+
print "\nSample invocation: %s %s %s" % \
17+
(__file__, "'<prefix>.<env>.<key>.sum.all (10) = sum <prefix>.<env>.<<key>>.sum.<node>'", 'stats.prod.js.ktime_sum.sum.host2' )
18+
sys.exit(42)
19+
20+
### cli arguments
21+
me, raw_rule, raw_metric = sys.argv
22+
23+
24+
### XXX rather whitebox, by reading the source ;(
25+
rm = RuleManager
26+
rule = rm.parse_definition( raw_rule )
27+
28+
### rule/parsed rule
29+
print "Raw rule: %s" % raw_rule
30+
print "Parsed rule: %s" % rule.regex.pattern
31+
32+
print "\n======\n"
33+
34+
### run the parse
35+
match = rule.regex.match( raw_metric )
36+
37+
print "Raw metric: %s" % raw_metric
38+
if match:
39+
print "Match dict: %s" % match.groupdict()
40+
print "Result: %s" % rule.output_template % match.groupdict()
41+
42+
else:
43+
print "ERROR: NO MATCH"

0 commit comments

Comments
 (0)
Please sign in to comment.