forked from gws/munin-plugin-couchdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
couchdb_doc_count
executable file
·57 lines (48 loc) · 1.45 KB
/
couchdb_doc_count
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 doc count
// 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 doc count")
sys.puts("graph_args --base 1000")
sys.puts("graph_vlabel Documents")
sys.puts("graph_category couchdb")
}
dbs.forEach(function(db, idx) {
if (mode === 'config') {
sys.puts(db + "_doc_count.label " + db)
sys.puts(db + "_doc_count.draw " + (idx ? "STACK" : "AREA"))
} else {
conn.database(db).info(function (err, info) {
if (err) {
sys.puts(db + "_doc_count.value U")
} else {
sys.puts(db + "_doc_count.value " + (info.doc_count || 0))
}
})
}
})
}
})
})