<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Emmanuel Onesime</title>
    <description>The latest articles on DEV Community by Emmanuel Onesime (@emmanuel_onesime_2dce9e5b).</description>
    <link>https://dev.to/emmanuel_onesime_2dce9e5b</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3165123%2Fc260e341-d12f-4371-b686-bc2e1d69e48c.jpg</url>
      <title>DEV Community: Emmanuel Onesime</title>
      <link>https://dev.to/emmanuel_onesime_2dce9e5b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emmanuel_onesime_2dce9e5b"/>
    <language>en</language>
    <item>
      <title>🔧 Monitoring Server Health with a Python Script That Runs Every Minute</title>
      <dc:creator>Emmanuel Onesime</dc:creator>
      <pubDate>Thu, 15 May 2025 08:54:26 +0000</pubDate>
      <link>https://dev.to/emmanuel_onesime_2dce9e5b/monitoring-server-health-with-a-python-script-that-runs-every-minute-1fk6</link>
      <guid>https://dev.to/emmanuel_onesime_2dce9e5b/monitoring-server-health-with-a-python-script-that-runs-every-minute-1fk6</guid>
      <description>&lt;p&gt;Introduction&lt;br&gt;
In any production environment, monitoring server performance is essential for maintaining availability and preventing system failures. For system administrators, real-time information about memory, CPU, and disk usage is crucial to ensure that infrastructure remains healthy.&lt;br&gt;
In this article, we'll walk through creating a Python script that runs every minute, collects server health metrics, and sends a report via email to a system administrator. We'll also log each execution and use tail -f to monitor logs in real-time.&lt;br&gt;
Steps to Follow:&lt;br&gt;
Prepare Your Environment&lt;/p&gt;

&lt;p&gt;1.1 First, create a Python virtual environment:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjtdvev4vw4s6b2saktq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgjtdvev4vw4s6b2saktq.png" alt="Image description" width="800" height="28"&gt;&lt;/a&gt;&lt;br&gt;
1.2  install the required packages:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsq77jcggsj1kr4widf8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhsq77jcggsj1kr4widf8.png" alt="Image description" width="800" height="67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a .env File for Your Secrets
In your home directory, create the file /home/emma/.env with the following content (replace with your actual credentials):&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xgj9r51hgvnapgh09ar.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xgj9r51hgvnapgh09ar.png" alt="Image description" width="378" height="62"&gt;&lt;/a&gt;&lt;br&gt;
Notice: The EMAIL_PASSWORD is your Google App Password, not your real Gmail password.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write the Python Script
Create the file /home/emma/server_health_report.py with the following code:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65gmu70f1qv34ej3duu2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F65gmu70f1qv34ej3duu2.png" alt="Image description" width="800" height="376"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Schedule the Script to Run Every Minute
4.1 Edit your crontab:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vie7w9ijmd88po6rgs7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vie7w9ijmd88po6rgs7.png" alt="Image description" width="295" height="35"&gt;&lt;/a&gt;&lt;br&gt;
4.2 Add the following line:&lt;br&gt;
****/home/emma/env/bin/python3/home/emma/server_health_report.y&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzddq0o1wj20r2lmw0706.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzddq0o1wj20r2lmw0706.png" alt="Image description" width="770" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Monitor the Log in Real-Time&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1dl6ahcn6ftj55mgygj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd1dl6ahcn6ftj55mgygj.png" alt="Image description" width="495" height="16"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc8coeae7szlwkjqelprg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc8coeae7szlwkjqelprg.png" alt="Image description" width="800" height="158"&gt;&lt;/a&gt;&lt;br&gt;
Conclusion&lt;br&gt;
By following these steps, you've built an automated monitoring system using Python that runs every minute, gathers key server metrics, logs the results, and sends real-time performance data via email. This setup enhances visibility and helps system administrators react promptly to any issues - improving reliability and efficiency in server management.&lt;/p&gt;

</description>
      <category>python</category>
      <category>crontab</category>
      <category>linux</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
