brettlangdon / node-dogapi Goto Github PK
View Code? Open in Web Editor NEWDatadog API Node.JS Client
Home Page: https://brettlangdon.github.io/node-dogapi/
Datadog API Node.JS Client
Home Page: https://brettlangdon.github.io/node-dogapi/
Thanks for building this great library!
Hi, I'm building an Electron app and I'd like to collect metrics from the app. Is there any way I can use a Client Token to submit metrics? I'm playing with the API but keep getting erros that api_key is required.
The log management system and RUM can take a client token, but I haven't found a way to get their metrics APIs to accept a client token.
When I initialize dogapi with for example:
dogapi.initialize({
api_key: "12123456789012345678901234567890",
api_host: "api.datadoghq.eu"
})
Which is random API key with length of 32 chars, then it returns status: ok
after calling dogapi.metric.send_all
.
To make stuff more interesting, for api_key: 123456789012345678901234567890az
it raises an error with "Forbidden" description.
For keys with api_key.length !== 32
it's always "Forbidden".
Is this expected behaviour due to limitations of DataDog API? It's a little bit confusing for me.
I could have sworn I had written something in the readme about it, but apparently I didn't.
For reference for anyone finding this before I actually get around to adding it to the docs:
We ran into an issue #16 which is that number values returned from Datadog were larger than JSON could support, so there was lose of precision/overflowing for large numbers.
The solution was to utilize json-bigint which utilizes bignumber.js to support larger numbers in JSON.
The problem with this is that the format that bignumber.js
stores numbers in isn't the most intuitive manner.
> var bn = require('bignumber.js');
> console.dir(new bn('2349082309420934834234234'));
{ s: 1, e: 24, c: [ 23490823094, 20934834234234 ] }
For information on how to interact with bignumber.js
please see their documentation: https://www.npmjs.com/package/bignumber.js
Here is the output before JSON.parse(data) on line #100 of lib/api/client.js
{"status": "ok",
"event":
{ "priority": null,
"date_happened": 1435260251,
"handle": null, "title": "Nimbus Sanity Test",
"url": "https://app.datadoghq.com/event/event?id=2868860079149422351",
"text": "Sanity Test Datadog",
"tags": null,
"related_event_id": null,
"id": 2868860079149422351 }
}
After parsing:
{ status: 'ok',
event:
{ priority: null,
date_happened: 1435260251,
handle: null,
title: 'Nimbus Sanity Test',
url: 'https://app.datadoghq.com/event/event?id=2868860079149422351',
text: 'Sanity Test Datadog',
tags: null,
related_event_id: null,
id: 2868860079149422600 }
}
Using this librarys metric.send_all methos and sending metrics from Europe region to Datadog US site:
we get 20% success rate , 80% failures caused with timeout errors?
How can we increase timeout or add Header Connection: Keep-alive in our requests
2019-10-08T11:25:24.857Z 8d847170-26e0-42e2-a336-c7bd86fd1840 ERROR 1570533907242 'Failed send_all: Error: Client network socket disconnected before secure TLS connection was established Error: Client network socket disconnected before secure TLS connection was established\n at TLSSocket.onConnectEnd (_tls_wrap.js:1095:19)\n at Object.onceWrapper (events.js:286:20)\n at TLSSocket.emit (events.js:203:15)\n at TLSSocket.EventEmitter.emit (domain.js:448:20)\n at endReadableNT (_stream_readable.js:1145:12)\n at process._tickCallback (internal/process/next_tick.js:63:19)'
Are there any plans for integrating the service checks (http://docs.datadoghq.com/api/#service_checks)?
On this line https://github.com/brettlangdon/node-dogapi/blob/master/lib/api/metric.js#L38, I'm assuming you should be setting callback as extra
, not tags
, right? tags
is undefined.
Getting the following points with the query API for a metrics query.
[[1460670060000,{"s":1,"e":0,"c":[8,6,6,6,6,6,6,9,8,4,5,5,8,1,0,5,5]}]]
Is this related to this lib?
const now = parseInt(new Date().getTime() / 1000);
const then = now - 3600; // one hour ago
const query = '';
const response = await dogapi.metric.query(then, now, query);
console.log(`response: ${response}`);
return response;
};
it returns undefined
When I get a monitor I expect to have a state object in the response, the state includes information like the effected hosts from the alert.
dogapi.monitor.getAll(['alert'],(err, monitors) => {...
I expect:
"state": {"groups": {"host:data-tests-mongo-prod-mongo-127-conf-0": {"status": "OK", "last_triggered_ts": null, "last_nodata_ts": null, "name": "host:data-tests-mongo-prod-mongo-127-conf-0", "last_notified_ts": null, "last_resolved_ts": null}
but actually, I don't get the state object, the state object I'm showing above is from python datadog : https://github.com/DataDog/datadogpy
Any idea why it's missing?
Hey Brett,
Thanks for putting together this handy little package. My co-worker and I have been working hard to implement data-dog in our app, your package seems to report events fine but the metrics section might need to be updated... Neither of us have been able to successfully implement the metric.send() function from both the app and the command line. We scrubbed your package's code and it seems sound but we're wondering if you're aware of this issue or if we're just derping it up somehow.
code (coffeescript):
dogapi.metric.send(metric, points, extra, (err, res)->
console.log "Metric Sent! #{metric}"
if err
console.log err
console.dir res
)
the res that comes back from our function above always evaluates to the following object:
{status: 'ok'}
however the metric never appears in the data dog GUI, the events that we log using the dogapi and same app keys do show up without a hitch.
Best,
Kevin
the api has had a few changes since I wrote it, should probably do a full sweep and update to the latest.
Not sure if this is related to the api or my node setup, but I'm getting
XMLHttpRequest cannot load <link>.
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:8080' is therefore not allowed access.
I've added this to my app already:
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
I also tried running it through a proxy like in the example-
agent = new HttpsProxyAgent({
proxyHost: "localhost",
proxyPort: 8080
});
but then I get
Error: (SystemJS) Node tls module not supported in browsers.
I think that may be a separate issue as I used JSPM to install https-proxy-agent for an angularjs app.
But overall how would I get it set up to not have the XMLHttpRequest error?
Right now documentation says, that for Metrics send_all
and send
functions, we can pick one of 2 metric types:
metric_type|type: the type of metric to use ("gauge" or "count") [default: gauge]
and it's no longer true.
Since DataDog supports metric type "rate" and this library doesn't do any type validation, "rate" metric type is correctly supported by those functions.
Documentation for Metrics send_all
and send
should be:
metric_type|type: the type of metric to use ("gauge", "count" or "rate") [default: gauge]
Is there a way currently for, or how should I go about, specifying the "interval" for a metric of type "count"?
the AWS logs integration was release
https://docs.datadoghq.com/api/v1/aws-logs-integration/
could you add api to be able to manage the aws logs integration
here is the golang implementation: https://github.com/DataDog/datadog-api-client-go/blob/master/api/v1/datadog/docs/AWSLogsIntegrationApi.md
Thanks
similar to monitors, being able to CRUD synthetics would be useful
dogapi.metric.send
takes metric_type
as extra parameter and documentation specifies it can be either "gauge" or "counter", but setting it to "counter" works exactly as setting it to "gauge" (i.e. it reports constant value to the datadog).
I don't see any mentions of metric type at all in the Datadog's HTTP API docs and official API libraries (e.g. datadogpy) rely on the statsd to implement counters.
Maybe this option is obsolete? Or am I missing something?
Thanks!
The most popular fork of rc is currently run-con which is being maintained whereas rc has been deprecated. We should move to run-con
The following code will return a 202 {"status":"ok"}
from DataDog, but the metrics will not appear in DataDog. (That's a bug on their side, they seem to silently swallow the malformed points).
var metrics = [
{
metric: "some.key",
points: 8,
tags: ["environment:qa"]
},
{
metric: "some.other.key",
points: 22,
tags: ["environment:qa"]
}
];
dogapi.metric.send_all(metrics, function(err, results) {
console.log(results);
});
dogapi formats the above data into {"series":[{"metric":"some.key","points":[1455834677,8],"tags":["environment:qa"]},{"metric":"some.other.key","points":[1455834677,22],"tags":["environment:qa"]}]}
. Note that both points
keys have a single array as their values.
According to the API documentation, they expect an array of arrays for the points. Instead of "points":[1455834677,8]
, we should have "points":[[1455834677,8]]
.
Hello there,
I've noticed that since updating to 1.0.0 metrics aren't being sent correctly and I'm getting no response back in my callbacks, and no metrics are being posted.
E.G
var dogapi = require('dogapi');
dogapi.initialize({
api_key: this.config.keys.datadog.api,
app_key: this.config.keys.datadog.app
});
var metrics = [{
metric: 'loadTest.avg_response_time',
points: [1431343811, 2834],
tags: [ 'exampleTag:v1' ]
},
{
metric: 'loadTest.avg_error_rate',
points: [1431343811, 0],
tags: [ 'exampleTag:v1' ]
}];
dogapi.metric.send_all(metrics, function(err, res) {
if (err) {
return callback(new DataDogAPIError(err), res);
}
callback(false, res);
});
I get an empty response back and no error ({ response: '' }
). Comparitively If I use the REST endpoint:
curl -X POST -H "Content-type: application/json"
-d "{"series": [{
"metric": "loadTest.avg_response_time",
"points": [[1431342268, 2834], [1431342268, 2833]],
"tags": ["exampleTag:v1"]
}]}"
'https://app.datadoghq.com/api/v1/series?api_key=DD_API_KEY'
using postman I get the response
{ "status": "ok" }
in Screenboard.js the function share is not using the correct http method it should be "POST" instead of "GET"
as the current behavior wont actually share the given screen-board
function share(boardId, callback){
client.request("GET", util.format("/screen/share/%s", boardId), callback);
}
it should be
function share(boardId, callback){
client.request("POST", util.format("/screen/share/%s", boardId), callback);
}
Query is an undocumented api method that is explained here: https://gist.github.com/clofresh/a390cd2cc7509d0939f0
If lodash releases a major version that breaks any API changes that this repo relies on, consuming repos that use yarn will cause this library to break.
Could you please lock lodash to a specific version?
You will otherwise see an error message like the one below if using yarn and other dependencies that rely on lodash:
Pattern ["lodash@latest"] is trying to unpack in the same destination "~/Library/Caches/Yarn/v1/npm-lodash-4.17.5-99a92d65c0272debe8c96b6057bc8fbfa3bed511" as pattern ["lodash@^4.8.0","lodash@^4.8.0","lodash@^4.14.0","lodash@^4.8.0","lodash@^4.0.0","lodash@^4.13.1","lodash@^4.14.0","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.11.1","lodash@^4.17.4","lodash@^4.6.0","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.2.0","lodash@^4.2.0","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.17.4","lodash@^4.3.0","lodash@^4.17.4","lodash@^4.15.0","lodash@^4.2.0","lodash@^4.2.0","lodash@^4.2.0","lodash@^4.2.0","lodash@^4.2.0","lodash@^4.14.2","lodash@^4.17.5","lodash@^4.13.1","lodash@^4.8.0","lodash@^4.11.1","lodash@^4.17.4","lodash@^4.17.4"]. This could result in non-deterministic behavior, skipping.
we also need to use the screenboard update/PUT API. I can submit a pull-request for that soon as well :)
Screenboard API's create api in the library currently indicates that a 'graph' key should be passed in.
However http://docs.datadoghq.com/api/screenboards/ doesn't make a mention of the graph
key.
Additionally it looks like the update
method isn't supported on the Screenboard API though it shouldn't be hard to add.
I'm happy to open a pull request to add it if you're okay with it @brettlangdon
I'm experiencing a memory leak when using this library.
So far I've nailed it down to the use of V8Type . Have you seen similar issues in the past?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.