forked from gws/munin-plugin-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
couchdb_httpd_request_methods
executable file
·57 lines (49 loc) · 1.59 KB
/
couchdb_httpd_request_methods
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
// Munin plugin for CouchDB request methods
// Magic Markers for auto-configuration
// #%# family=auto
// #%# capabilities=autoconf suggest
var sys = require("sys")
, fs = require("fs")
, path = require("path")
fs.realpath(__filename, function(err, realpath) {
require.paths.unshift(path.dirname(realpath) + "/vendor")
var cradle = require("cradle")
, conn = new(cradle.Connection)
, mode = "fetch"
, verbs = ['GET', 'PUT', 'POST', 'DELETE', 'COPY', 'HEAD', 'MOVE']
// could be "config" or "autoconf" mode
if (process.argv[2] !== undefined) mode = process.argv[2]
if (mode === 'config') {
sys.puts("graph_title CouchDB httpd request methods")
sys.puts("graph_args --base 1000")
sys.puts("graph_vlabel requests / \${graph_period}")
sys.puts("graph_category couchdb")
verbs.forEach(function(verb, idx) {
sys.puts(verb + ".label HTTP " + verb)
sys.puts(verb + ".type COUNTER")
sys.puts(verb + ".min 0")
sys.puts(verb + ".max 1000000")
sys.puts(verb + ".draw " + (idx ? "STACK" : "AREA"))
})
} else {
conn.stats(function(err, stats) {
if (mode === 'autoconf') {
if (!err) {
sys.puts("yes")
} else {
sys.puts("no")
process.exit(1)
}
} else {
verbs.forEach(function(verb) {
if (err || typeof stats.httpd_request_methods[verb] === "undefined") {
sys.puts(verb + ".value U")
} else {
sys.puts(verb + ".value " + (stats.httpd_request_methods[verb].mean || 0))
}
})
}
})
}
})