prometheus 收集kube-state-metrics指标信息
Posted gaofeng-henu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了prometheus 收集kube-state-metrics指标信息相关的知识,希望对你有一定的参考价值。
安装kube-state-metrics
-
下载
$ cd /opt/k8s/work/ $ wget -O kube-state-metrics.zip https://github.com/kubernetes/kube-state-metrics/archive/master.zip $ unzip kube-state-metrics.tar.gz $ cd kube-state-metrics-master/examples/standard $ ls cluster-role-binding.yaml cluster-role.yaml deployment.yaml service-account.yaml service.yaml
-
修改namespace
将默认的namespace从kube-system修改成monitoring
$ cd /opt/k8s/work/kube-state-metrics-master/examples/standard $ ls | xargs -I {} sed -i "s/namespace: kube-system/namespace: monitoring/g" {}
-
在service.yaml追加如下annotation
annotations: prometheus.io/scraped: "true"
修改后的server.yml文件
cat service.yaml apiVersion: v1 kind: Service metadata: annotations: prometheus.io/scraped: "true" labels: app.kubernetes.io/name: kube-state-metrics app.kubernetes.io/version: 1.9.5 name: kube-state-metrics namespace: monitoring spec: clusterIP: None ports: - name: http-metrics port: 8080 targetPort: http-metrics - name: telemetry port: 8081 targetPort: telemetry selector: app.kubernetes.io/name: kube-state-metrics
-
启动服务
$ cd /opt/k8s/work/kube-state-metrics-master/examples/standard $ kubectl create -f .
prometheus 收集指标
-
prometheus 追加配置,仅抓取带有
prometheus.io/scraped: "true"
注解的endpoint- job_name: "kubernetes-service-endpoints" kubernetes_sd_configs: - role: endpoints relabel_configs: - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scraped] action: keep regex: true - action: labelmap regex: __meta_kubernetes_service_label_(.+) - source_labels: [__meta_kubernetes_namespace] action: replace target_label: kubernetes_namespace - source_labels: [__meta_kubernetes_service_name] action: replace target_label: service_name
-
prometheus重新加载配置后,查看对应的target
kube-state-metrics对应的pod有两个端口,在prometheus中显示了两个target
配置grafana
-
从grafana.com 下载state-metrics监控模版1. Kubernetes Deployment Statefulset Daemonset metrics,导入模版
grafana效果图
以上是关于prometheus 收集kube-state-metrics指标信息的主要内容,如果未能解决你的问题,请参考以下文章
如何使用联合从多个 Prometheus 实例(每个使用 instance="localhost:9090")中收集 Prometheus 的指标
Springboot 网关 Prometheus 收集海量数据
如何编写一个在文件中收集值的 Prometheus 导出器?