Projet

Général

Profil

Révision 51864405

ID518644057e1651bc5db78b588010f003f079aac0
Parent 7cf2dda9
Enfant 5301b7f5

Ajouté par Lars Kruse il y a environ 5 ans

Plugin nutcracker_requests_: migrate to Python3, format documentation

Voir les différences:

plugins/twemproxy/nutcracker_requests_
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
#
1
#!/usr/bin/env python3
2
"""
3
=head1 NAME
12 4

  
5
nutcracker_requests_ - monitor twemproxy (aka: nutcracker)
6

  
7

  
8
=head1 CONFIGURATION
9

  
10
Config in /etc/munin/plugin-conf.d/nutcracker.conf:
11

  
12
 [nutcracker_*]
13
 env.NUTCRACKER_STATS_HOST 127.0.0.1
14
 env.NUTCRACKER_STATS_PORT 22222
15

  
16

  
17
=head1 AUTHORS
18

  
19
Copyright 2013 Edgar Veiga <edgarmveiga@gmail.com>
20

  
21
=cut
22
"""
23

  
24

  
25
import json
13 26
import socket
14
import sys
15 27
import os
28
import sys
16 29

  
17
try:
18
    import json
19
except ImportError:
20
    import simplejson as json
21 30

  
22 31
def get_stats():
23
    data = '';
32
    data = ''
24 33

  
25
    HOST = os.environ.get('NUTCRACKER_STATS_HOST', '127.0.0.1');
34
    HOST = os.environ.get('NUTCRACKER_STATS_HOST', '127.0.0.1')
26 35
    PORT = int(os.environ.get('NUTCRACKER_STATS_PORT', 22222))
27 36

  
28 37
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
29 38
    s.connect((HOST, PORT))
30 39

  
31 40
    file = s.makefile('r')
32
    data = file.readline();
41
    data = file.readline()
33 42
    s.close()
34 43

  
35
    return json.loads(data);
44
    return json.loads(data)
45

  
36 46

  
37 47
def process_data():
38
    data = get_stats();
48
    data = get_stats()
39 49
    # get pools
40
    for key, value in data.iteritems():
41
        if(type(value) == dict):
50
    for key, value in data.items():
51
        if isinstance(value, dict):
42 52
            total = 0
43 53
            # get server requests
44 54
            for pool_key, pool_value in value.items():
45
                if(type(pool_value) == dict):
55
                if isinstance(pool_value, dict):
46 56
                    total += pool_value["requests"]
47
            print "requests_"+key+".value"+" "+str(total)
57
            print("requests_" + key + ".value" + " " + str(total))
58

  
48 59

  
49 60
def process_config():
50
    print "graph_title Nutcracker requests/s"
51
    print "graph_category other"
52
    print "graph_vlabel requests/s"
61
    print("graph_title Nutcracker requests/s")
62
    print("graph_category other")
63
    print("graph_vlabel requests/s")
53 64

  
54
    data = get_stats();
65
    data = get_stats()
55 66
    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"
67
        if isinstance(value, dict):
68
            print("requests_" + key + ".label " + key)
69
            print("requests_" + key + ".type COUNTER")
70
            print("requests_" + key + ".min 0")
71

  
60 72

  
61 73
if __name__ == "__main__":
62 74
    if len(sys.argv) > 1 and sys.argv[1] == "config":
t/test-exception-wrapper.expected-failures
453 453
plugins/tor/tor_traffic
454 454
plugins/trafic_ro/trafic_ro_24h
455 455
plugins/tv/hdhomerun_
456
plugins/twemproxy/nutcracker_requests_
457 456
plugins/unicorn/unicorn_
458 457
plugins/unicorn/unicorn_memory_status
459 458
plugins/unicorn/unicorn_status

Formats disponibles : Unified diff