npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monyt

v0.3.0

Published

## Extensible Monitor and Logger for Node.js Applications

Downloads

121

Readme

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