DevOps 面试题大全(七·下):监控高级查询与企业级架构 25 题

前言

监控面试题下篇(26-50 题),涵盖高级查询、故障排查、最佳实践、企业级监控架构等进阶内容。

三、高级查询题(26-35 题)

26. PromQL 高级函数

# 偏移量
http_requests_total offset 1h

# 预测
predict_linear(node_memory_MemAvailable_bytes[1h], 3600)

# 分位数
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))

# 连接指标
label_join(node_cpu_seconds_total, "cpu_core", "-", "cpu", "core")

27. 子查询

# 每 5 分钟采样,查询 1 小时
max_overall(sum_over_time(http_requests_total[5m:1h]))

# 平均值的变化率
avg_over_time(rate(http_requests_total[5m])[1h:5m])

28. Recording Rules

groups:
  - name: recording_rules
    interval: 1m
    rules:
      - record: job:http_requests_total:rate5m
        expr: sum(rate(http_requests_total[5m])) by (job)

29. 多数据源查询

Grafana 支持混合数据源,同一 Panel 查询 Prometheus + Elasticsearch + MySQL。

30. 日志聚合查询

# ELK 聚合
GET /logs/_search
{
  "size": 0,
  "aggs": {
    "errors_by_host": {
      "terms": { "field": "host.name" },
      "aggs": {
        "status_codes": {
          "terms": { "field": "http.response.status_code" }
        }
      }
    }
  },
  "query": {
    "range": {
      "@timestamp": { "gte": "now-1h" }
    }
  }
}

31. 告警关联分析

使用标签关联多个告警,识别根因,减少告警风暴。

32. 指标重标签

relabel_configs:
  - source_labels: [__meta_kubernetes_pod_name]
    target_label: pod
  - source_labels: [__meta_kubernetes_namespace]
    target_label: namespace
  - action: labeldrop
    regex: temp_.*

33. 黑盒监控配置

scrape_configs:
  - job_name: 'blackbox'
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
          - https://example.com
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: blackbox-exporter:9115

34. 分布式追踪集成

Jaeger/Zipkin + Prometheus,指标 + 追踪关联分析。

35. 自定义 Dashboard 开发

  • JSON 模型导出导入
  • 变量动态查询
  • 模板变量级联
  • 自定义面板插件

四、故障排查题(36-42 题)

36. 指标采集失败

  1. 检查 Exporter 状态
  2. 验证网络连通性
  3. 查看 Prometheus targets 页面
  4. 检查防火墙规则
  5. 验证认证配置

37. 查询性能慢

  • 减少时间范围
  • 优化 PromQL(避免 regex)
  • 使用 Recording Rules
  • 增加 Prometheus 资源

38. 内存不足问题

  • 降低采集频率
  • 减少标签基数
  • 配置数据保留策略
  • 使用降采样

39. 告警不触发

  • 验证 PromQL 语法
  • 检查 for 持续时间
  • 查看 Alertmanager 日志
  • 测试告警规则

40. 日志丢失问题

  • 检查 Filebeat 状态
  • 验证 Logstash 管道
  • 查看 Elasticsearch 索引
  • 检查磁盘空间

41. Grafana 面板不显示

  • 检查数据源连接
  • 验证查询语法
  • 查看浏览器控制台
  • 测试数据源

42. 时间同步问题

所有节点配置 NTP,时间偏差会导致指标关联失败。

五、最佳实践题(43-47 题)

43. 指标命名规范

  • 使用下划线分隔:http_requests_total
  • 单位作为后缀:_seconds, _bytes
  • 类型作为后缀:_total, _ratio
  • 避免高基数标签

44. 标签设计原则

  • 有限的可能值
  • 避免用户 ID、IP 等
  • 使用小写字母
  • 保持一致性

45. 告警策略设计

  • 基于症状而非原因
  • 设置合理的阈值
  • 配置告警抑制
  • 定期审查告警规则
  • 告警可操作化

46. 数据保留策略

# Prometheus 本地保留
--storage.tsdb.retention.time=15d
--storage.tsdb.retention.size=10GB

# Thanos 长期存储
对象存储(S3/GCS)+ 降采样

47. 监控即代码

  • 告警规则版本控制
  • Dashboard JSON 管理
  • Grafana CLI 部署
  • Terraform 管理 Alertmanager

六、企业级架构题(48-50 题)

48. 大规模监控架构

  • 边缘 Prometheus 采集
  • Thanos Query 全局视图
  • 对象存储长期保存
  • 多租户隔离

49. 多集群监控

每个 K8s 集群部署 Prometheus,联邦或 Thanos 聚合,统一 Dashboard。

50. 可观测性体系

  • Metrics - Prometheus
  • Logs - ELK/Loki
  • Traces - Jaeger/Tempo
  • 关联分析 - 统一标签

总结

监控是 DevOps 的核心能力,需要掌握指标、日志、追踪三大支柱,构建完整的可观测性体系。

学习路线建议

  1. Prometheus 基础查询
  2. Grafana Dashboard 制作
  3. Alertmanager 告警配置
  4. ELK Stack 日志分析
  5. 分布式追踪集成
  6. 企业级监控架构

发表回复

后才能评论