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

monoxide.js

v1.0.3

Published

monoxide.js is a client for Carbon, a data injest tool which is a part of the Graphite project

Downloads

3

Readme

monoxide.js

JavaScript Style Guide npm version Github build status License MIT

monoxide.js is a Node.js client for Carbon that is a component of Graphite, and is responsible for receiving metrics over the network and writing them down to disk using a storage backend. This project is a fork of Oxide but currently supports only Carbon and not StatsD as Oxide does (I'm planning to add the support for StatsD in the next releases).

Installation

To install this library, open a terminal and type:

npm i --save monoxide.js

Then, import the library in your project:

const Monoxide = require('monoxide.js')

Examples

Inside the folder /examples you can see an example of sending metrics to Carbon using monoxide.js.

Usage

To start sending metrics to Carbon you need to create 3 objects:

  1. the config object that stores the information about the server (Carbon)
  2. the protocol object that formats the metrics before sending them to Carbon
  3. the client that stores the metrics and periodically sends them to Carbon

Configuration

After you installed and imported the library correctly, the first thing you need to create is a Config object. This class is responsible to store the data that will be used to connect to Carbon.

const config = new Monoxide.Config('127.0.0.1', 1234, 10000, 'your.global.prefix')

The config object has 4 properties:

  • host: the ip address of the host where Carbon is currently running (127.0.0.1)
  • port: the port where Carbon is currently listening (1234)
  • interval: the interval in ms each time the metrics are sent to the server (10000)
  • prefix: the prefix that will be appended to every metric's path before sending the metric to Carbon (your.global.prefix)

The prefix is optional and can be omitted in the last parameter of the constructor if you don't want to prefix anything in the metric's path.

Also, if you don't pass anything to the constructor the config object will use the following parameters to connect to Carbon:

  • host: 127.0.0.1
  • port: 2003
  • interval: 5000
  • prefix: <nothing>

Protocols

After you have created the config object, you have to create the protocol object. This object will be the responsible of formatting the metrics before sending them to the server.

You can choose between 2 different types of protocols:

  • pickle protocol [More]
  • plaintext protocol [More]

Pickle Protocol

You can create an instance of the pickle protocol like this:

const protocol = new Monoxide.Protocols.PickleProtocol()

Plaintext Protocol

You can create an instance of the plaintext protocol like this:

const protocol = new Monoxide.Protocols.PlaintextProtocol()

Create your custom protocol

If you want, you can create your custom protocol. Just override the AbstractProtocol class or create an instance of this class. If you want to know more, you can take a look at the AbstractProtocol class's code and also at the derived classes PlaintextProtocol and PickleProtocol.

Carbon client

The client is the core component of the library. It's responsible of record, store and send metrics to the Carbon service. First, create the client:

const client = new Monoxide.Clients.CarbonClient(config, protocol)

Then, you need to start the process that sends the metrics periodically and opens a socket connection to Carbon:

client.start()

The client emits 2 events:

  • error: everytime there is an error (for example, if there was an error sending the metrics)
  • metrics-sent: everytime the metrics are correctly sent to Carbon

You should at least subscribe to the error event so you can process the errors:

client.on('error', (err) => {
  // process the error
})

client.on('metrics-sent', () => {
  // do some stuff
})

Now, you can record metrics that will be sent periodically to Carbon (using the interval you specified in the config object):

client.record('example.metric.1', 123, new Date())

The metric will be enqueued and sent the next time the process that sends metrics will be executed. If you have specified the prefix, the record method will add the prefix in front of the metric path.

Also, If you don't provide the date object, the metric will be stored with the timestamp of its creation.

If you need, you can stop the sending process and close the connection to the server (you can restart the process using the .start() method):

client.stop()

Test

If you want to test the code, clone the repo locally on your computer, install the project dependencies and then run:

npm test

Contribution

If you find a bug or just want to contribute to the project, you can open an issue or fork the project and then open a pull request on branch dev.

Credits

As I said above, this project is a fork of Oxide. I decided to rewrite this library because on Github the project has been archived and on npm the last version doesn't reflect the code on Github.