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

opsdash-client

v0.3.0

Published

NodeJS client for the OpsDash Server Monitor

Downloads

10

Readme

OpsDash Client for NodeJS

This is a node client for the OpsDash Server Monitor. You can report process metrics like memory and cpu usage and of course your own individual metrics.

It requires NodeJS >= 4.0.0

Memory example

Uptime example

Install

npm install --save opsdash-client

Setup

let opsDashClient = require('opsdash-client')

let opsDashReporter = opsDashClient({
  server: 'http://yourOpsDashDomain:8080',
  interval: 30,
  source: 'expressApp-' + opsDashClient.hostname
})

The option object can have the following attributes:

  • server: Address of your OpsDash server including the port.
  • interval: Default interval for sending metrics in seconds.
  • reportProcessMetrics: Boolean, default true. Should the opsDashClient automatically send process reports (details see below).
  • source: Name of the source.

Reporting metrics of your node process

The opsDashClient can send the following metrics of your node process:

  • memory.rss
  • memory.heapUsed
  • memory.heapTotal
  • cpu (CPU usage in %)
  • uptime (uptime of your node process in seconds - great to identify crashes or restarts)

If you instantiate your reporter with reportProcessMetrics set to true, then this metrics will be reported automatically (default).

Otherwise you can start sending this metrics manually:

opsDashReporter.startProcessReporting()

If you want to stop sending this metrics:

opsDashReporter.stopProcessReporting()

Sending only selected process metrics

If you don't want to send all available process metrics, you can start them manually. For example, to only report the cpu usage:

opsDashReporter.addMetric(
  'cpu',
  {type: 'callback', start:true},
  opsDashClient.processReporter.cpu
)

Reporting individual metrics

Currently three different types of values are supported:

  • Simple values like counters
  • Setting values with a synchronous function
  • Setting values with an asynchronous callback

To add a new metric use the opsDashReporter.addMetric(name, options, callback) method.

Simple values

Setup:

//Add new metric and start reporting
opsDashReporter.addMetric(
  'numberOfLogins',
  {type: 'value', start: true, reset:true}
)

Options:

  • type: In case of simple values, this must be value
  • start: Boolean, should we stat the reporting automatically?
  • reset: Boolean. If true, the value will be reseted after every report interval, default true
  • startValue: The initial value of your metric, default 0
  • interval: The reporting interval in seconds. If not set, the default interval will be used.

Increase the value:

//will increase the value by 1:
opsDashReporter.incMetric('numberOfLogins')

//will increase the value by number
opsDashReporter.incMetric('numberOfLogins', number)

//will set the value to number
opsDashReporter.setMetricValue('numberOfLogins', number)

Synchronous and asynchronous functions for retrieving values

Setup:

//Add new metric and start reporting
opsDashReporter.addMetric(
  'numberOfLogins',
  {type: 'callback', start: true, reset:true},
  yourCallbackFunction
)

In this case you provide a callback function to get the current value of your metric.

If this is a synchronous function, this callback must not have any parameters and must return the value of your metric.

If this is a asynchronous function, the function must have a callback function in the form of function(err, result) as the only parameter.

Error Handling

The opsDashClient emits a error-Event:

opsDashReporter.on('error', function(err){
  console.error(err);
})

TODO

  • Support Basic Auth
  • Improve error handling
  • Check usage in cluster mode