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

@statful/statful-client

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@statful/statful-client

NodeJS Client for the Statful

  • 4.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Statful Client for NodeJS

NPM version Build Status

Staful 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

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, at least, 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
- staful.counter('myCounter', 1, {agg: ['sum']});
- staful.gauge('myGauge', 10, { tags: { host: 'localhost' } });
- staful.timer('myCounter', 200, {namespace: 'sandbox'});
- staful.put('myCustomMetric', 200, {timestamp: '1471519331'});

// Aggregated Metrics
- staful.aggregatedCounter('myCounter', 1, 'avg', 60, { tags: { host: 'localhost' } });
- staful.aggregatedGauge('myGauge', 10, 'avg', 60, { tags: { host: 'localhost' } });
- staful.aggregatedTimer('myCounter', 200, 'avg', 60, {namespace: 'sandbox'});
- staful.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.

OptionDescriptionTypeDefault for CounterDefault for GaugeDefault for TimerDefault for PutAvailable for Aggregated Methods
aggDefines 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
array['avg', 'p90'][last]['avg', 'p90', 'count'][]NO
aggFreqDefines the aggregation frequency in seconds. It overrides the global aggregation frequency configuration.

Valid Aggregation Frequencies: 10, 30, 60, 120, 180, 300
number10101010'NO
namespaceDefines the namespace of the metric. It overrides the global namespace configuration.stringapplicationapplicationapplicationapplicationYES
tagsDefines the tags of the metric. These tags are merged with the ones configured globally, including method defaults.object{}{}{ unit: 'ms' }{}YES
timestampDefines the timestamp of the metric. This timestamp is a POSIX/Epoch time in seconds.stringcurrent timestampcurrent timestampcurrent timestampcurrent timestampYES

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 21 Aug 2017

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