Sending GELF to graylog node by HTTP
npm install gelf-httpinit(url[,defaultMessage])string or instanceof require('url')) url : URL of the HTTP Input on your Graylog server. gelf-http supports both HTTP and HTTPS
object) defaultMessage : default object that will be used as a base message for all the messages sent. Useful if you want to provide some fields with all your messages. Will be merged with the message parameter of send().
send(message, level [, callback])message : Either a string or a object. If an object is given, it will be flattened to be correctly analyzed by Graylog.
level : from 0 (panic) to 7 (debug), as described in the GELF specifications.
callback : optional function(err, (boolean) success) fired on the result of the HTTP request.
debug(message [, callback])
info(message [, callback])
notice(message [, callback])
warn(message [, callback])
error(message [, callback])
critical(message [, callback])
alert(message [, callback])
panic(message [, callback])
gelf-http also provides two functions specifically used for sending metrics to Graylog.
metric(name, value[, callback])
metrics(values[, callback])
js
let gl2 = require('gelf-http');
gl2.init('http://localhost:8082/gelf');
/ Graylog will receive a basic DEBUG message with "This is a debug line" as message /
gl2.debug("This is a debug line");
/* Graylog will receive a INFO message with variables :
{
"_cpu_load" : 0.509439832,
"_ram_load" : 0.2984398,
"_db_connections" :298
}
*/
gl2.info({
"cpu_load":0.509439832,
"ram_load":0.2984398,
"db_connections":298
});
/* Graylog will receive a INFO message with the following payload :
{
"_label" : "cpu_load",
"_value" : 50
}
*/
gl2.metric("cpu_load",50);
`
Contribute
$3
I use the module in some of my personal/professional projects, so any major bug would be detected by myself. Anyway, submit an issue if you encounter any trouble. I'll be glad to help. :)
$3
Fork the repository, do your modifications, and send a PR :) I don't intend to add much more features to this module, as it already does all I need. But if you have any idea, don't hesitate!
Run unit tests
$3
`bash
$ npm install
$ mocha test
`
$3
`bash
$ npm install
$ env GELF_HTTP_SERVER="url_of_your_http_input"
$ mocha test
``