首页 文章

Kubernetes Pods的应用程序指标监控

提问于
浏览
1

我们已经在使用节点导出器在我们的kubernetes环境中提取/收集docker / container指标 . 接下来,我们还希望能够收集应用程序指标(在我们的案例中由 spring Actuator 提供,例如http://pod-name:8080/prometheus) . 这通常是如何完成的,请记住我们不能将Kubernetes服务用作固定DNS名称(它们在服务后面的pod上进行负载均衡)以及pod随时消失并出现,更改其名称和可寻址性的事实?

我们最初的天真方法如下(但由于服务负载均衡,这还不够):

- job_name: 'example-service'
  scheme: http
  metrics_path: '/prometheus'
  static_configs:
   - targets: ['example-service:8080']

任何建议或例子都会非常棒 .

非常感谢提前,

巴特

1 回答

  • 0

    我在同时找到了一个例子......问题已经结束 .

    # Example scrape config for pods
    #
    # The relabeling allows the actual pod scrape endpoint to be configured via the
    # following annotations:
    #
    # * `prometheus.io/scrape`: Only scrape pods that have a value of `true`
    # * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
    # * `prometheus.io/port`: Scrape the pod on the indicated port instead of the default of `9102`.
    - job_name: 'kubernetes-pods'
    
      kubernetes_sd_configs:
      - role: pod
    
      relabel_configs:
      - 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
        regex: ([^:]+)(?::\d+)?;(\d+)
        replacement: $1:$2
        target_label: __address__
      - action: labelmap
        regex: __meta_kubernetes_pod_label_(.+)
      - source_labels: [__meta_kubernetes_namespace]
        action: replace
        target_label: kubernetes_namespace
      - source_labels: [__meta_kubernetes_pod_name]
        action: replace
        target_label: kubernetes_pod_name
    

相关问题