{"id":29195441,"url":"https://github.com/oluwatobi-roie/sre-diskmonitor","last_synced_at":"2026-04-27T18:03:30.037Z","repository":{"id":300238036,"uuid":"1005637103","full_name":"oluwatobi-roie/SRE-diskMonitor","owner":"oluwatobi-roie","description":"Monitor disk usage on a MySQL server and auto-reset binary logs safely when space runs low.","archived":false,"fork":false,"pushed_at":"2025-06-23T00:42:57.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-02T05:04:26.691Z","etag":null,"topics":["automation","bash","cronjob","devops","diskmonitoring","mysql","server-maintenance","sre"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oluwatobi-roie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-20T14:51:43.000Z","updated_at":"2025-06-23T00:43:00.000Z","dependencies_parsed_at":"2025-06-20T15:44:03.977Z","dependency_job_id":"0c7863e5-2abc-4df1-a17e-54ffb65b54ae","html_url":"https://github.com/oluwatobi-roie/SRE-diskMonitor","commit_stats":null,"previous_names":["oluwatobi-roie/sre-diskmonitor"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oluwatobi-roie/SRE-diskMonitor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oluwatobi-roie%2FSRE-diskMonitor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oluwatobi-roie%2FSRE-diskMonitor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oluwatobi-roie%2FSRE-diskMonitor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oluwatobi-roie%2FSRE-diskMonitor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oluwatobi-roie","download_url":"https://codeload.github.com/oluwatobi-roie/SRE-diskMonitor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oluwatobi-roie%2FSRE-diskMonitor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32348058,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T17:12:42.749Z","status":"ssl_error","status_checked_at":"2026-04-27T17:12:41.658Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash","cronjob","devops","diskmonitoring","mysql","server-maintenance","sre"],"created_at":"2025-07-02T05:04:28.128Z","updated_at":"2026-04-27T18:03:30.018Z","avatar_url":"https://github.com/oluwatobi-roie.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# MySQL Disk Monitor and Auto RESET MASTER Script\n\nThis project provides a secure, automated solution to monitor the disk usage of a specific block device (`/dev/vdb1`) and automatically execute the MySQL `RESET MASTER;` command when disk usage exceeds a set threshold (default: 95%).\n\n\u003e ⚠️ **Warning:** `RESET MASTER;` will delete **all binary logs** from your MySQL server. Only use this if:\n\u003e - You're **not using MySQL replication**.\n\u003e - You understand the implications of losing binary log history.\n\n---\n\n## 📌 Project Objectives\n\n- 🔍 Monitor `/dev/vdb1` mounted at `/mnt/blockstorage`\n- ⚙️ Automatically run `RESET MASTER;` when disk usage ≥ 95%\n- 🪵 Log every run with a timestamp and status (reset or skip)\n- 🔐 Securely handle MySQL credentials using `.my.cnf`\n- 🕑 Run automatically using a cron job (default: every 10 minutes)\n\n---\n\n## 🧱 System Requirements\n\n- Linux server (e.g., Ubuntu)\n- MySQL Server installed\n- Root or sudo access\n- Target disk mounted at `/mnt/blockstorage` (linked to `/dev/vdb1`)\n\n---\n\n## 🛡️ MySQL Credential Security\n\nTo avoid hardcoding credentials in the script, use a secure MySQL client config file:\n\n### Create `/root/.my.cnf`\n\n```ini\n[client]\nuser=yousqlusername\npassword=yousqlpassword[leaveblank if password is empty]\n```\n\n\u003e Leave the password empty if your root MySQL user has no password.\n\nSet appropriate permissions:\n\n```bash\nsudo chmod 600 /root/.my.cnf\n```\n\nThis allows you to run MySQL commands without specifying `-u` or `-p` in the script.\n\n---\n\n## ⚙️ Script Setup\n\n### 1. Create the Monitor Script\n\nCreate the script file:\n\n```bash\nsudo nano /usr/local/bin/check_vdb1_and_reset_master.sh\n```\n\nPaste the following:\n\n```bash\n#!/bin/bash\n\n# Threshold for disk usage\nTHRESHOLD=95\n\n# Target mount point to monitor\nTARGET_MOUNT=\"/mnt/blockstorage\"\n\n# Log file path\nLOG_FILE=\"/var/log/mysql_reset_monitor.log\"\n\n# Get current usage of target mount\nUSAGE=$(df -h | grep \"$TARGET_MOUNT\" | awk '{print $5}' | sed 's/%//')\n\n# Get current timestamp\nTIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')\n\n# If unable to get usage\nif [ -z \"$USAGE\" ]; then\n  echo \"$TIMESTAMP - ERROR: Could not determine disk usage for $TARGET_MOUNT\" \u003e\u003e \"$LOG_FILE\"\n  exit 1\nfi\n\n# Check if usage exceeds threshold\nif [ \"$USAGE\" -ge \"$THRESHOLD\" ]; then\n  echo \"$TIMESTAMP - Disk usage at ${USAGE}% on $TARGET_MOUNT. Running RESET MASTER...\" \u003e\u003e \"$LOG_FILE\"\n  mysql -e \"RESET MASTER;\"\n  if [ $? -eq 0 ]; then\n    echo \"$TIMESTAMP - RESET MASTER executed successfully.\" \u003e\u003e \"$LOG_FILE\"\n  else\n    echo \"$TIMESTAMP - ERROR: RESET MASTER command failed.\" \u003e\u003e \"$LOG_FILE\"\n  fi\nelse\n  echo \"$TIMESTAMP - Disk usage at ${USAGE}% on $TARGET_MOUNT. No action taken.\" \u003e\u003e \"$LOG_FILE\"\nfi\n```\n\nMake it executable:\n\n```bash\nsudo chmod +x /usr/local/bin/check_vdb1_and_reset_master.sh\n```\n\n---\n\n## 🧭 Cron Job Setup\n\nTo automate the script every 10 minutes:\n\n### Edit the root user's crontab:\n\n```bash\nsudo crontab -e\n```\n\n### Add this line:\n\n```cron\n*/10 * * * * /usr/local/bin/check_vdb1_and_reset_master.sh\n```\n\n---\n\n## 📄 Log Output\n\nAll script activity is logged to:\n\n```bash\n/var/log/mysql_reset_monitor.log\n```\n\n### Example Entries:\n\n```\n2025-06-18 14:10:01 - Disk usage at 96% on /mnt/blockstorage. Running RESET MASTER...\n2025-06-18 14:10:02 - RESET MASTER executed successfully.\n2025-06-18 14:20:01 - Disk usage at 91% on /mnt/blockstorage. No action taken.\n```\n\n---\n\n## 🧠 Optional Enhancements\n\n### 🔁 Use Safer Binary Log Rotation (Recommended for Production)\n\nInstead of deleting **all** logs, rotate logs older than a few days:\n\n```sql\nPURGE BINARY LOGS BEFORE NOW() - INTERVAL 3 DAY;\n```\n\nReplace this in your script if you prefer safer cleanup.\n\n---\n\n### 🔔 Email Notifications (Optional)\n\nYou can modify the script to send an email alert when `RESET MASTER` is triggered:\n\n```bash\necho \"Disk usage reached $USAGE%. RESET MASTER executed.\" | mail -s \"MySQL Reset Triggered\" your@email.com\n```\n\n---\n\n## ✅ Summary\n\n| Feature                  | Description                                            |\n|--------------------------|--------------------------------------------------------|\n| Disk Monitored           | `/mnt/blockstorage` (`/dev/vdb1`)                     |\n| Threshold                | 95% disk usage                                         |\n| MySQL Command            | `RESET MASTER;`                                        |\n| Credentials              | Stored securely in `/root/.my.cnf`                    |\n| Execution Frequency      | Every 10 minutes via cron                              |\n| Logs File                | `/var/log/mysql_reset_monitor.log`                    |\n| Script Location          | `/usr/local/bin/check_vdb1_and_reset_master.sh`       |\n\n---\n\n## 👨‍🔧 Maintainer Notes\n\n- Monitor the log file regularly.\n- Ensure `/mnt/blockstorage` is correctly mounted on reboot.\n- Rotate `/var/log/mysql_reset_monitor.log` with `logrotate` if needed.\n- Regularly back up important data before using destructive MySQL commands.\n\n---\n\n## 📬 Contact\n\n🔗 [Connect with me on LinkedIn](https://www.linkedin.com/in/akomolafetech/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foluwatobi-roie%2Fsre-diskmonitor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foluwatobi-roie%2Fsre-diskmonitor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foluwatobi-roie%2Fsre-diskmonitor/lists"}