πŸ”§ DevOps

Monitoring

Monitoring

Real-time observation of system status. Prometheus, Grafana, Datadog.

πŸ“– Detailed Explanation

Monitoring is the activity of continuously collecting, analyzing, and visualizing the status and performance of systems, applications, and infrastructure. The core goals of monitoring are to detect problems in advance, respond quickly when failures occur, and understand the health of the system.

Monitoring is broadly divided into infrastructure monitoring and application monitoring. Infrastructure monitoring tracks system resources such as CPU, memory, disk, and network. Application monitoring (APM) tracks business metrics such as request processing time, error rate, and throughput.

Metrics are stored as time series data, and changes over time are analyzed. Key metrics include the RED method (Rate, Errors, Duration) and the USE method (Utilization, Saturation, Errors). Service health is judged by measuring SLIs (Service Level Indicators), which define service quality, and comparing them with the target values, SLOs (Service Level Objectives).

Representative monitoring tools include the open-source Prometheus+Grafana stack and the commercial services Datadog, New Relic, and Dynatrace. Prometheus collects metrics using a pull model and is queried with PromQL, and dashboards are built in Grafana. Threshold-based alerts are set up by integrating with Alertmanager.

πŸ’» Code Example

# prometheus.yml - Prometheus μ„€μ •
global:
  scrape_interval: 15s      # λ©”νŠΈλ¦­ μˆ˜μ§‘ μ£ΌκΈ°
  evaluation_interval: 15s  # μ•Œλ¦Ό κ·œμΉ™ 평가 μ£ΌκΈ°

alerting:
  alertmanagers:
    - static_configs:
        - targets: ['alertmanager:9093']

rule_files:
  - "alerts/*.yml"

scrape_configs:
  # Prometheus 자체 λͺ¨λ‹ˆν„°λ§
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  # Kubernetes Pod μžλ™ 발견
  - job_name: 'kubernetes-pods'
    kubernetes_sd_configs:
      - role: pod
    relabel_configs:
      # prometheus.io/scrape: "true" μ–΄λ…Έν…Œμ΄μ…˜μ΄ μžˆλŠ” Pod만
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
        action: keep
        regex: true
      # μ»€μŠ€ν…€ 경둜 지원
      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
        action: replace
        target_label: __metrics_path__
        regex: (.+)
      # 포트 μ§€μ •
      - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
        action: replace
        target_label: __address__
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
# alerts/api-alerts.yml - μ•Œλ¦Ό κ·œμΉ™
groups:
- name: api-alerts
  rules:
  # 높은 μ—λŸ¬μœ¨ 감지
  - alert: HighErrorRate
    expr: |
      sum(rate(http_requests_total{status=~"5.."}[5m])) by (service)
      /
      sum(rate(http_requests_total[5m])) by (service)
      > 0.05
    for: 5m
    labels:
      severity: critical
    annotations:
      summary: "High error rate on {{ $labels.service }}"
      description: "Error rate is {{ $value | humanizePercentage }}"

  # 느린 응닡 μ‹œκ°„
  - alert: HighLatency
    expr: |
      histogram_quantile(0.95,
        sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service)
      ) > 1
    for: 10m
    labels:
      severity: warning
    annotations:
      summary: "P95 latency above 1s on {{ $labels.service }}"

  # Pod λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰
  - alert: PodHighMemory
    expr: |
      container_memory_working_set_bytes / container_spec_memory_limit_bytes > 0.9
    for: 15m
    labels:
      severity: warning

πŸ—£οΈ How It's Said in Practice

SRE: "We got way too many alerts over the weekend. It's at the level of alert fatigue."

Developer: "Most of them are HighCPU alerts, and they fire every time the cron job runs..."

Senior: "Let's suppress alerts during the cron job window, raise the CPU threshold, or increase the duration (for) so that transient spikes are ignored. That way only the truly important alerts go out."

Interviewer: "Do you have experience with SLI/SLO-based monitoring?"

Candidate: "Yes, I defined the SLO for the main API as "99.9% availability, P95 response time within 200ms." I measured the error rate and latency percentiles in Prometheus and used them as SLIs, and I built an SLO dashboard in Grafana to track the Error Budget burn rate. I operated a policy where, once 80% of the monthly Error Budget was consumed, we would freeze features and focus on stabilization."

Take a mock interview on this topic β†’ WIA SOOM AI Interview Β· Start for free

Reviewer: "Did you check the label cardinality of this custom metric? If you put user_id in as a label, the metrics will explode."

Author: "Oh, I'll leave out user_id and only use bounded values like user_type (free, premium, enterprise) as labels."

⚠️ Cautions

πŸ“š Learn More