简体   繁体   English

如何编写 prometheus 服务监视器以从 k8s 节点上的服务中抓取指标

[英]how to write a prometheus service monitor to scrape metrics from a service on k8s node

Team, I am new to prometheus.团队,我是普罗米修斯的新手。 Please assist.请协助。

I have a k8s node and on that node locally i have a service running (lustre-exporter) which is exposing metrics as shown below.我有一个 k8s 节点,在该节点本地我有一个正在运行的服务(lustre-exporter),它正在公开指标,如下所示。

node:~$ curl http://localhost:9169/metrics | head -n 10
go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 8.4924e-05
go_gc_duration_seconds{quantile="0.25"} 9.0081e-05
go_gc_duration_seconds{quantile="0.5"} 9.2247e-05

I want to know how would i write a service monitor such that above is scraped by prometheus.我想知道我将如何编写一个服务监视器,以便上面被普罗米修斯刮掉。

I tried below but getting syntax error from k8s.我在下面尝试过,但从 k8s 收到语法错误。

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: lustre-exporter
  namespace: team-monitoring
spec:
  endpoints:
    - path: /metrics
      port: "9169"
The ServiceMonitor "lustre-exporter" is invalid: []: Invalid value: map[string]interface {}{"metadata":map[string]interface {}{"name":"lustre-exporter", "namespace":"team-monitoring", "creationTimestamp":"2022-07-01T02:14:16Z", "generation":1, "uid":"824d31a3-f8e3-11ec-b65c-ac1f6b4ea082"}, "spec":map[string]interface {}{"endpoints":[]interface {}{map[string]interface {}{"path":"/metrics", "port":"9169"}}}, "apiVersion":"monitoring.coreos.com/v1", "kind":"ServiceMonitor"}: validation failure list:
spec.selector in body is required

figured out and thanks for hint in comment but label selector was missing too.想通了,感谢评论中的提示,但 label 选择器也丢失了。

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: lustre-exporter
  namespace: team-monitoring
spec:
  endpoints:
    - path: /metrics
      port: "9169"
  selector:
   nodeGroup: gpu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM