All Projects → Soluto → monitored

Soluto / monitored

Licence: MIT license
A utility for monitoring services 🔍

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to monitored

Rye
A tiny http middleware for Golang with added handlers for common needs.
Stars: ✭ 95 (+156.76%)
Mutual labels:  statsd
Node Statsd Client
Node.js client for statsd
Stars: ✭ 170 (+359.46%)
Mutual labels:  statsd
docker grafana statsd elk
Docker repo for a general purpose graphing and logging container - includes graphite+carbon, grafana, statsd, elasticsearch, kibana, nginx, logstash indexer (currently using redis as an intermediary)
Stars: ✭ 19 (-48.65%)
Mutual labels:  statsd
Statsd Csharp Client
Statsd C# Client
Stars: ✭ 110 (+197.3%)
Mutual labels:  statsd
Statsite
C implementation of statsd
Stars: ✭ 1,791 (+4740.54%)
Mutual labels:  statsd
Redis Timeseries
Future development of redis-timeseries is at github.com/RedisLabsModules/redis-timeseries.
Stars: ✭ 197 (+432.43%)
Mutual labels:  statsd
Statsderl
High-Performance Erlang StatsD Client
Stars: ✭ 92 (+148.65%)
Mutual labels:  statsd
perfmetrics
A library for sending software performance metrics from Python libraries and apps to statsd.
Stars: ✭ 26 (-29.73%)
Mutual labels:  statsd
Go Statsd Client
statsd client for Go
Stars: ✭ 163 (+340.54%)
Mutual labels:  statsd
Netdata
Real-time performance monitoring, done right! https://www.netdata.cloud
Stars: ✭ 57,056 (+154105.41%)
Mutual labels:  statsd
Statsd Vis
Standalone StatsD server with built-in visualization
Stars: ✭ 124 (+235.14%)
Mutual labels:  statsd
Promitor
Bringing Azure Monitor metrics where you need them.
Stars: ✭ 140 (+278.38%)
Mutual labels:  statsd
Statix
Fast and reliable Elixir client for StatsD-compatible servers
Stars: ✭ 228 (+516.22%)
Mutual labels:  statsd
Foundatio
Pluggable foundation blocks for building distributed apps.
Stars: ✭ 1,365 (+3589.19%)
Mutual labels:  statsd
statsd.cr
A statsd client library for Crystal.
Stars: ✭ 32 (-13.51%)
Mutual labels:  statsd
Amon
Amon is a modern server monitoring platform.
Stars: ✭ 1,331 (+3497.3%)
Mutual labels:  statsd
Trashed
Tell StatsD about request time, GC, objects and more. Latest Rails 4 and Ruby 2.1 support, and ancient Rails 2 and Ruby 1.8 support.
Stars: ✭ 188 (+408.11%)
Mutual labels:  statsd
fastify-metrics
📊 Fastify plugin that integrates metrics collection and dispatch to statsd
Stars: ✭ 62 (+67.57%)
Mutual labels:  statsd
ecs-container-exporter
AWS ECS side car that exports ECS container level docker stats metrics to Prometheus as well as publish it via Statsd.
Stars: ✭ 22 (-40.54%)
Mutual labels:  statsd
Datadog Go
go dogstatsd client library for datadog
Stars: ✭ 238 (+543.24%)
Mutual labels:  statsd

Monitored 🕵️‍♀️

A utility for monitoring services

Monitored is a wrapper function that writes success/error logs and StatsD metrics (gauge, increment, timing) after execution. It supports both asynchronous and synchronous functions.

GitHub Workflow Status License code style: prettier

Quick start

Yarn

yarn add monitored

Npm

npm install monitored

Initialize

Call setGlobalInstance at the root of the project

To wire this package, you must pass an Options object.

import { setGlobalInstance, Monitor } from 'monitored';

interface MonitorOptions {
    serviceName: string; // Represents the name of the service you are monitoring (mandatory)
    plugins: MonitoredPlugin[]; // Stats plugins, statsD and/or prometheus (mandatory)
    logging?: {
        // Writes success and error logs with the passed in logger (optional)
        logger: any; // logger (mandatory)
        logErrorsAsWarnings?: boolean; // log errors as warnings (optional)
        disableSuccessLogs?: boolean; // When true, will not send success log. defaults to false (optional)
    };
    shouldMonitorExecutionStart?: boolean; // When true will log execution start and will increment a metrics. defaults to true (optional)
    mock?: boolean; //Writes the metrics to logs instead of StatsD for debugging. defaults to false (optional)
}

setGlobalInstance(
    new Monitor({
        serviceName: 'monitored-example',
        logging: {
            logger: logger,
            logErrorsAsWarnings: false,
            disableSuccessLogs: false,
        },
        plugins: [
            new StatsdPlugin({
                serviceName: 'test',
                apiKey: 'key',
                host: 'host',
                root: 'root',
            }),
            new PrometheusPlugin(),
        ],
        shouldMonitorExecutionStart: true,
    })
);

API

monitored

After execution, a wrapper function writes success/error logs and StatsD metrics (gauge, increment, timing).

monitored supports both Asynchronous and Synchronous functions:

//Async function:
const result = await monitored('functionName', async () => console.log('example'));

//Sync function:
const result = monitored('functionName', () => {
    console.log('example');
});

You can also pass a options argument to monitored:

type MonitoredOptions = {
    context?: any; //add more information to the logs
    logResult?: boolean; //should write log of the method start and success
    parseResult?: (e: any) => any; //custom parser for result (in case it is logged)
    level?: 'info' | 'debug'; //which log level to write (debug is the default)
    logAsError?: boolean; //enables to write error log in case the global `logErrorsAsWarnings` is on
    logErrorAsInfo?: boolean //enables to write the error as info log
    shouldMonitorError: e => boolean //determines if error should be monitored and logged, defaults to true
    shouldMonitorSuccess: (r: T) => boolean //determines if success result should be monitored and logged, defaults to true
    tags?: Record<string, string>; //add more information/labels to metrics
};

You can use context to add more information to the log, such as user ID

const result = monitored(
    'functionName',
    () => {
        console.log('example');
    },
    {context: {id: 'some context'}}
);

You can use tags to add labels to metrics

const result = monitored(
    'functionName',
    () => {
        console.log('example');
    },
    {tags: {'some-label': 'some-value'}}
);

Also, you can log the function result by setting logResult to true:

const result = monitored(
    'functionName',
    () => {
        console.log('example');
    },
    {context: {id: 'some context'}, logResult: true}
);

flush

Wait until all current metrics are sent to the server.
We recommend using it at the end of lambda execution to ensure all metrics are sent.

import { getGlobalInstance } from 'monitored';

const flushTimeout: number = 2000;
await getGlobalInstance().flush(flushTimeout)

Testing

  1. Create a .env file with STATSD_API_KEY and STATSD_HOST values
  2. Run yarn example
  3. Verify manually that console logs and metrics in the statsd server are valid

Contributing

Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the documentation. See the Contribution Guidelines if you'd like to submit a PR.

License

Licensed under the MIT License, Copyright © 2020-present Soluto.

Crafted by the Soluto Open Sourcerers🧙

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].