doubi1928 2017-08-25 22:06
浏览 232
已采纳

如何显示使用Golang客户端库从Kubernetes中运行的所有Pod中捕获的Prometheus中的自定义应用程序指标

I am trying to get some custom application metrics captured in golang using the prometheus client library to show up in Prometheus.

I have the following working:

apiVersion: v1
kind: Pod
metadata:
  name: my-app-pod
  labels:
    zone: prod
    version: v1
  annotations:
   prometheus.io/scrape: 'true'
   prometheus.io/port: '8080'

spec:
   containers:
    - name: my-container
      image: name/my-app:latest
      imagePullPolicy: IfNotPresent
      ports:
      - containerPort: 8080
  • If I connect to my pod using:

kubectl exec -it my-app-pod -- /bin/bash

then do wget on "localhost:8080/metrics", I can see my metrics

So far so good, here is where I am hitting a wall. I could have multiple pods running this same image. I want to expose all the images to prometheus as targets. How do I configure my pods so that they show up in prometheus so I can report on my custom metrics?

Thanks for any help offered!

  • 写回答

3条回答 默认 最新

  • dpik71879 2017-08-27 08:30
    关注

    You need 2 things:

    • a ServiceMonitor for the Prometheus Operator, which specifies which services will be scraped for metrics
    • a Service which matches the ServiceMonitor and points to your pods

    There is an example in the docs over here: https://coreos.com/operators/prometheus/docs/latest/user-guides/running-exporters.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿