Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

statful-client

Package Overview
Dependencies
Maintainers
5
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

statful-client

NodeJS Client for the Statful

  • 6.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-6.25%
Maintainers
5
Weekly downloads
 
Created
Source

Statful Client for NodeJS

NPM version Build Status

Statful client for NodeJS written in Javascript. This client is intended to gather metrics and send them to Statful.

Table of Contents

Supported Versions of NodeJS

Statful client VersionTested NodeJS versions
4.x.x4.4.0, 5.12.0, 6.9.2, 7.10.1, 8.2.0
5.x.x6.9.2, 7.10.1, 8.2.0, 10.9.0
6.x.x8.2.0, 8.12.0, 10.12.0, 11.0.0

Installation

$ npm install statful-client --save

Quick start

After installing Statful Client you are ready to use it. The quickest way is to do the following:

var Statful = require('statful-client');

// Creates an object with the configuration and pass it to the client
var config = {
    app: 'AccountService',
    transport: 'api',
    api: {
        token: 'STATFUL_API_TOKEN'
    },
    tags: { cluster: 'production' }
};
var statful = new Statful(config);

// Send a metric
statful.counter('transactions', 1);

IMPORTANT: This configuration uses the default host and port. You can learn more about configuration in Reference.

Examples

You can find here some useful usage examples of the Statful Client. In the following examples is assumed you have already installed and included Statful Client in your project.

UDP Configuration

Creates a simple UDP configuration for the client.

var Statful = require('statful-client');

var config = {
    app: 'AccountService',
    transport: 'udp',
    host: 'statful-relay.yourcompany.com',
    tags: { cluster: 'production' }
};

var statful = new Statful(config);

HTTP Configuration

Creates a simple HTTP API configuration for the client.

var Statful = require('statful-client');

var config = {
    app: 'AccountService',
    transport: 'api',
    api: {
        token: 'STATFUL_API_TOKEN'
    },
    tags: { cluster: 'production' }
};

var statful = new Statful(config);

Logger configuration

Creates a simple client configuration and adds your favourite logger to the client like Bunyan, Winston or any other you want. Just assure that logger object supports: log, info, warn, debug and error methods.

var Statful = require('statful-client');
var logger = require('your-favourite-logging-lib');

var config = {
    app: 'AccountService',
    transport: 'api',
    api: {
        token: 'STATFUL_API_TOKEN'
    },
    tags: { cluster: 'production' }
};

var statful = new Statful(config, logger);

Defaults Configuration Per Method

Creates a configuration for the client with custom default options per method.

var Statful = require('statful-client');

var config = {
    default: {
        counter: { agg: ['avg'], aggFreq: 180 },
        gauge: { agg: ['first'], aggFreq: 180 },
        timer: { tags: { cluster: 'qa' }, agg: ['count'], aggFreq: 180 }
    },
    tags: { cluster: 'production' },
    api: {
        token: 'STATFUL_API_TOKEN'
    },
    transport: 'api'
}

var statful = new Statful(config);

Mixed Complete Configuration

Creates a configuration defining a value for every available option.

var Statful = require('statful-client');

var config = {
    default: {
        timer: { tags: { cluster: 'qa' }, agg: ['count'], aggFreq: 180 }
    },
    dryRun: true,
    flushInterval: 5000,
    flushSize: 50,
    transport: 'api',
    api: {
        timeout: 300,
        token: 'STATFUL_API_TOKEN'
    },
    namespace: 'application',
    tags: { cluster: 'production' }
}

var statful = new Statful(config);

Add metrics

Creates a simple client configuration and use it to send some metrics.

var Statful = require('statful-client');

var config = {
    app: 'AccountService',
    transport: 'udp',
    host: 'statful-relay.yourcompany.com',
    tags: { cluster: 'production' }
};

var statful = new Statful(config);

// Send three different metrics (gauge, timer and a counter)
statful.gauge('testGauge', 10);
statful.timer('testTimer', 100);
statful.counter('testCounter', 1, { agg: ['first'], aggFreq: 60, namespace: 'sandbox' });

// Metric to be sent with tags
statful.counter('testCounter', 1, {tags: {host: 'localhost', status: 'SUCCESS'}});

Reference

Detailed reference if you want to take full advantage from Statful.

Global configuration

The custom options that can be set on config param are detailed below.

OptionDescriptionTypeDefaultRequired
appDefines the application global name. If specified sets a global tag app=setValue.stringnoneNO
defaultObject to set methods options.object{}NO
apiDefined API configurations.objectnoneNO
dryRunDefines if metrics should be output to the logger instead of being send.booleanfalseNO
flushIntervalDefines the periodicity of buffer flushes in miliseconds.number3000NO
flushSizeDefines the maximum buffer size before performing a flush.number1000NO
namespaceDefines the global namespace.stringapplicationNO
sampleRateDefines the rate sampling. Should be a number between [1, 100].number100NO
tagsDefines the global tags.object{}NO
transportDefines the transport layer to be used to send metrics.

Valid Transports: udp, api
stringnoneYES
hostDefines the host name to where the metrics should be sent. Can also be set inside api.string127.0.0.1NO
pathDefines the api path to where the metrics should be sent. Can also be set inside api.string/tel/v2.0/metricNO
portDefines the port. Can also be set inside api.string2013NO
tokenDefines the token to be used. Must be set inside api.stringnoneNO
timeoutDefines the timeout for the transport layers in miliseconds. Must be set inside api.number2000NO

Methods

// Non Aggregated Metrics
- statful.counter('myCounter', 1, {agg: ['sum']});
- statful.gauge('myGauge', 10, { tags: { host: 'localhost' } });
- statful.timer('myCounter', 200, {namespace: 'sandbox'});
- statful.put('myCustomMetric', 200, {timestamp: '1471519331'});

// Aggregated Metrics
- statful.aggregatedCounter('myCounter', 1, 'avg', 60, { tags: { host: 'localhost' } });
- statful.aggregatedGauge('myGauge', 10, 'avg', 60, { tags: { host: 'localhost' } });
- statful.aggregatedTimer('myCounter', 200, 'avg', 60, {namespace: 'sandbox'});
- statful.aggregatedPut('myCustomMetric', 200, 'avg', 60, {timestamp: '1471519331'});

The methods for non aggregated metrics receive a metric name and a metric value as arguments and send a counter/gauge/timer/custom metric. The methods for aggregated metrics receive a metric name, a metric value, an aggregation and an aggregation frequency (used previously to aggregate the metric) as arguments and send a counter/gauge/timer/custom metric. If the options parameter is omitted, the default values are used. Those methods are truly valuable due to need of ingest already aggregated metrics into Statful (for example from AWS CloudWatch). Read the methods options reference bellow to get more information about the default values.

IMPORTANT: You can only send aggregated metrics with api transport type. Otherwise metrics will be discarded and not be sent.

DescriptionDefault for CounterDefault for GaugeDefault for TimerDefault for PutAvailable for Aggregated Methods
agg (array) - Defines the aggregations to be executed. These aggregations are merged with the ones configured globally, including method defaults.

Valid Aggregations: avg, count, sum, first, last, p90, p95, min, max
['sum', 'count'][last]['avg', 'p90', 'count'][]NO
aggFreq (number) - Defines the aggregation frequency in seconds. It overrides the global aggregation frequency configuration.

Valid Aggregation Frequencies: 10, 30, 60, 120, 180, 300
10101010'NO
namespace (string) - Defines the namespace of the metric. It overrides the global namespace configuration.applicationapplicationapplicationapplicationYES
tags (object) - Defines the tags of the metric. These tags are merged with the ones configured globally, including method defaults.{}{}{ unit: 'ms' }{}YES
timestamp (string) - Defines the timestamp of the metric. This timestamp is a POSIX/Epoch time in seconds.current timestampcurrent timestampcurrent timestampcurrent timestampYES

Plugins

It is possible to use plugin with the client.

    var SystemStatsPlugin = require('statful-client').systemStatsPlugin;
    var statful = new Statful(config, log);
    statful.use(new SystemStatsPlugin());

System Stats Plugin

This plugin allows the client to send system-related metrics and/or enrich the user metrics with system tags.

System Stats Plugin Configuration

The custom options that can be set on config param are detailed below.

OptionDisplay nameDescriptionTypeDefaultRequired
bufferFlushLength.buffler.flush_lengthDefines the application global name. If specified sets a global tag app=setValue.metricfalseNO
timerEventLoop.timer.event_loopObject to set methods options.metricfalseNO
processUptime.process.uptimeUptime of the process in miliseconds.metricfalseNO
processMemoryUsageprocess.memory.usageProcess memory usage in bytes.metricfalseNO
processMemoryUsagePercprocess.memory.usage.percProcess memory usage percentage. (compared to total OS memory)metricfalseNO
osUptime.os.uptimeOS uptime in miliseconds.metricfalseNO
osTotalMemory.os.memory.totalOS total memory in bytes.metricfalseNO
osFreeMemoryos.memory.freeOS free memory in bytes.metricfalseNO
tagHostnamehostnameHostname.tagfalseNO
tagPlatformplatformPlatform.tagfalseNO
tagArchitecturearchitectureArchitecture.tagfalseNO
tagNodeVersionnode_versionNodeJS VersiontagfalseNO

Authors

Mindera - Software Craft

License

Statful NodeJS Client is available under the MIT license. See the LICENSE file for more information.

FAQs

Package last updated on 05 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc