The `memmon` plugin is a supervisor "event listener" that monitors the memory usage of processes under supervisor control. It checks the resident set size (RSS) of processes and restarts them if they exceed a configurable limit. The plugin can be configured to monitor specific programs or groups of programs and send email notifications when processes are restarted[4][5].
Configuration
To use the `memmon` plugin, you need to add an `[eventlistener:x]` section to your supervisor configuration file (`supervisord.conf`). The configuration includes the following options:
- `command`: specifies the command to run `memmon` with, including the memory limit and email address for notifications.
- `events`: specifies the event to subscribe to, typically `TICK_60` for checking every 60 seconds.
- `cumulative`: checks the cumulative RSS of a process and its children if set to `true`.
Here is an example configuration:
bash
[eventlistener:memmon]
command=memmon -a 200MB -m
<script language='JavaScript' type='text/javascript'>
<!--
var prefix = 'mailto:';
var suffix = '';
var attribs = '';
var path = 'hr' + 'ef' + '=';
var addy27611 = 'bob' + '@';
addy27611 = addy27611 + 'example' + '.' + 'com';
document.write( '<a ' + path + '\'' + prefix + addy27611 + suffix + '\'' + attribs + '>' );
document.write( addy27611 );
document.write( '<\/a>' );
//-->
</script><script language='JavaScript' type='text/javascript'>
<!--
document.write( '<span style=\'display: none;\'>' );
//-->
</script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
<script language='JavaScript' type='text/javascript'>
<!--
document.write( '</' );
document.write( 'span>' );
//-->
</script>
events=TICK_60
How it Works
1. Event Subscription: `memmon` subscribes to the specified event (e.g., `TICK_60`).
2. Memory Check: When the event is triggered, `memmon` checks the RSS of the processes under supervisor control.
3. Restart: If a process exceeds the configured memory limit, `memmon` restarts the process.
4. Notification: If configured, `memmon` sends an email notification to the specified address when a process is restarted.
Limitations
- `memmon` can only monitor processes that are direct children of the supervisor process.
- It does not work on other operating systems besides Linux and Mac OS X.
Installation
The `memmon` plugin is part of the `superlance` package, which can be installed using pip:
bash
pip install superlance
Conclusion
The `memmon` plugin is a useful tool for monitoring and controlling memory usage of processes under supervisor control. It provides a simple and effective way to ensure that processes do not consume excessive memory resources, which can help prevent system crashes and improve overall system performance.
Citations:[1] https://github.com/Supervisor/superlance/blob/master/superlance/memmon.py
[2] https://codesamplez.com/management/supervisord-web-interface-and-plugin
[3] https://stackoverflow.com/questions/12571052/have-supervisord-periodically-restart-child-processes
[4] https://superlance.readthedocs.io/en/latest/memmon.html
[5] https://pypi.org/project/superlance/0.5/