Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
statful-client
Advanced tools
Staful client for NodeJS written in Javascript. This client is intended to gather metrics and send them to Statful.
Statful client Version | Tested NodeJS versions |
---|---|
4.0.0 | 0.10 , 0.12 , 4 and Stable |
$ npm install statful-client --save
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 = {
token: 'MyAppToken',
app: 'AccountService',
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.
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.
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);
Creates a simple HTTP API configuration for the client.
var Statful = require('statful-client');
var config = {
app: 'AccountService'
transport: 'http',
api: {
token: 'YOUR_TOKEN_FOR_STATFUL_API'
}
tags: { cluster: 'production' },
};
var statful = new Statful(config);
Creates a simple client configuration and adds your favourite logger to the client, like Bunyan or Winston.
var Statful = require('statful-client');
var logger = require('your-favourite-logging-lib');
var config = {
app: 'AccountService'
transport: 'http',
api: {
token: 'YOUR_TOKEN_FOR_STATFUL_API'
},
tags: { cluster: 'production' },
};
var statful = new Statful(config, logger);
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: 'YOUR_TOKEN_FOR_STATFUL_API'
},
transport: 'http'
}
var statful = new Statful(config);
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 }
},
dryRyn: true,
flushInterval: 5000,
flushSize: 50,
transport: 'http',
api: {
secure: false,
timeout: 300,
token: 'YOUR_TOKEN_FOR_STATFUL_API'
}
namespace: 'application',
tags: { cluster: 'production' }
}
var statful = new Statful(config);
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'}});
Detailed reference if you want to take full advantage from Statful.
The custom options that can be set on config param are detailed below.
Option | Description | Type | Default | Required |
---|---|---|---|---|
app | Defines the application global name. If specified sets a global tag app=setValue . | string | none | NO |
default | Object to set methods options. | object | {} | NO |
api | Defined API configurations. | object | none | NO |
dryRun | Defines if metrics should be output to the logger instead of being send. | boolean | false | NO |
flushInterval | Defines the periodicity of buffer flushes in miliseconds. | number | 10000 | NO |
flushSize | Defines the maximum buffer size before performing a flush. | number | 10 | NO |
namespace | Defines the global namespace. | string | application | NO |
sampleRate | Defines the rate sampling. Should be a number between [1, 100]. | number | 100 | NO |
tags | Defines the global tags. | object | {} | NO |
transport | Defines the transport layer to be used to send metrics. Valid Transports: udp, http | string | none | YES |
host | Defines the host name to where the metrics should be sent. Can also be set inside api. | string | 127.0.0.1 | NO |
port | Defines the port. Can also be set inside api. | string | 2013 | NO |
secure | Enable or disable https protocol. Must be set inside api. | boolean | true | NO |
token | Defines the token to be used. Must be set inside api. | string | none | NO |
timeout | Defines the timeout for the transport layers. Must be set inside api. | number | 2000 | NO |
- staful.counter('myCounter', 1, {agg: ['sum']});
- staful.gauge('myGauge', 10, { tags: { host: 'localhost' } });
- staful.timer('myCounter', 200, {namespace: 'sandbox'});
These methods receive a metric name and a metric value as arguments and send a counter/gauge/timer metric. If the options parameter is omitted, the default values are used. Read the methods options reference bellow to get more information about the default values.
Option | Description | Type | Default for Counter | Default for Gauge | Default for Timer |
---|---|---|---|---|---|
agg | 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 | array | ['avg', 'p90'] | last] | ['avg', 'p90', 'count'] |
aggFreq | Defines the aggregation frequency in seconds. It overrides the global aggregation frequency configuration. Valid Aggregation Frequencies: 10, 30, 60, 20, 180, 300 | number | 10 | 10 | 10 |
namespace | Defines the namespace of the metric. It overrides the global namespace configuration. | string | application | application | application |
tags | Defines the tags of the metric. These tags are merged with the ones configured globally, including method defaults. | object | {} | {} | { unit: 'ms' } |
Statful NodeJS Client is available under the MIT license. See the LICENSE file for more information.
FAQs
NodeJS Client for the Statful
The npm package statful-client receives a total of 10 weekly downloads. As such, statful-client popularity was classified as not popular.
We found that statful-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.