Projet

Général

Profil

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

root / plugins / arangodb / arangodb_ @ a7139bca

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

1 a7139bca Lars Kruse
#!/usr/bin/env python
2 0e6f3e6f Ralf Geschke
3
"""
4 17f78427 Lars Kruse
Plugin to monitor ArangoDB  servers. It works with the new server statistics
5 0e6f3e6f Ralf Geschke
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 17f78427 Lars Kruse
        arangodb_bytes_total		Total sent/received bytes
34 0e6f3e6f Ralf Geschke
35
36
Configuration:
37
        - No configuration required. Just enable the admin interface of ArangoDB.
38
39 17f78427 Lars Kruse
Thanks to the authors of other Python munin plugins. I've used some of
40
them as inspiring example.
41 0e6f3e6f Ralf Geschke
42
Possible todos:
43
        - support of munin-like configuration parameters
44
        - add more statistics
45 17f78427 Lars Kruse
46 0e6f3e6f Ralf Geschke
"""
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 17f78427 Lars Kruse
61 0e6f3e6f Ralf Geschke
    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 17f78427 Lars Kruse
        timeTotal = data['totalTime']['sum']
70
        timeConnection = data['connectionTime']['sum']
71
        timeRequest = data['requestTime']['sum']
72
        timeQueue = data['queueTime']['sum']
73
74 0e6f3e6f Ralf Geschke
        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 17f78427 Lars Kruse
79 0e6f3e6f Ralf Geschke
    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 17f78427 Lars Kruse
86 0e6f3e6f Ralf Geschke
    else:
87
        pass
88 17f78427 Lars Kruse
89 0e6f3e6f Ralf Geschke
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 84c28707 dipohl
        print "graph_category db"
95 0e6f3e6f Ralf Geschke
        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 84c28707 dipohl
        print "graph_category db"
102 0e6f3e6f Ralf Geschke
        print "total.label total"
103
        print "connection.label connection"
104
        print "request.label request"
105
        print "queue.label queue"
106 17f78427 Lars Kruse
107 0e6f3e6f Ralf Geschke
    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 84c28707 dipohl
        print "graph_category db"
112 0e6f3e6f Ralf Geschke
        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 17f78427 Lars Kruse
129 0e6f3e6f Ralf Geschke
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