|
|
@ -1,62 +1,4 @@ |
|
|
module.exports = function(client) { |
|
|
module.exports = function(client) { |
|
|
/* section: metric |
|
|
|
|
|
*comment: | |
|
|
|
|
|
* submit a new metric |
|
|
|
|
|
*params: |
|
|
|
|
|
* metric: the metric name |
|
|
|
|
|
* points: | |
|
|
|
|
|
* a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) |
|
|
|
|
|
* or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) |
|
|
|
|
|
* extra: | |
|
|
|
|
|
* optional, object which can contain the following keys |
|
|
|
|
|
* * host: the host source of the metric |
|
|
|
|
|
* * tags: array of "tag:value"'s to use for the metric |
|
|
|
|
|
* * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] |
|
|
|
|
|
* callback: | |
|
|
|
|
|
* function(err, res) |
|
|
|
|
|
*example: | |
|
|
|
|
|
* ```javascript
|
|
|
|
|
|
* const dogapi = require("dogapi"); |
|
|
|
|
|
* const options = { |
|
|
|
|
|
* api_key: "api_key", |
|
|
|
|
|
* app_key: "app_key" |
|
|
|
|
|
* }; |
|
|
|
|
|
* dogapi.initialize(options); |
|
|
|
|
|
* dogapi.metric.send("my.metric", 1000, function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* dogapi.metric.send("my.metric", [500, 1000], function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* const now = parseInt(new Date().getTime() / 1000); |
|
|
|
|
|
* dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* ```
|
|
|
|
|
|
*/ |
|
|
|
|
|
function send(metric, points, extra, callback) { |
|
|
|
|
|
if (arguments.length < 4 && typeof arguments[2] === 'function') { |
|
|
|
|
|
callback = extra; |
|
|
|
|
|
extra = {}; |
|
|
|
|
|
} |
|
|
|
|
|
extra = extra || {}; |
|
|
|
|
|
const series = [ |
|
|
|
|
|
{ |
|
|
|
|
|
metric, |
|
|
|
|
|
points, |
|
|
|
|
|
host: extra.host, |
|
|
|
|
|
tags: extra.tags, |
|
|
|
|
|
// DEV: For backwards compatibility, allow `metric_type`
|
|
|
|
|
|
type: extra.type || extra.metric_type |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
send_all(series, callback); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* section: metric |
|
|
/* section: metric |
|
|
*comment: | |
|
|
*comment: | |
|
|
* send a list of metrics |
|
|
* send a list of metrics |
|
|
@ -117,7 +59,6 @@ module.exports = function(client) { |
|
|
// 500 => [<timestamp>, 500]
|
|
|
// 500 => [<timestamp>, 500]
|
|
|
// [<timestamp>, 500] => unchanged
|
|
|
// [<timestamp>, 500] => unchanged
|
|
|
if (!Array.isArray(point)) { |
|
|
if (!Array.isArray(point)) { |
|
|
const now = parseInt(new Date().getTime() / 1000); |
|
|
|
|
|
point = [now, point]; |
|
|
point = [now, point]; |
|
|
} |
|
|
} |
|
|
return point; |
|
|
return point; |
|
|
@ -140,13 +81,71 @@ module.exports = function(client) { |
|
|
client.request('POST', '/series', params, callback); |
|
|
client.request('POST', '/series', params, callback); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* section: metric |
|
|
|
|
|
*comment: | |
|
|
|
|
|
* submit a new metric |
|
|
|
|
|
*params: |
|
|
|
|
|
* metric: the metric name |
|
|
|
|
|
* points: | |
|
|
|
|
|
* a single data point (e.g. `50`), an array of data points (e.g. `[50, 100]`) |
|
|
|
|
|
* or an array of `[timestamp, value]` elements (e.g. `[[now, 50], [now, 100]]`) |
|
|
|
|
|
* extra: | |
|
|
|
|
|
* optional, object which can contain the following keys |
|
|
|
|
|
* * host: the host source of the metric |
|
|
|
|
|
* * tags: array of "tag:value"'s to use for the metric |
|
|
|
|
|
* * metric_type|type: which metric type to use ("gauge" or "count") [default: gauge] |
|
|
|
|
|
* callback: | |
|
|
|
|
|
* function(err, res) |
|
|
|
|
|
*example: | |
|
|
|
|
|
* ```javascript
|
|
|
|
|
|
* const dogapi = require("dogapi"); |
|
|
|
|
|
* const options = { |
|
|
|
|
|
* api_key: "api_key", |
|
|
|
|
|
* app_key: "app_key" |
|
|
|
|
|
* }; |
|
|
|
|
|
* dogapi.initialize(options); |
|
|
|
|
|
* dogapi.metric.send("my.metric", 1000, function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* dogapi.metric.send("my.metric", [500, 1000], function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* const now = parseInt(new Date().getTime() / 1000); |
|
|
|
|
|
* dogapi.metric.send("my.metric", [[now, 1000]], function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* dogapi.metric.send("my.counter", 5, {type: "count"}, function(err, results){ |
|
|
|
|
|
* console.dir(results); |
|
|
|
|
|
* }); |
|
|
|
|
|
* ```
|
|
|
|
|
|
*/ |
|
|
|
|
|
function send(metric, points, extra, callback) { |
|
|
|
|
|
if (arguments.length < 4 && typeof arguments[2] === 'function') { |
|
|
|
|
|
callback = extra; |
|
|
|
|
|
extra = {}; |
|
|
|
|
|
} |
|
|
|
|
|
extra = extra || {}; |
|
|
|
|
|
const series = [ |
|
|
|
|
|
{ |
|
|
|
|
|
metric, |
|
|
|
|
|
points, |
|
|
|
|
|
host: extra.host, |
|
|
|
|
|
tags: extra.tags, |
|
|
|
|
|
// DEV: For backwards compatibility, allow `metric_type`
|
|
|
|
|
|
type: extra.type || extra.metric_type |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
send_all(series, callback); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* section: metric |
|
|
/* section: metric |
|
|
*comment: | |
|
|
*comment: | |
|
|
* make a metric query |
|
|
* make a metric query |
|
|
*params: |
|
|
*params: |
|
|
* from: POSIX timestamp for start of query |
|
|
* from: POSIX timestamp for start of query |
|
|
* to: POSIX timestamp for end of query |
|
|
* to: POSIX timestamp for end of query |
|
|
* query: the string query to perform (e.g. "system.cpu.idle{*}by{host}") |
|
|
|
|
|
|
|
|
* q: the string query to perform (e.g. "system.cpu.idle{*}by{host}") |
|
|
* callback: function(err, res) |
|
|
* callback: function(err, res) |
|
|
*example: | |
|
|
*example: | |
|
|
* ```javascript
|
|
|
* ```javascript
|
|
|
@ -164,12 +163,12 @@ module.exports = function(client) { |
|
|
* }); |
|
|
* }); |
|
|
* ```
|
|
|
* ```
|
|
|
*/ |
|
|
*/ |
|
|
function query(from, to, query, callback) { |
|
|
|
|
|
|
|
|
function query(from, to, q, callback) { |
|
|
const params = { |
|
|
const params = { |
|
|
query: { |
|
|
query: { |
|
|
from, |
|
|
from, |
|
|
to, |
|
|
to, |
|
|
query |
|
|
|
|
|
|
|
|
query: q |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
client.request('GET', '/query', params, callback); |
|
|
client.request('GET', '/query', params, callback); |
|
|
@ -213,7 +212,10 @@ module.exports = function(client) { |
|
|
const q = args._[6]; |
|
|
const q = args._[6]; |
|
|
query(from, to, q, callback); |
|
|
query(from, to, q, callback); |
|
|
} else { |
|
|
} else { |
|
|
callback('unknown subcommand or arguments try `dogapi metric --help` for help', false); |
|
|
|
|
|
|
|
|
return callback( |
|
|
|
|
|
'unknown subcommand or arguments try `dogapi metric --help` for help', |
|
|
|
|
|
false |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|