🚀 Python for DevOps – Log Monitoring with File Output Today I built a simple automation script to read logs and write alerts to a separate file. 📂 Scenario: Instead of manually checking logs, automate detection of ERROR messages and store them in another file. 💻 Python Code: with open("app.log") as f, open("alerts.log", "w") as out: for line in f: if "ERROR" in line: out.write(line) output: root@satheesha:~# python3 Python 3.12.3 (main, Mar 3 2026, 12:15:18) [GCC 13.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> with open("app.log") as f, open("Alert.log", "w") as out: ... for line in f: ... if "ERROR" in line: ... out.write(line) ... 17 >>> exit() root@satheesha:~# cat Alert.log ERROR: Disk full 🔍 What this does: Reads app.log line by line Filters only ERROR logs Writes them into alerts.log 📌 Why this is useful: Helps in faster troubleshooting Reduces manual log scanning Can be integrated with monitoring systems 🔥 Real DevOps Use Cases: Production log monitoring CI/CD pipeline validation Incident detection and alerting 📈 Next Step: Enhance this script to: Handle multiple log levels (ERROR / WARNING / INFO) Send alerts to email or Slack Monitor logs in real-time (like tail -f) #Python #DevOps #Automation #Scripting #Cloud #Learning #100DaysOfCode
Python Log Monitoring with File Output Automation
More Relevant Posts
-
🚀 Monitor Disk Usage with Python (DevOps Practical Tip) As a DevOps Engineer, keeping an eye on disk usage is critical to avoid unexpected outages in production. Here’s a simple Python script I use to check disk usage of the root filesystem: import subprocess result = subprocess.run(["df", "-h", "/"], capture_output=True, text=True) print(result.stdout) 🔍 What this does: Executes df -h / to fetch disk usage Displays output in a human-readable format 💡 Real-world use case: You can extend this script to trigger alerts when disk usage crosses a threshold (say 80%): for line in result.stdout.split("\n"): if "/" in line: usage_percent = int(line.split()[4].replace("%", "")) if usage_percent > 80: print("⚠️ Alert: Disk usage is above 80%") Output: ubuntu@satheesha:~/python$ python3 check-disk_usage.py Filesystem Size Used Avail Use% Mounted on /dev/sdd 1007G 28G 928G 3% / 🔥 Where this helps: Production server monitoring Preventing downtime due to full disk Automating health checks via cron jobs Integrating with alerting tools (Slack, Email, etc.) Simple scripts like this can save hours of troubleshooting and keep systems stable. #DevOps #Python #Automation #Monitoring #Linux #SRE
To view or add a comment, sign in
-
# 7. Python: A Powerful Language for Modern Development Python is one of the most versatile and widely used programming languages in the world. Known for its simplicity and readability, Python is used across multiple domains including web development, automation, data science, machine learning, and DevOps. One of the reasons for Python’s popularity is its **clean and intuitive syntax**, which makes it easy for beginners to learn while still being powerful enough for complex applications. Python supports multiple programming paradigms, including: • Object-oriented programming • Functional programming • Procedural programming This flexibility allows developers to build a wide variety of applications efficiently. Python also has a vast ecosystem of **libraries and frameworks**. For example: • Django and Flask for web development • Pandas and NumPy for data analysis • TensorFlow and PyTorch for machine learning • Selenium for automation testing In the DevOps world, Python is often used to automate repetitive tasks such as infrastructure management, monitoring, and deployment. Many popular tools like **Ansible and AWS CLI** are built using Python, highlighting its importance in cloud and automation environments. Python’s cross-platform compatibility allows applications to run on Windows, Linux, and macOS without major modifications. This portability makes it a preferred language for developers worldwide. Companies value Python developers because they can build scalable applications, automate workflows, and work with modern technologies such as artificial intelligence and cloud computing. Learning Python is a great investment for anyone entering the technology field. Its versatility, strong community support, and wide range of applications make Python one of the most valuable programming languages today. #Python #Programming #Automation #DevOps #SoftwareDevelopment #Coding
To view or add a comment, sign in
-
🚀 pywho — a debugging painkiller for Python developers (30+ GitHub stars in 1 month 🔥) 💡 What is pywho? A zero-dependency Python CLI that explains your environment, traces imports, and detects module shadowing. No guessing. No scattered checks. Just clear answers. ⚠️ Pain point: Debugging Python issues usually means checking: • Interpreter • Virtualenv • sys.path • pip • Import resolution 👉 All separately → slow, repetitive, and perfect for “works on my machine” problems 📊 Existing tools: • Python built-in site/path inspection • pip debug • Manual import checks 👉 Useful individually, but each shows only part of the picture 🛠️ What pywho does: One CLI that gives you: ✅ Interpreter details ✅ Virtualenv detection ✅ Import tracing ✅ Import resolution insights ✅ Module shadow scanning ✅ JSON output for CI/sharing ➡️ One place, not five ➡️ Zero dependency ➡️ Cross-platform ➡️ Built for real debugging workflows 👨💻 For all Python developers 🔗 GitHub: https://lnkd.in/dMvz9PYM 🔗 PyPI: https://lnkd.in/dM72_8rs 🔗 Docs: https://lnkd.in/dCvUBAeu ♻️ Resharing to support the Python community 🤝 💬 What’s the most confusing Python environment issue you’ve debugged? #Python #PythonDeveloper #PythonDev #PyPI #PythonTools #DebuggingTools #DeveloperTools #DevTools #CLItools #CommandLine #SoftwareEngineering #BackendDevelopment #DevOps #OpenSource #OpenSourceProject #Programming #CodingLife #BuildInPublic #TechInnovation #ProductivityTools #Automation #CI_CD #TestingTools #PythonTips #CodeQuality #SoftwareDevelopment #DevelopersLife #TechCommunity #GitHubProjects
To view or add a comment, sign in
-
-
🚀 pywho — a debugging painkiller for Python developers (~45 stars ⭐ on GitHub 🔥) 💡 What is pywho? A zero-dependency Python CLI that explains your environment, traces imports, and detects module shadowing. No guessing. No scattered checks. Just clear answers. ⚠️ Pain point: Debugging Python issues usually means checking: • Interpreter • Virtualenv • sys.path • pip • Import resolution 👉 All separately → slow, repetitive, and perfect for “works on my machine” problems 📊 Existing tools: • Python built-in site/path inspection • pip debug • Manual import checks 👉 Useful individually, but each shows only part of the picture 🛠️ What pywho does: One CLI that gives you: ✅ Interpreter details ✅ Virtualenv detection ✅ Import tracing ✅ Import resolution insights ✅ Module shadow scanning ✅ JSON output for CI/sharing ➡️ One place, not five ➡️ Zero dependency ➡️ Cross-platform ➡️ Built for real debugging workflows 👨💻 For all Python developers 🔗 GitHub: https://lnkd.in/dMvz9PYM 🔗 PyPI: https://lnkd.in/dM72_8rs 🔗 Docs: https://lnkd.in/dCvUBAeu ♻️ Resharing to support the Python community 🤝 💬 What’s the most confusing Python environment issue you’ve debugged? #Python #PythonDeveloper #PythonDev #PyPI #PythonTools #DebuggingTools #DeveloperTools #DevTools #CLItools #CommandLine #SoftwareEngineering #BackendDevelopment #DevOps #OpenSource #OpenSourceProject #Programming #CodingLife #BuildInPublic #TechInnovation #ProductivityTools #Automation #CI_CD #TestingTools #PythonTips #CodeQuality #SoftwareDevelopment #DevelopersLife #TechCommunity #GitHubProjects
To view or add a comment, sign in
-
-
Easily merge ODS files with Python! With the GroupDocs.Merger Cloud SDK for Python, you can seamlessly combine multiple ODS documents using a simple REST API. This powerful tool saves you time and effort, allowing you to focus on more critical tasks. Unlock the potential of your document management process and streamline your workflow today. https://lnkd.in/djKUiCgd
To view or add a comment, sign in
-
🚀 Python for DevOps – Real-Time Error Monitoring Practiced building a simple real-time log monitoring script using Python to detect errors instantly. 📂 Use Case: In production, logs are continuously generated. We need a way to detect errors in real time instead of manually checking files. 💻 Python Script: import time with open("app.log", "r") as f: f.seek(0, 2) # move to end of file while True: line = f.readline() if not line: time.sleep(1) continue if "ERROR" in line: print("Alert:", line.strip()) Output: ubuntu@satheesha:~/python$ python3 real-time_log-montr.py Alert ERROR: Test Wed Apr 22 08:05:25 UTC 2026 Alert ERROR: Test Wed Apr 22 08:05:27 UTC 2026 Alert ERROR: Test Wed Apr 22 08:05:29 UTC 2026 Alert ERROR: Test Wed Apr 22 08:05:31 UTC 2026 🔍 What this does: Reads log file in real time Starts from end (like tail -f) Continuously checks for new entries Prints alert when ERROR is detected 🔥 Why this matters: Helps detect issues instantly Reduces downtime Automates monitoring tasks 💡 Key Learning: Python can be used to build lightweight monitoring tools, similar to real-world DevOps systems. 📈 Next Step: Add timestamps Handle multiple log levels Send alerts (email/Slack) Auto-restart services on failure #Python #DevOps #Automation #Monitoring #Logging #Scripting #Learning #100DaysOfCode
To view or add a comment, sign in
-
🚀 From Scripts to Systems: A Python Automation Milestone Over the past few weeks, I’ve been deliberately strengthening my Python skills by focusing on real‑world automation, not just isolated scripts or tutorials. As a capstone, I recently completed an end‑to‑end, production‑style automation project, where I built a config‑driven Python system that: • Validates and processes structured CSV data • Applies configurable business rules (PAID / DUE classification) • Generates clean, reusable reports automatically • Integrates with an external API using retries and exponential backoff • Logs every critical step for observability • Persists execution state and run metrics in JSON • Is idempotent and safe to run repeatedly Throughout this journey, I focused heavily on engineering discipline: ✅ dry‑run mindset before writing data ✅ defensive validation of inputs ✅ separation of logic from configuration ✅ graceful failure handling instead of crashes ✅ building automation that can be trusted to run unattended This experience reinforced an important lesson for me: "Automation is not about writing code fast — it’s about building systems that behave correctly when things go wrong". I’m excited to continue building on this foundation as I move deeper into backend and automation‑heavy roles, and eventually into scalable application development. Always happy to connect and learn from others building reliable systems with Python. #Python #Automation #BackendDevelopment #SoftwareEngineering #LearningByBuilding #ResilientSystems #ContinuousLearning
To view or add a comment, sign in
-
Day 64 - Troubleshooting a Python App Deployed on K8s Cluster #100DaysOfDevOps 🧑💻 Today’s Day 64 of #100DaysOfDevOps was a hands-on Kubernetes troubleshooting scenario that felt very close to a real production incident. A Python Flask app deployed on the cluster was completely unavailable, and digging into the Pods revealed an "ImagePullBackOff" error. After investigating with "kubectl describe", I traced the issue to an incorrect container image, which prevented the Pod from ever starting. Fixing that immediately brought the Pods back to life. But that wasn’t the only issue, traffic still wasn’t reaching the app. The Service was misconfigured with "targetPort: 8080" instead of Flask’s default port 5000, meaning requests were being routed to the wrong destination. Updating the Service to use the correct targetPort and ensuring the required nodePort: 32345 made the application accessible externally. This task reinforced a key production lesson: small misconfigurations in image names or port mappings can completely break deployments, and systematic debugging (Pods → Logs → Services) is critical for fast recovery. I’ve documented the full breakdown and fix here: https://lnkd.in/eKtVpMdK Each challenge is sharpening my troubleshooting instincts and deepening my Kubernetes expertise. 💪 #DevOps #Kubernetes #CloudEngineering #K8s #SRE #Troubleshooting #LearningInPublic
To view or add a comment, sign in
-
🚀 Simple Python Script for DevOps Practice In DevOps, even small scripts can make a big difference in automation and monitoring. Here’s a simple Python script I practiced to simulate basic server details and loop operations 👇 name = "server1" cpu_usage = 75 is_running = True print(f"Name: {name}") print(f"CPU Usage: {cpu_usage}%") print(f"Is Running: {is_running}") print("-" * 30) for i in range(6): print(i) print("-" * 30) for i in range(1, 12, 2): print(i) print("-" * 30) for i in range(10, -1, -1): print(i) print("-" * 30) Output: ubuntu@satheesha:~/python$ python3 variable-for_loop.py Name: server1 CPU Usage: 75% Is Running: True ------------------------------ 0 ------------------------------ 1 ------------------------------ 2 ------------------------------ 3 ------------------------------ 4 ------------------------------ 5 ------------------------------ 1 ------------------------------ 3 ------------------------------ 5 ------------------------------ 7 ------------------------------ 9 ------------------------------ 11 ------------------------------ 10 ------------------------------ 9 ------------------------------ 8 ------------------------------ 7 ------------------------------ 6 ------------------------------ 5 ------------------------------ 4 ------------------------------ 3 ------------------------------ 2 ------------------------------ 1 ------------------------------ 0 ------------------------------ 🔹 Key concepts used: ✔ Variables & data types ✔ f-strings for clean output ✔ Loops with range() ✔ Reverse iteration 💡 These basics are very useful for: Automation scripts Monitoring tasks Log analysis Learning step by step and practicing regularly helps build strong DevOps scripting skills. #DevOps #Python #Automation #Scripting #Learning #AWS #Kubernetes #Jenkins
To view or add a comment, sign in
-
Python application Build process: Building a python application involves packaging, dependency resolution, distribution steps that are required for CI/CD and production deployments. the python build process include: 1. organize the project structure myapp/ │ ├── myapp/ # Application source code │ └── __init__.py ├── tests/ # Unit tests ├── pyproject.toml # Modern metadata and build system ├── requirements.txt # Dependency list (optional) └── README.md 2. Declare dependencies use requirements.txt or pyproject.toml to declare dependencies. these are install using pip install eg: pip install -r requirements.txt 3.Build the package python uses setuptools and build to convert your source code into distributable format(sdist and wheel) python3 -m venv venv source venv/bin/activate pip install build python -m build This generates: dist/myapp-0.1.0.tar.gz (source distribution) dist/myapp-0.1.0-py3-none-any.whl (wheel binary) 4.Run unit tests use pytest, unittest and another test framework for code quality pytest tests/ 5. distribute distribute via pypi pip install twine twine upload dist/* 6. Deploy manually or via CI/CD package can be deployed into containers, vms or directly like aws lambda, google cloud run, etc. REAL WORLD EXAMPLE: for a flask based project: . declare dependencies using requirements.txt . create a pyproject.toml for packaging metadata . ran python -m build in ci to produce a wheel . build a docker image with the wheel inside . deploy in kubernetes using helm chart
To view or add a comment, sign in
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development