🚀 Simple yet powerful way to monitor your server's health using GitHub Actions and Gmail!
In the fast-paced world of tech, server downtime can be more than just an inconvenience. It can lead to lost revenue and a tarnished reputation. That's why proactive monitoring is a cornerstone of any robust DevOps strategy. Today, I'm excited to share a simple practical guide on setting up an automated server monitoring utility using GitHub Actions. This tool will not only keep an eye on your server health but also send timely alerts, ensuring you're always in the loop 🔁
🛠️ Gmail and GitHub Configuration
Gmail Settings:
- Enable 2FA Auth: Visit this link to enable Two-Factor Authentication (2FA) on your Gmail account.
- Create App Passwords: For GitHub Actions to send emails on your behalf, you'll need an app password. Generate one at myaccount.google.com/apppasswords.
GitHub Settings:
- Create a New Repository: Start by creating a new repository on GitHub to house your monitoring workflow.
- Repository Secrets: Navigate to your repo settings(the one created in the above step), then to 'Secrets & variables' under 'Actions'. Here, you'll create new repo secrets and create descriptive secrets variables to store below data
a. Variable for "from: gmail address" - the one used to enable the 2FA auth
b. Variable for "from gmail address's app password" - the one used to enable the 2FA auth
c. Variable for server URL in which the monitoring needs to be enabled
d. Variable for "to: email address" to receive the alerts.
📝 GitHub Actions Workflow
Now that we've set up our environment, it's time to write the yml file that will orchestrate the monitoring actions. This file, typically named main.yml or workflow.yml, will define the triggers, jobs, and steps that GitHub Actions will execute.
Here's what the yml code might look like:
This will run every hour. It can be configurable by adjusting the cron definition. https://crontab.guru/#0_*_*_*_*
👀 Real-Time Monitoring and Alerts
With your GitHub Actions workflow set up, you'll be able to monitor your server's health in real-time.
And, the email sent by the Actions looks like this
The alert can be sent to the development channels by integrating the Actions with Slack or Discord ✌🏼