-
Notifications
You must be signed in to change notification settings - Fork 4
/
librato-cli-metric-get
executable file
·45 lines (37 loc) · 1.44 KB
/
librato-cli-metric-get
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
#!/usr/bin/env node
var config = require('./modules/librato-cli-config');
var client = require('./modules/librato-cli-client');
var flow = require('./modules/librato-cli-flow');
var moment = require('moment');
var program = require('commander');
program
.usage('<metric_name_pattern> <seconds_back_to_search>')
.parse(process.argv);
var args = program.args;
if (!args.length) {
program.outputHelp();
flow.error('You must specify the name of the metric you want to get values for');
return;
}
if (args.length < 2) {
program.outputHelp();
flow.error('You should supply the number of seconds in the past to fetch values for');
return;
}
var getMetricOverSpan = function(metricName, startTime, endTime) {
var endPoint = config.baseUrl + 'v1/metrics/' + metricName +
'?start_time=' + startTime +
'&end_time=' + endTime + '&resolution=60';
client.get(endPoint, function (data, response) {
console.log(JSON.stringify(data, null, 2));
if (data.query && data.query.next_time) {
getMetricOverSpan(metricName, data.query.next_time, endTime);
}
});
};
var getMetric = function(metricName, numberOfSeconds) {
var startTime = moment().subtract(numberOfSeconds, 'seconds').unix();
var endTime = moment().unix();
getMetricOverSpan(metricName, startTime, endTime);
};
getMetric(args[0], args[1]);