forked from gws/munin-plugin-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
couchdb_disk_size
executable file
·57 lines (48 loc) · 1.46 KB
/
couchdb_disk_size
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 database disk sizes
// 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"
// could be "config" or "autoconf" mode
if (process.argv[2] !== undefined) mode = process.argv[2]
conn.databases(function(err, dbs) {
if (mode === 'autoconf') {
if (!err) {
sys.puts("yes")
} else {
sys.puts("no")
process.exit(1)
}
} else {
if (err) throw err
if (mode === 'config') {
sys.puts("graph_title CouchDB db disk sizes")
sys.puts("graph_args --base 1024")
sys.puts("graph_vlabel Disk sizes in Megabytes")
sys.puts("graph_category couchdb")
}
dbs.forEach(function(db, idx) {
if (mode === 'config') {
sys.puts(db + "_disk_size.label " + db)
sys.puts(db + "_disk_size.draw " + (idx ? "STACK" : "AREA"))
} else {
conn.database(db).info(function (err, info) {
if (err) {
sys.puts(db + "_disk_size.value U")
} else {
sys.puts(db + "_disk_size.value " + (info.disk_size || 0))
}
})
}
})
}
})
})