Skip to content

Fully configurable bash script that detects CPU abuse and sends a webhook alert.

License

Notifications You must be signed in to change notification settings

noxitylabs/virtfusion-cpu-abuse-detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

CPU Monitoring Script for Hypervisors

This CPU Monitoring Script is a practical tool designed to monitor and alert about the CPU usage abuse for virtual machines on Virtfusion Debian hypervisors. It uses Virsh to collect data and integrate with an SRE management platform like Squadcast to send notifications via outgoing webhooks.


Table of Contents


Getting Started

To use this script:

  1. Ensure that all dependencies are installed on your hypervisor.
  2. Clone the repository onto your hypervisor in desired location. We recommend /usr/local/bin/virtfusion_helpers.
  3. Add execute permissions to the script using chmod +x /usr/local/bin/virtfusion_helpers/abuse-detector.sh.
  4. Schedule the script to run at regular intervals using CRON. Create a file in /etc/cron.d/ named virtfusion_abuse-detector with the following content (adjust the path and frequency as needed):
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
* * * * * root /usr/local/bin/virtfusion_helpers/abuse-detector.sh >/dev/null 2>&1
  1. Adjust the threshold values, notification endpoints and other "Editable fields" as per your requirements at the beggining of the script.
  2. Adjust the SRE management platform's deduplication rules to avoid duplicate notifications.
  3. Adjust the webhook payload to your liking. Currently it's formatted for Squadcast's incoming webhook format.

Dependencies

  • Utilities: curl, bc, awk and grep, should be present on the system.
  • SRE management platform such as Squadcast/OpsGenie, for sending notification POST requests. You can replace this with anything that accepts POST webhook requests to handle the notifications.

Authors


Roadmap / Ideas

  • Make data collection more reliable by using Virsh.
  • Redo the CPU time calculation from scratch to be more accurate.
  • Ability to run the script anywhere, not just on the hypervisor - (Requires Virtfusion API endpoint for data collection).
  • Ability to automatically throttle VM CPU % - (Requires Virtfusion API endpoint).

Contributing

Contributions to this project are highly appreciated. If you have ideas for improvements or enhancements, please feel free to open a pull request or issue. All contributions will be credited appropriately.


Acknowledgements

This script was developed out of a personal need and in response to the community's demand for a reliable CPU monitoring tool for Virtfusion Debian hypervisors without the need for external tools such as HetrixTools, Grafana/Prometheus, netdata etc...

CRON code was adapted from Virtfusion's official disaster backup automation guide, to remain consistent with the rest of the Virtfusion ecosystem.

Special thanks to Phill, the creator of Virtfusion, for providing the code segment that calculates CPU time. This ensures that the usage values are as closely aligned as possible with those used by Virtfusion (in statistic graphs), thereby offering a high degree of accuracy.

About

Fully configurable bash script that detects CPU abuse and sends a webhook alert.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages