Giter Club home page Giter Club logo

opsdash-client's Introduction

OpsDash Client for NodeJS

Code Climate Dependency Status NPM Version

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

opsdash-client's People

Contributors

pdaether avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.