metricsmonitoring.py is a Python script for monitoring Pantheon site metrics, detecting traffic anomalies, and alerting on low cache efficiency. It sends detailed, actionable Slack notifications to help you quickly identify and address performance issues.
- Monitors multiple Pantheon sites for traffic spikes and cache efficiency
- Sends rich Slack alerts with historical trends, performance impact, and improvement tips
- Integrates with Pantheon’s Terminus CLI
- Easy configuration via YAML and environment variables
- Python 3.7+
- Terminus CLI
- Slack webhook URL
Python dependencies (install with pip install -r requirements.txt
):
- pandas
- requests
- pyyaml
- python-dotenv
- matplotlib
- pillow
- Clone the repository
- Install dependencies
pip install -r requirements.txt
Create a .env file with your Slack webhook URL. There is an example file for this as well, called (.env.example):
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
- Edit sites.yaml to list your Pantheon site names and thresholds.
Should look like this when you setup your sites.yaml file, I have also inlucded an example file as well. (example.sites.yaml):
threshold_percent: 25
sites_to_monitor:
- site1
- site2
- site3
Ensure Terminus is installed and accessible, if not run this command:
terminus auth:login
If not in your PATH, set the TERMINUS_COMMAND environment variable to the full path. But this script will look for this on initial script run
Run the script to check weekly metrics:
python metricsmonitoring.py
Or for daily metrics:
python metricsmonitoring.py --day
When you run this script, it will create a metricsmonitoring.log file that you can use for debugging or just info when it runs.
- When running under cron, the TERMINUS_COMMAND entry might be required. Here is an example below:
TERMINUS_COMMAND=/usr/local/bin/terminus
You may need to adjust that to your path if you running crons
Included in this repo is a .env.example file and a example.sites.yaml file. Just rename the .env.example file to .env and the example.sites.yaml file to sites.yaml and put your own Webhook and sites in.
Make sure you are running a virtual enviroment to run commands like (pip install -r requirements.txt
). You can run this command if you are on any Linux based platform:
python3 -m venv venv && source venv/bin/activate'
Slack alerts include:
- Site name and environment
- Traffic anomaly detection
- Cache efficiency with historical trends and actionable advice
- Direct link to the Pantheon dashboard
- Curt Hayman
- Terminus
- pandas
- requests
- pyyaml
- python-dotenv
- matplotlib
- pillow