@kulakovdmitr/pm2-slack
v6.0.1
Published
A PM2 module to emit events to Slack and configure settings
Downloads
3
Maintainers
Readme
pm2-slack-configured
This is an extended version of abandoned project: https://github.com/mattpker/pm2-slack
pm2-slack
This is a PM2 Module for sending events & logs from your PM2 processes to Slack.
Install
To install and setup pm2-slack, run the following commands:
pm2 install pm2-slack
pm2 set pm2-slack:slack_url https://slack_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
Events subscription configuration
The following events can be subscribed to:
log
- All standard out logs from your processes. Default: falseerror
- All error logs from your processes. Default: truekill
- Event fired when PM2 is killed. Default: trueexception
- Any exceptions from your processes. Default: truerestart
- Event fired when a process is restarted. Default: falsereload
- Event fired when a cluster is reloaded. Default: falsedelete
- Event fired when a process is removed from PM2. Default: falsestop
- Event fired when a process is stopped. Default: falserestart overlimit
- Event fired when a process is reaches the max amount of times it can restart. Default: trueexit
- Event fired when a process is exited. Default: falsestart
- Event fired when a process is started. Default: falseonline
- Event fired when a process is online. Default: false
You can simply turn these on and off by setting them to true or false using the PM2 set command.
pm2 set pm2-slack:log true
pm2 set pm2-slack:error false
Options
The following options are available:
slack_url
(string) - Slack Incomming Webhook URL.servername
/username
(string) - Set the custom username for Slack messages (visible in message headers). Default: server hostnamebuffer
(bool) - Enable/Disable buffering of messages. Messages that occur in short time will be concatenated together and posted as a single slack message. Default: truebuffer_seconds
(int) - If buffering is enables, all messages are stored for this interval. If no new messages comes in this interval, buffered message(s) are sended to Slack. If new message comes in this interval, the "timer" will be reseted and buffer starts waiting for the new interval for a new next message. Note: Puspose is reduction of push notifications on Slack clients. Default: 2buffer_max_seconds
(int) - If time exceed this time, the buffered messages are always sent to Slack, even if new messages are still comming in interval (propertybuffer_seconds
). Default: 20queue_max
(int) - Maximum number of messages, that can be send in one Slack message (in one bufferring round). When the queue exceeds this maximum, next messages are suppresesed and replaced with message "Next XX messages have been suppressed.". Default: 100
Set these options in the same way as subscribing to events.
Example
The following configuration options will enable message buffering, and set the buffer duration to 5 seconds. All messages that occur within maximum 5 seconds delay between two neighboring messages will be concatenated into a single slack message.
pm2 set pm2-slack:slack_url https://hooks.slack.com/services/123456789/123456789/aaaaaaa
pm2 set pm2-slack:buffer_seconds 5
Note: In this example, the maximum total delay for messages is still 20 seconds (default value for buffer_max_seconds
). After this time, the buffer will be flushed
everytime and all messages will be sent.