πŸ” Keeping Your Linux Services in Check: How I Use Monit for Bulletproof Monitoring 🚨

> *β€œIf it can fail silently, it probably will.”* > β€” Me, after hours of debugging why a service stopped 6 hours ago.

February 03, 2025
Victor Nthuli
Linux Security
5 min read

πŸ›  What is Monit?

Monit is a lightweight, yet powerful utility for monitoring and managing system processes, files, directories, and more. It’s like having a silent watchdog that not only barks when something breaks β€” it fixes it.

Whether you’re running a homelab, a production server, or something in between β€” Monit ensures your critical services stay alive.


πŸ”§ My Setup β€” What I Monitor

I use Monit to manage and recover key services on my stack:

  • πŸ›‘ wazuh-manager, wazuh-dashboard, wazuh-indexer
  • πŸ“Š grafana, uptime-kuma, fluent-bit
  • πŸ” clamav, fail2ban, tailscale, haproxy, sshd, mariadb
  • ⚠️ Custom alerting via Discord and email

Each service has a dedicated configuration file under /etc/monit/conf.d/.

Example: grafana-server

check process grafana-server matching "grafana-server"
  start program = "/usr/bin/systemctl start grafana-server"
  stop program  = "/usr/bin/systemctl stop grafana-server"
  if failed port 3000 protocol http with timeout 30 seconds then restart
  if 3 restarts within 5 cycles then unmonitor
  if does not exist for 3 cycles then exec "/etc/monit/discord-alert.sh grafana-server failed"

βœ… Auto-restart
βœ… Rate-limiting restarts
βœ… Discord webhook notifications


πŸ“¬ Discord Alerts: No More Missed Downtime

I created a small Bash script that pushes alerts directly to Discord using a webhook. Here’s how it works:

/etc/monit/discord-alert.sh <service> <status>

Sample Discord JSON payload:

{
  "content": "**wazuh-manager is failed**",
  "embeds": [
    {
      "title": "Service Alert",
      "description": "**wazuh-manager** is **failed**",
      "color": 16711680
    }
  ]
}

Monit executes this when a service fails for 3 cycles. It’s fast, clean, and doesn’t require mail relay configurations.


πŸ“§ Email Alerts (Optional)

I also configured Monit to send email alerts through Gmail using App Passwords:

set mailserver smtp.gmail.com port 587
  username "ngashauth@gmail.com" password "your-app-password"
  using STARTTLS

πŸ’‘ Tip: Use Gmail’s “App Password” instead of your real password to avoid authentication issues.


πŸ§ͺ Simulating Failure β€” Why Testing Matters

I don’t deploy monitoring and pray. I simulate real failures:

sudo systemctl stop wazuh-manager

Then watch Monit take action:

sudo tail -f /var/log/monit.log

Expected log:

[UTC] error    : 'wazuh-manager' process is not running
[UTC] info     : 'wazuh-manager' trying to restart

After 3 failures, you’ll see:

[UTC] alert    : 'wazuh-manager' failed 3 times in 5 cycles β€” unmonitored

Boom β€” it’s working.


😡 Issues I Faced (And Fixed)

Here are a few challenges I ran into:

πŸ”„ Wazuh Restart Problem

Monit wasn’t restarting wazuh-manager because it was looking for the wrong process name.

βœ… Fixed by updating config:

check process wazuh-manager matching "wazuh-analysisd"

πŸ“§ SSL Issues with Gmail

Monit couldn’t send emails via Gmail due to outdated SSL settings.

βœ… Fixed by switching to:

using STARTTLS

βœ… Also enabled App Passwords for Gmail login.


πŸ” Crash Loop Prevention

Sometimes a broken service causes infinite restarts. I prevent this with:

if 3 restarts within 5 cycles then unmonitor

βœ… Keeps the server sane
βœ… Prevents resource exhaustion


πŸ”‘ Recommendations

Here’s what I recommend to anyone setting up Monit:

βœ… 1. Use Discord or Telegram Webhooks

They’re easier to test, faster to receive, and don’t rely on SMTP servers.

βœ… 2. Test Your Configs

Use:

monit -t

Before restarting:

sudo systemctl restart monit

βœ… 3. Rate-Limit Restarts

Prevent infinite loops:

if 3 restarts within 5 cycles then unmonitor

βœ… 4. Don’t Just Monitor β€” Simulate Failures

Testing is part of setup. Simulate and verify that Monit responds as expected.

βœ… 5. Monitor the Monitor

Enable Monit’s web dashboard:

set httpd port 2812 and
  allow admin:monit

Access it via: http://localhost:2812


🎯 Final Thoughts

Monit is simple yet powerful. It’s a great watchdog for anyone running services β€” whether on a Raspberry Pi or in production.

Add some scripting, test your setup, and sleep better at night. πŸ›ŒπŸ’€


Would you like me to convert this into a Markdown file or publish-ready HTML version?

Tags

Linux Security Hardening SELinux Kernel Security System Hardening

Victor Nthuli

Security Operations Engineer specializing in incident response, threat hunting, and compliance alignment for regulated industries.

Related Posts

April 22, 2025

My Terminal is My Happy Place: A Tour of My CLI Setup

Read More
April 19, 2025

Comprehensive Network Traffic Monitoring: A Deep Dive into Zeek, MySQL, and Grafana Integration

This project provides a comprehensive solution for capturing network traffic, processing it with Zeek (formerly Bro), and storing the enriched logs into a MySQL database for further analysis and visualization. It includes scripts and configurations to enhance Zeek's capabilities with GeoIP, ASN data, and JA3/JA4 fingerprinting, enabling detailed network security monitoring and analysis.

Read More

Table of Contents

Loading...

Recent Posts

  • My Terminal is My Happy Place: A Tour of My CLI Setup

    April 22, 2025

    Read Post
  • Comprehensive Network Traffic Monitoring: A Deep Dive into Zeek, MySQL, and Grafana Integration

    April 19, 2025

    Read Post
  • Bookmarklet DeepΒ Dive: Harvest Every JavaScript URL on a Page with a Single Line

    April 10, 2025

    Read Post
  • Ultimate Command Arsenal: Master Wireshark, Linux, and Windows CLI

    April 07, 2025

    Read Post
  • ZeroDay Odyssey: A Cyberpunk Framework for Web Application Penetration Testing

    April 05, 2025

    Read Post
  • Mastering Cybersecurity: A Complete Roadmap from Beginner to Expert

    April 02, 2025

    Read Post
  • Responsible Disclosure: Browser DevTools and Direct File Access in SlidesGPT

    April 01, 2025

    Read Post
  • Bluewave vs Uptime Kuma: A Real-World Comparison for Monitoring Uptime and Beyond

    March 26, 2025

    Read Post
  • Nextcloud

    March 25, 2025

    Read Post
  • πŸ” Keeping Your Linux Services in Check: How I Use Monit for Bulletproof Monitoring 🚨

    February 03, 2025

    Current Post

About the Author

Victor Nthuli is a Security Operations Engineer with expertise in incident response, SIEM implementation, and threat hunting. With a background in cybersecurity and a passion for Linux systems, he provides insights based on real-world experience.

Learn More

Subscribe for Security Updates

Get notified when new security articles and insights are published.

Need Enterprise Security Solutions?

Visit SocDev Africa for comprehensive security services and software development solutions for your organization.

Visit SocDev.Africa