root / plugins / twemproxy / nutcracker_requests_ @ a7139bca
Historique | Voir | Annoter | Télécharger (1,61 ko)
| 1 |
#!/usr/bin/env python |
|---|---|
| 2 |
|
| 3 |
# This is a monitoring plugin for twemproxy (aka: nutcracker) |
| 4 |
# config in /etc/munin/plugin-conf.d/nutcracker.conf |
| 5 |
# |
| 6 |
# [nutcracker_*] |
| 7 |
# env.NUTCRACKER_STATS_HOST 127.0.0.1 |
| 8 |
# env.NUTCRACKER_STATS_PORT 22222 |
| 9 |
# |
| 10 |
# any questions to edgarmveiga at gmail dot com |
| 11 |
# |
| 12 |
|
| 13 |
import socket |
| 14 |
import sys |
| 15 |
import os |
| 16 |
|
| 17 |
try: |
| 18 |
import json |
| 19 |
except ImportError: |
| 20 |
import simplejson as json |
| 21 |
|
| 22 |
def get_stats(): |
| 23 |
data = ''; |
| 24 |
|
| 25 |
HOST = os.environ.get('NUTCRACKER_STATS_HOST', '127.0.0.1');
|
| 26 |
PORT = int(os.environ.get('NUTCRACKER_STATS_PORT', 22222))
|
| 27 |
|
| 28 |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 29 |
s.connect((HOST, PORT)) |
| 30 |
|
| 31 |
file = s.makefile('r')
|
| 32 |
data = file.readline(); |
| 33 |
s.close() |
| 34 |
|
| 35 |
return json.loads(data); |
| 36 |
|
| 37 |
def process_data(): |
| 38 |
data = get_stats(); |
| 39 |
# get pools |
| 40 |
for key, value in data.iteritems(): |
| 41 |
if(type(value) == dict): |
| 42 |
total = 0 |
| 43 |
# get server requests |
| 44 |
for pool_key, pool_value in value.items(): |
| 45 |
if(type(pool_value) == dict): |
| 46 |
total += pool_value["requests"] |
| 47 |
print "requests_"+key+".value"+" "+str(total) |
| 48 |
|
| 49 |
def process_config(): |
| 50 |
print "graph_title Nutcracker requests/s" |
| 51 |
print "graph_category other" |
| 52 |
print "graph_vlabel requests/s" |
| 53 |
|
| 54 |
data = get_stats(); |
| 55 |
for key, value in data.items(): |
| 56 |
if(type(value) == dict): |
| 57 |
print "requests_"+key+".label "+key |
| 58 |
print "requests_"+key+".type COUNTER" |
| 59 |
print "requests_"+key+".min 0" |
| 60 |
|
| 61 |
if __name__ == "__main__": |
| 62 |
if len(sys.argv) > 1 and sys.argv[1] == "config": |
| 63 |
process_config() |
| 64 |
else: |
| 65 |
process_data() |
