System Monitor with mWatcher

Harry - The DevOps Guy
4 min readFeb 27, 2021

Hi Everyone,

Here I would lke to explain one of the tool, called mWatcher. you can configure this tool to monitor your ubuntu server and services very smartly. it developed in shell scripting. so it won’t required any third party utility. it works on system utility like curl, grep, sed, awk, etc.

Monitor Linux System Smartly

Features

  1. Monitor CPU, Disk, Memory Utilization.
  2. Monitor Systemd services and perform action( restart, start, etc)
  3. Notification - Slack, Email
  4. Generate Daily / Weekly Server health Status report.
  5. Automatically Block Spammer/attacker/ bad requests if you are using nginx/apache2.

How to Install mWatcher ?

  1. You can follow mWatcher repository Document to install mWatcher .

2. you can use below commands to install mWatcher

sudo curl -sL "https://github.com/HarryTheDevOpsGuy/mwatcher/raw/master/$(uname -p)/mwatcher" -o /usr/bin/mwatcher
sudo chmod +x /usr/bin/mwatcher

How to verify ?

# To check Version
mwatcher -v
# To help page.
mwatcher -h

mwatcher [OPTION]
-e email Send Email Notification
-s "#devops" Send Slack Notification
-u units:action monitor service
-m 80:alarmtype Notify if used momory >= 80% ( alerm type warning, critical, etc)
-c 80:alarmtype Notify if used cpu >= 80% ( alerm type warning, critical, etc)
-d 80:alarmtype Notify if used disk >= 80% ( alerm type warning, critical, etc)
-a file_path Aattach file with email Notification.
-x interval Repeat alert Interval in minutes.
-h Display this help
-v Display version

DEFAULT VARIABLES | CONFIGURATIONS

You can edit default threshold rules file /etc/mwatcher/rules.sh

# vim /etc/mwatcher/rules.sh
### User defined variables
## For more details visit https://github.com/HarryTheDevOpsGuy/mwatcher
REPEAT_NOTIFICATION_INTERVAL="30 minutes"
LOG_DIR="/tmp/mwatcher.log"
# Time Interval to check CPU MEMORY DISK Utilization to avaid spikes
TIME_INTERVAL="2" # 2 Seconds
# Threshold configure ( default no Threshold)
MEMORY_ALARM=( 70:info 80:Warning 90:Critical )
CPU_ALARM=(70:info 80:Warning 90:Critical )
DISK_ALARM=( 70:info 80:warning 90:Critical )
#SERVICE_STATUS=( nginx:restart mysql ssh )
# Email Notification
EMAIL_NOTIFICATION="false"
FULL_HTML_REPORT_INTERVAL="1 days"
#EMAIL_NOTIFY_TO=( youremail@gmail.com )
# Slack Notification
SLACK_NOTIFICATION="false"
# export SLACK_CLI_TOKEN=xoxb-343434345454-sdlfkdf-kdfde-example-token
# export SLACK_CHANNEL='#devops'
# BLOCK_SPAMMER="true"
# BLOCK_SPAMMER_RELOAD_NGINX="true"
# BLOCK_RISK_LEVEL="critical\|High" # Critical\|High\|Medium
# # Check top 30 failed requests
# FAIL_REQUEST_COUNT="30"
# Default Email Template
# DEFAULT_MWATCHER_TEMPLATE=https://cdn.jsdelivr.net/gh/mCloud-Automation/mData/mWatcher/mwatcher-v2.html

Example 1 — To trigger alert based on threshold on slack and email

If you want to get alert on your slack and email. it will send you full html report on your email id once in day. also it will notify you if any resource (cpu, memory, disk) utilization goes high. you can use command arguments multiple times.

mwatcher -c 80:warning -d 80:critical -m 80:warning -s '#SLACK_CHANNEL' -e yourname@domain.com
  • -c 80:warning - WARNING trigger alert if CPU usage greater than 80%.
  • -d 80:critical - CRITICAL alert if DISK usage greater than 80%.
  • -m 90:critical - CRITICAL alert if MEMORY usage greater than 90%
  • -s '#SLACK_CHANNEL' - Notify on Slack channel
  • -e yourname@domain.com - Notify on email.
  • Note : - it will send you full html report daily.

Example 2 — To Generate html report only.

You can generate html report only. this command will not trigger any alert.

mwatcher /tmp/daily_report.html

Configure Cronjobs To Get email alert daily or weekly.

You can schedule cronjob according to your choice. Here is few example for you. you can use any of one.

# Schedule cron every 5 min for memory monitoring
*/5 * * * * /usr/bin/mwater -m 80:warning -m 90:critical -s '#SLACK_CHANNEL' -e yourname@domain.com

Sample Email Notification

Server Health Report

Here is sample email for server health report. you will get daily/weekly.

Other mCloud Automation Tools and utitlity

You can Visit my Portfolio to read more about mCloud Automation Tools.

Thanks

Harry - The DevOps Guy

My Portfolio : https://harrythedevopsguy.github.io/
Connect me if any query.

--

--