Intermediate

📊 Monitoring

Watch your system. Catch problems before users notice.

📖 What is Monitoring?

Monitoring means watching your system all the time. You collect data about CPU, memory, errors, and speed. If something goes wrong, you get an alert.

💡 Simple Example:
Think of a hospital patient. The heart monitor beeps if something is wrong. Monitoring is the heart monitor for your app.

🤔 Why Monitor?

  • Find problems early — Before users complain.
  • Understand performance — See what is slow and why.
  • Plan for growth — Know when to add more servers.
  • Prove reliability — Show uptime to clients.

🌍 Real Client Example

Client: An online learning platform with 50,000 students.

Problem: Every Monday morning, the site becomes very slow. Students complain. The client does not know why.

Solution with Monitoring:

  1. Set up Prometheus to collect CPU, memory, and request data.
  2. Set up Grafana dashboards to see the data visually.
  3. Add alerts that send an email if CPU goes above 80%.
  4. Found the problem: a nightly report was running during peak hours.

Result: We moved the report to 3 AM. The site is fast on Monday mornings. Students are happy.

🛠️ Key Monitoring Tools

Prometheus
Collects numbers (metrics) from your app. Stores them over time.
Grafana
Shows the numbers in beautiful dashboards.
ELK Stack
Collects and searches log files.
Alertmanager
Sends alerts by email, Slack, or SMS.

📈 Example: Key Metrics to Watch

MetricWhat It MeansGood Value
CPU UsageHow busy the CPU isBelow 70%
Memory UsageHow much RAM is usedBelow 80%
Response TimeHow long a request takesBelow 500 ms
Error RatePercentage of failed requestsBelow 1%
UptimeTime the system is onlineAbove 99.9%

✍️ Your First Alert Rule

This Prometheus rule sends an alert if CPU is too high for 5 minutes:

groups:
- name: example
  rules:
  - alert: HighCpuUsage
    expr: cpu_usage > 80
    for: 5m
    labels:
      severity: warning
    annotations:
      summary: "CPU usage is above 80% for 5 minutes"

What this does:

  • expr — The condition (CPU above 80%).
  • for — Must be true for 5 minutes.
  • labels — Mark the alert type.
  • annotations — A message to send.

✅ What You Learned

  • Monitoring watches your system all the time.
  • Prometheus collects numbers. Grafana shows them.
  • Alerts tell you when something is wrong.
  • Good to watch: CPU, memory, response time, errors, uptime.