-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding basic first version with one metric only. More to come...
- Loading branch information
Josh Devins
committed
Feb 24, 2011
1 parent
7d59275
commit 5bf6338
Showing
2 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
modules { | ||
module { | ||
name = "scribe_stats" | ||
language = "python" | ||
} | ||
} | ||
|
||
collection_group { | ||
|
||
collect_every = 20 | ||
time_threshold = 90 | ||
|
||
metric { | ||
name = "scribe_overall_messages_per_second" | ||
title = "avg messages/second" | ||
value_threshold = 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import subprocess | ||
import re | ||
import time | ||
|
||
from subprocess import Popen, PIPE, STDOUT | ||
|
||
descriptors = list() | ||
Debug = False | ||
|
||
last_mps_timestamp = float(0) | ||
last_mps_value = 0 | ||
|
||
def dprint(f, *v): | ||
if Debug: | ||
print >>sys.stderr, "DEBUG: "+f % v | ||
|
||
def GetOverallMessagesPerSecond(name): | ||
dprint("%s", name) | ||
|
||
global last_mps_timestamp, last_mps_value | ||
|
||
# get the current value | ||
rc, output = run_cmd(["/usr/sbin/scribe_ctrl", "counters"]) | ||
|
||
# return 0 if command fails | ||
if rc: | ||
return float(0) | ||
|
||
match = re.compile(r"^scribe_overall:received good: (\d+)$", re.MULTILINE).search(output) | ||
value = int(match.group(1)) | ||
|
||
# save current value | ||
value_diff = value - last_mps_value | ||
last_mps_value = value | ||
|
||
# calculate seconds that have passed since last call | ||
current_time = time.time() | ||
elapsed = current_time - last_mps_timestamp | ||
|
||
# save current timestamp | ||
first_run = last_mps_timestamp is 0 | ||
last_mps_timestamp = current_time | ||
|
||
if first_run: | ||
return float(0) | ||
|
||
return float(value_diff / elapsed) | ||
|
||
def run_cmd(arglist): | ||
'''Run a command and capture output.''' | ||
|
||
try: | ||
p = Popen(arglist, stdout=PIPE, stderr=PIPE) | ||
output, errors = p.communicate() | ||
except OSError, e: | ||
return (1, '') | ||
|
||
return (p.returncode, output) | ||
|
||
def metric_init(params): | ||
'''Create the metric definition dictionary object for each metric.''' | ||
|
||
global descriptors | ||
|
||
d1 = { | ||
'name': 'scribe_overall_messages_per_second', | ||
'call_back': GetOverallMessagesPerSecond, | ||
'time_max': 90, | ||
'value_type': 'float', | ||
'units': 'msg/sec', | ||
'slope': 'both', | ||
'format': '%f', | ||
'description': 'Average number of messages sent per second', | ||
'groups': 'scribe' | ||
} | ||
|
||
descriptors = [d1] | ||
return descriptors | ||
|
||
def metric_cleanup(): | ||
'''Clean up the metric module.''' | ||
pass | ||
|
||
if __name__ == '__main__': | ||
metric_init({}) | ||
|
||
# setup last timestamp as 10 seconds ago | ||
last_mps_timestamp = time.time() - 10 | ||
|
||
for d in descriptors: | ||
v = d['call_back'](d['name']) | ||
print '%s: %s' % (d['name'], v) |