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-notify

v1.0.2

Published

SMTP PM2 notifier

Downloads

15

Readme

How does it work?

We're listening on pm2 bus automatic events (manual exits won't be mailed). When an exit event happend we're keeping the pm2 process environnement in a queue. Those elements are then emailed through SMTP by using the famous nodemailer.

Templates can be customized, if you want to use another mailing protocol feel free to dig into the code! This is meant to be used out of the box with minimal configuration but it can't fit everyone needs.

If you need better email interactions have a look at Keymetrics!

Configuration

mail:
    from: "[email protected]"
    to: "[email protected]"
# see https://github.com/andris9/nodemailer-smtp-transport#usage
smtp:
    host: "smtp.gmail.com"
    port: 25
# Events list:
# - restart
# - delete
# - stop
# - restart overlimit
# - exit
# - start
# - online
events:
    - exit
template: './template.md'
# this is the process subject if there is only one event to be mailed
subject: '<%= process.name %> errored (<%= process.NODE_ENV %>)'
# if multiple events are going to be mailed, use a global subject:
multiple_subject: 'Error on <%= hostname %>'
#wait for 5 seconds after each event before sending an email - avoid spam when a lot of events happened
polling: 2500 
#attach your process logs to the email
attach_logs: true 

Templating

This is how a standard pm2 object looks like:

{ event: 'exit',
  manually: false,
  process:
   { name: 'throw',
     vizion: true,
     autorestart: true,
     exec_mode: 'fork_mode',
     exec_interpreter: 'node',
     pm_exec_path: '/usr/share/nginx/www/pm2-notify/throw.js',
     pm_cwd: '/usr/share/nginx/www/pm2-notify',
     instances: 1,
     node_args: [],
     pm_out_log_path: '/home/abluchet/.pm2/logs/throw-out-0.log',
     pm_err_log_path: '/home/abluchet/.pm2/logs/throw-error-0.log',
     pm_pid_path: '/home/abluchet/.pm2/pids/throw-0.pid',
     NODE_APP_INSTANCE: 0,
     NODE_ENV: 'production',

     ... //your env variables here

     status: 'stopped',
     pm_uptime: 1434096604224,
     axm_actions: [],
     axm_monitor: {},
     axm_options: {},
     axm_dynamic: {},
     vizion_running: false,
     created_at: 1434096545628,
     pm_id: 0,
     restart_time: 19,
     unstable_restarts: 0,
     started_inside: false,
     command:
      { locked: false,
        metadata: {},
        started_at: null,
        finished_at: null,
        error: null },
     versioning: null,
     exit_code: 1 },
  at: 1434096607294 }

You can use all those variables in the template. We're adding the hostname and we format at in a date variable by using date = new Date(at).toString(). Templating is done through lodash and the email should be markdown-formatted.

Testing

Mail testing is hard to automate. There is a sample throwing process in the test directory. To test manually just launch pm2 start test/throw.js with node index.js. If you have an idea to unit test this feel free to open an issue.