代码之家  ›  专栏  ›  技术社区  ›  andig

如何为prometheus操作员创建ServiceMonitor?

  •  2
  • andig  · 技术社区  · 8 年前

    最近,普罗米修斯算子被提升为稳定舵图( https://github.com/helm/charts/tree/master/stable/prometheus-operator ).

    我想了解如何在k8s集群中为prometheus操作员的监控添加自定义应用程序。举个例子,比如gitlab runner,它默认提供9252上的度量( https://docs.gitlab.com/runner/monitoring/#configuration-of-the-metrics-http-server ).

    我有一个初步的yaml,显然不起作用,但也没有提供任何反馈 什么 不起作用:

    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: gitlab-monitor
      # Change this to the namespace the Prometheus instance is running in
      namespace: default
      labels:
        app: gitlab-runner-gitlab-runner
        release: prometheus
    spec:
      selector:
        matchLabels:
          app: gitlab-runner-gitlab-runner
      namespaceSelector:
        # matchNames:
        # - default
        any: true
      endpoints:
      - port: http-metrics
        interval: 15s
    

    这是普罗米修斯的配置:

    > kubectl get prometheus -o yaml
    
    ...
    serviceMonitorNamespaceSelector: {}
    serviceMonitorSelector:
      matchLabels:
        release: prometheus
    ...
    

    所以选择器应该匹配。“不工作”的意思是端点不会出现在prometheusui中。

    1 回复  |  直到 8 年前
        1
  •  29
  •   andig    8 年前

    多亏了彼得,他让我知道这个想法在原则上并不是完全错误的,我找到了缺失的环节。作为一个 servicemonitor

    # Service targeting gitlab instances
    apiVersion: v1
    kind: Service
    metadata:
      name: gitlab-metrics
      labels:
        app: gitlab-runner-gitlab-runner
    spec:
      ports:
      - name: metrics # expose metrics port
        port: 9252 # defined in gitlab chart
        targetPort: metrics
        protocol: TCP
      selector:
        app: gitlab-runner-gitlab-runner # target gitlab pods
    ---
    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      name: gitlab-metrics-servicemonitor
      # Change this to the namespace the Prometheus instance is running in
      # namespace: default
      labels:
        app: gitlab-runner-gitlab-runner
        release: prometheus
    spec:
      selector:
        matchLabels:
          app: gitlab-runner-gitlab-runner # target gitlab service
      endpoints:
      - port: metrics
        interval: 15s
    

    很高兴知道:是的 metrics targetPort

        2
  •  20
  •   vrs    7 年前

    我知道这个问题已经回答了。但当普罗米修斯部署在库伯内特斯时,我遇到了一个类似的问题,赫尔姆的稳定/普罗米修斯操作图无法为我的目标找到任何活动目标 ServiceMonitor

      - protocol: TCP
        port: 8080
        targetPort: uwsgi
    

    我可以用它来攻击目标 uwsgi 港口。但看起来 中需要显式命名的端口 Service

      - name: uwsgi
        protocol: TCP
        port: 8080
        targetPort: uwsgi
    

    我写了一篇关于这个问题的博文 here

    推荐文章