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-webhook-monitor

v1.0.7

Published

A pm2 monitor which sends log messages to webhook url.

Downloads

14

Readme

PM2 Webhook Monitor

This is a pm2 module which monitors application processes and sends log messages of specified events, exceptions and errors.

At the first, I want to monitor my application and I want a program which can notify me on WeChat when my application crashes. But, for some reason, I have to implement this by a private webhook url. So this module is only works for me. If you want to use a public webhook url (e.g. WeChat webhook) or your own private url, you can fork this module and implement your own notify function in notifier.js. It's very easy.

Usage

You should install this module first:


pm2 install pm2-webhook-monitor

To get this module work, you need to tell it your webhook url:


pm2 set pm2-webhook-monitor:webhookUrl < https://www.webhook.com/notify.action >

And for my case, I use phone numbers to specify the people who will receive the notification. It could be set like this:


pm2 set pm2-webhook-monitor:phone "13000000000,13000000001"

Configuration

Here are the all configuration items and their default value.


{
  "webhookUrl"        : null,
  "log"               : false,
  "error"             : true,
  "kill"              : true,
  "exception"         : true,
  "restart"           : true,
  "reload"            : true,
  "delete"            : true,
  "stop"              : true,
  "restart overlimit" : true,
  "exit"              : false,
  "start"             : false,
  "online"            : false,
  "phone"             : null,
  "bufferMaxSecond"   : 5,
  "buffer"            : true
}

You can config them by using:


pm2 set pm2-webhook-monitor:<key> <value>

Message merge and postpone sending

When our application is executed in cluster mode, there will be many processes. And if we restart the application, every process will trigger a restart event and all the events will be notified to us. I think this is unnecessary and use a message queue to avoid this behaviour.

The message queue receives messages and merges the same event. Then it uses a scheduler to finish the notify task.

We can enable this by set:


pm2 set pm2-webhook-monitor:buffer true

And the bufferMaxSecond specifies how long should the monitor program buffer the messages. The default value is 5, which means the message queue waits at most 5 seconds while the first message is arrived. Once the waiting time is over the limit, the notify task is executed immediately.

Acknowledgements

  • pm2-slack : This project inspired me to create this module, thanks to every one contributes to this project, thanks for their hard-working and open source spirit.

  • sailor103 : This is one of my best friends, he introduced the pm2-slack project to me, and he often plays the duck role in my rubber duck debugging. Thanks for his time and love(just love between friends, I'm not a gay, but I'm not sure if he is a gay :smirk: ).