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

pm2-alert

v1.2.4

Published

send Events of pm2 and alerting process memory leak to slack

Downloads

7

Readme

pm2-alert

Get notified the changes and events of your processes in Slack

How it works

Depends on the cron configuration that defined in pm2-alert.js, it will check the memory of your processes which managed by pm2 and if its memory reach the maximum size then it will send notification via Slack

Notification Example:

Slack Notification

How to use

  1. simply install pm2-alert via npm install pm2-alert --save
  2. Copy pm2-alert.js from node_modules/pm2-alert into the root directory of your application
  3. Edit pm2-alert.js and replace to with your Slack Incomming Webhook URL
  4. Start your application via pm2 then Start pm2-alert.js with pm2 by running pm2 start pm2-alert.js

Configuration

pm2-alert.js:

let config = {

    /**
     * list of processes that you want to be alerted on memory leak
     * if you want to monitor all of your processes just leave this property empty array
     * (Example) processes: ['app', 'http'] 
     */
    processes: [],

    /**
     * Slack Incomming Webhook URL.
     * To get the Slack URL, you need to setup an Incoming Webhook. 
     * More details on how to set this up can be found here: https://api.slack.com/incoming-webhooks
     */
    to: 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX',

    /**
     * set target
     */
    target: 'slack', // custom or slack


    // TODO: listen to these Events then send notification
    // Events: ['start', 'restart'], // pm2 events

    info: {
        serverName: '192.168.1.1 US'
    },

    /**
     * fill this Object with right value to get the right notification
     */
    memory: {

        /**
         * Define when this module is try to check your process memory
         * You can learn more about cron here: https://en.wikipedia.org/wiki/Cron 
         * By default: every five minute
         */
        cron: '*/5 * * * *', // cronTab => every minute,

        /**
         * Get notified when your memory reached maxMemroySize
         * By default: 800MB
         */
        maxMemroySize: 800 * 1000000, // when process reach 800MB get alerted

        /**
         * Slack messages format
         * learn more about this here: https://api.slack.com/docs/message-formatting
         */
        warning: [
            {
                "color": "warning",
                "pretext": "we noticed that your process not working well",
                "footer": "Raychat Process Managing Service",
                "footer_icon": "https://app.raychat.io/images/favicon.png",
            }
        ]
    }
}

const pm2_slack = require('pm2-alert')
new pm2_slack(config)