npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gelf-http

v1.0.1

Published

Sending GELF to graylog node by HTTP

Downloads

362

Readme

gelf-http

Node module to send Graylog Information via HTTP. Because sometimes that's all you need.

configuration

{
	url: "http://localhost:8082/gelf", // URL to the Graylog Node
	gzip : false // Set to true if you want to save some bandwidth.
}

Functions

init(url[,defaultMessage])

Initializes the module with the given configuration

var gl2 = require("gelf-http");
gl2.init('http://localhost:8082/gelf');

Parameters

  • (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])

Sends a message to the Graylog Server.

  • 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.

Shorthands functions to send()

So you don't need to remember which level is which number :)

  • debug(message [, callback])
  • info(message [, callback])
  • notice(message [, callback])
  • warn(message [, callback])
  • error(message [, callback])
  • critical(message [, callback])
  • alert(message [, callback])
  • panic(message [, callback])

Metrics

gelf-http also provides two functions specifically used for sending metrics to Graylog.

  • metric(name, value[, callback])
  • metrics(values[, callback])

Examples

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

Issues

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. :)

Code

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

Basic tests with only a mock server

$ npm install
$ mocha test

You have a real Graylog server with an HTTP input? Test the module with it too!

$ npm install
$ env GELF_HTTP_SERVER="url_of_your_http_input"
$ mocha test

Changelog

  • 1.0 (2017-11-15) : Published to npmjs.com