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

monyt

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monyt

## Extensible Monitor and Logger for Node.js Applications

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Monyt

Extensible Monitor and Logger for Node.js Applications

Build Status Coverage Status npm version npm downloads Gitter chat

Monyt provides abstraction interfaces of monitoring and logging for Node.js Applications.

Installation

$ npm i -S monyt

Usage

Basic

monitor.js

import Monyt, {
    RequestCountMetrics,
    ErrorCountMetrics,
    MemoryMetrics,
    GarbageCollectionMetrics,
    EventLoopLagMetrics,
    GraphiteSender
} from 'monyt';

const interval = 60000; //default is 30000(ms)

const senders = [new GraphiteSender({
    host: 'my.graphite.host.com',
    port: '2003' //port of plaintext protocol
})];

const metricses = [
    new RequestCountMetrics(),
    new ErrorCountMetrics(),
    new MemoryMetrics(),
    new GarbageCollectionMetrics(),
    new EventLoopLagMetrics()
];

const monitor = new Monyt({
    interval,
    prefix: `${application}.${hostname}.${clusterId}`, //This could be server hostname or application name or clusterId and etc.
    senders,
    metricses
});

export default monitor;

server.js

import Express from 'express';
import monitor from './monitor';

const logger = monitor.getLogger();

monitor.listen(results => {
    results
    .then(metricses=>logger.debug(metricses))
    .catch(error=>logger.error(error));
});

const app = new Express();
app.use(monyt.middlewares());
app.use('/', (req, res, next) => {
    logger.info('This is index.');
    res.send('hello monyt!');
});

Make your own Metrics and Sender

ProductBuyMetrics.js

import { Metrics } from 'monyt';

export default class ProductBuyMetrics extends Metrics {
    constructor() {
        super();
        this.name = 'product.buy';
        this.value = {}
    }

    buy(productId) {
        this.value[productId] = this.value[productId] || 0;
        this.value[productId] = this.value[productId] + 1;
    }
}

MongoDBSender.js

import { Sender } from 'monyt';

export default class MongoDBSender extends Sender {
    constructor(options = {}) {
        super();
        this.client = options.db.collection('metrics');
    }

    send(metrics) {
     return new Promise((resolve, reject)=> {
         this.client.insert(metrics, (error, result) => {
         if (error) {
           return reject(error);
         }
         return resolve(result);
       });
     });
    }
}

monitor.js

...
const productBuyMetrics = new ProductBuyMetrics()
const senders = [new MongoDBSender({db: mongodbClient});]
const metricses = [new ProductBuyMetrics()];
const monitor = new Monyt({
    ...
    senders,
    metricses,
    ...
});
export default monitor;
export productBuyMetrics;

your-app.js

import { productBuyMetrics } from './monitor';

app.post('/buy/:user/:productId', (req, res, next) => {
    //...buying process...
    productBuyMetrics.buy(req.params.productId);
    res.send(buyResult);
});

API

ESDoc

Change History

CHANGELOG

License

This software is free to use under the Minkyu Cho. MIT license. See the LICENSE file for license text and copyright information.

Contributing

Please don't hesitate to send a small pull-request or just leave anything you want as an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b feature/my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature/my-new-feature
  5. Submit a pull request :D

Keywords

FAQs

Package last updated on 02 Jun 2016

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