Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / arangodb / arangodb_ @ 84c28707

Historique | Voir | Annoter | Télécharger (4,39 ko)

1
#!/usr/bin/python
2

    
3
"""
4
Plugin to monitor ArangoDB  servers. It works with the new server statistics 
5
interface of ArangoDB 1.3. Not every value seems senseful, but there are
6
nice graphs generated...
7

    
8
Author: Ralf Geschke <ralf@kuerbis.org>
9
Version: 2013062601
10

    
11
This program is free software: you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15

    
16
This program is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
GNU General Public License for more details.
20

    
21
You should have received a copy of the GNU General Public License
22
along with this program.  If not, see <http://www.gnu.org/licenses/>.
23

    
24
Usage:
25
        - Link or copy to /etc/munin/plugins
26
        - To enable extra graphs, also link to one or more of the
27
        possible links (given below)
28
        - Then restart munin-node
29

    
30
Links possible:
31
        arangodb_conn                   HTTP client connections
32
        arangodb_time_total		Total request/queue/connection time
33
        arangodb_bytes_total		Total sent/received bytes 
34

    
35

    
36
Configuration:
37
        - No configuration required. Just enable the admin interface of ArangoDB.
38

    
39
Thanks to the authors of other Python munin plugins. I've used some of 
40
them as inspiring example. 
41

    
42
Possible todos:
43
        - support of munin-like configuration parameters
44
        - add more statistics
45
        
46
"""
47

    
48
from os.path import basename
49
import urllib2
50
import sys
51

    
52
try:
53
    import json
54
except ImportError:
55
    import simplejson as json
56

    
57

    
58
def getServerStatus(group):
59
    raw = urllib2.urlopen( "http://127.0.0.1:8529/_admin/statistics" ).read()
60
    
61
    return json.loads( raw )[group]
62

    
63
def doData(plugin_name):
64
    if plugin_name == 'arangodb_conn':
65
        print "connections.value " + str( getServerStatus('client')["httpConnections"] )
66

    
67
    elif plugin_name== 'arangodb_time_total':
68
        data = getServerStatus('client')
69
        timeTotal = data['totalTime']['sum'] 
70
        timeConnection = data['connectionTime']['sum'] 
71
        timeRequest = data['requestTime']['sum'] 
72
        timeQueue = data['queueTime']['sum'] 
73
         
74
        print "total.value " + str(int(round(timeTotal)))
75
        print "connection.value " + str(int(round(timeConnection)))
76
        print "request.value " + str(int(round(timeRequest)))
77
        print "queue.value " + str(int(round(timeQueue)))
78
        
79
    elif plugin_name== 'arangodb_bytes_total':
80
        data = getServerStatus('client')
81
        bytesReceived = data['bytesReceived']['sum']
82
        bytesSent = data['bytesSent']['sum']
83
        print "received.value " + str(int(round(bytesReceived)))
84
        print "sent.value " + str(int(round(bytesSent)))
85
        
86
    else:
87
        pass
88
    
89
def doConfig(plugin_name):
90
    if plugin_name == 'arangodb_conn':
91
        print "graph_title ArangoDB current connections"
92
        print "graph_args --base 1000 -l 0"
93
        print "graph_vlabel connections"
94
        print "graph_category db"
95
        print "connections.label connections"
96

    
97
    elif plugin_name == 'arangodb_time_total':
98
        print "graph_title ArangoDB total time"
99
        print "graph_args --base 1000 -l 0"
100
        print "graph_vlabel seconds"
101
        print "graph_category db"
102
        print "total.label total"
103
        print "connection.label connection"
104
        print "request.label request"
105
        print "queue.label queue"
106
        
107
    elif plugin_name == 'arangodb_bytes_total':
108
        print "graph_title ArangoDB total bytes"
109
        print "graph_args --base 1024"
110
        print "graph_vlabel total bytes received (-) / sent (+)"
111
        print "graph_category db"
112
        print "graph_order received sent"
113
        print "received.graph no"
114
        print "received.draw LINE2"
115
        print "received.type DERIVE"
116
        print "received.min 0"
117
        print "received.label Bytes received"
118
        print "received.cdef received,8,*"
119
        print "sent.draw LINE2"
120
        print "sent.type DERIVE"
121
        print "sent.min 0"
122
        print "sent.label bytes"
123
        print "sent.cdef sent,8,*"
124
        print "sent.negative received"
125

    
126
    else:
127
        pass
128
     
129

    
130

    
131
plugin_name = basename(sys.argv[0])
132

    
133
if __name__ == "__main__":
134
    if len(sys.argv) > 1 and sys.argv[1] == "config":
135
        doConfig(plugin_name)
136
    else:
137
        doData(plugin_name)
138

    
139