forked from neighbourhoodie/aws-couchwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bin.js
executable file
·60 lines (57 loc) · 1.68 KB
/
bin.js
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
57
58
59
60
#!/usr/bin/env node
'use strict'
const AWSCouchWatch = require('.')
const { version } = require('./package.json')
function scanWith (watcher) {
return watcher.scan().then(function (metrics) {
console.log('%i metrics received.', metrics.length)
return watcher.upload(metrics)
}).catch(function (error) {
console.log('Error encountered:')
console.trace(error)
})
}
require('yargs')
.version(version)
.option('url', {
alias: 'u',
description: 'URL for the CouchDB cluster to scan. Defaults to the COUCH_URL environment variable.',
default: process.env.COUCH_URL || 'http://localhost:5984'
})
.option('scanDb', {
alias: 's',
description: 'Scan each database in addition to each node.',
default: false
})
.command({
command: '$0',
aliases: ['start'],
description: 'Periodically scan a CouchDB instance and upload the results to AWS CloudWatch.',
builder: function (yargs) {
yargs.option('interval', {
alias: 'i',
description: 'Interval between scanning for metrics in milliseconds.',
default: 60000 // one minute
})
},
handler: function ({ url, interval, scanDb }) {
const watcher = new AWSCouchWatch({ url, scanDb })
watcher.setup().then(() => {
setInterval(function () {
return scanWith(watcher)
}, interval)
})
}
})
.command({
command: 'scan',
description: 'Scan a CouchDB instance once and upload the results to AWS CloudWatch.',
handler: function ({ url, scanDb }) {
const watcher = new AWSCouchWatch({ url, scanDb })
watcher.setup().then(() => {
scanWith(watcher)
})
}
})
.alias('help', 'h')
.parse()