Monitor and Control a Tons of processes of your OS with AWS Supervisor

Monitor and Control a Tons of processes of your OS with AWS Supervisor

December 10, 2020 / Nirav Shah

Monitor and Control a Tons of processes of your OS with AWS Supervisor

Supervisor is a client/server system that allows to monitor and control a number of processes on UNIX-like operating systems.

The components of the Supervisor are:

  • supervisord
  • supervisorctl
  • Web Server
  • XML-RPC Interface

Pre-requirement:

You have to install python on your server.

Installing Supervisor

By downloading the Supervisor package by the command

#apt-get install python-setuptools
sudo easy_install supervisor

monitor-and-control-os-aws

Now reboot your server and chillout.

Now we have to create a file inside the Etc folder and named supervisor. Follow below command:

sudo mkdir /etc/supervisor

Run the command echo_supervisord_conf to print a “sample” Supervisor configuration file to your terminal stdout.

echo_supervisord_conf

monitor-and-control-os-aws

Next, type the command as below as a root:

echo_supervisord_conf > /etc/supervisor/supervisord.conf

[include]
files=conf.d/*.conf

monitor-and-control-os-aws

Starting the supervisor server

Firstly, create a file called supervisord.service in the /etc/systemd/system directory.

touch /etc/systemd/system/supervisord.service

Open it with vim and add the following below to the file.

[Unit]

Description=Supervisor daemon

Documentation=http://supervisord.org

After=network.target

[Service]

ExecStart=/usr/local/bin/supervisord -n -c

/etc/supervisor/supervisord.conf

ExecStop=/usr/local/bin/supervisorctl $OPTIONS

shutdown

ExecReload=/usr/local/bin/supervisorctl $OPTIONS

reload

KillMode=process

Restart=on-failure

RestartSec=42s

[Install]

WantedBy=multi-user.target

Alias=supervisord.service

monitor-and-control-os-aws

Save the file using :wq!

And start the supervised service by the following command and see the status.

systemctl start supervisord.service
systemctl status supervisord.service

monitor-and-control-os-aws

Adding a Program

Now we are going to add the script.

supervisor_cw_hello.sh.

sudo touch supervisor_cw_hello.sh

sudo nano supervisor_cw_hello.sh

#!/bin/bash

while true

do

echo "This is xyz"

# Echo current timestamp to stdout

echo Hello Supervisor: `date`

# Echo 'error!' to stderr

echo An error occurred at `date`! >&2

sleep 1

done

Make the script executable with the command below:

sudo chmod +x supervisor_cw_hello.sh

sudo touch /etc/supervisor/conf.d/supervisor_cw_hello.conf

Add the following with nano

[program:supervisor_cw_hello]
command=/home/ayo/supervisor_cw_hello.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/hello.err.log
stdout_logfile=/var/log/hello.out.log

After successfully adding a new program, we should run the following two commands.

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl 

monitor-and-control-os-aws

You can see the process called supervisor_cw_hello with a RUNNING status.

To see all available commands, type help

monitor-and-control-os-aws

The Web Server Client: To allow access to the supervisord web server, open the supervisord configuration file and locate the [inet_http_server] section.

sudo nano /etc/supervisor/supervisord.conf

monitor-and-control-os-aws

Edit the following configuration

[inet_http_server]

port=*:9001

username=user

password=123

monitor-and-control-os-aws

Add username and password and restart the service

sudo systemctl restart supervisord.service

Service is running on port 9001 on your firewall.

http://{server-ip}:9001

monitor-and-control-os-aws

and it is working. This concludes the installation and working of AWS Supervisor for monitoring the OS processes.

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project