简体   繁体   English

使用 Prometheus 监控 Kubernetes 持久卷的使用情况

[英]Monitoring Kubernetes persistent volumes usage with Prometheus

I have a K8s 1.7 cluster using vSphere as persistent storage provider.我有一个使用vSphere作为持久存储提供程序的 K8s 1.7 集群。 I have also deployed Prometheus , node_exporter and kube-state-metrics .我还部署了Prometheusnode_exporterkube-state-metrics

I'm trying to find a way to monitor a persistent volume's usage using Prometheus .我正在尝试找到一种使用Prometheus监视持久卷使用情况的方法。 I have added custom labels to some PVs, eg.我已经为一些 PV 添加了自定义标签,例如。 app=rabbitmq-0 , etc. app=rabbitmq-0

How can I combine kube_persistentvolume_labels with node_filesystem_size metrics so that I can query PV usage using my custom label?如何将kube_persistentvolume_labelsnode_filesystem_size指标结合kube_persistentvolume_labels ,以便我可以使用自定义标签查询 PV 使用情况?

PS.附注。
I know that K8s 1.8 directly exposes these metrics from kubelet as mentioned in How to monitor disk usage of kubernetes persistent volumes?我知道 K8s 1.8 直接从 kubelet 公开这些指标,如如何监控 kubernetes 持久卷的磁盘使用情况中所述? but currently a cluster upgrade is not an option.但目前无法选择集群升级。

Starting from (v1.3.0-rc.0 / 2018-03-23) in the kube-state-metrics , two metrics that can convert PersistentVolume and PersistenVolumeClaims labels to Prometheus labels accordingly were added:kube-state-metrics中的 ( v1.3.0 -rc.0 / 2018-03-23) 开始,添加了两个可以相应地将PersistentVolumePersistenVolumeClaims标签转换为 Prometheus 标签的指标:

kube_persistentvolume_labels
kube_persistentvolumeclaim_lables

To get more details about implementing aggregation of metrics based on labels, consider reading these articles:要获取有关基于标签实现指标聚合的更多详细信息,请考虑阅读以下文章:

There are cases when hostpath cannot be mount to pod or node will not be accessible to a project (namespace) in that case node exporter cannot be deployed, in such cases volume_exporter would be useful.在某些情况下,主机路径无法挂载到 pod 或项目(命名空间)无法访问节点,在这种情况下无法部署节点导出器,在这种情况下, volume_exporter会很有用。

You can just add it as a side car您可以将其添加为侧车

      - name: volume-exporter
      image:  mnadeem/volume_exporter
      imagePullPolicy: "Always"
      args:
        - --volume-dir=prometheus:/prometheus
      ports:
      - name: metrics-volume
        containerPort: 9888
      volumeMounts:
      - mountPath: /prometheus
        name: prometheus-data
        readOnly: true

It will generate the metrics它将生成指标

        # HELP volume_bytes_free Free size of the volume/disk
        # TYPE volume_bytes_free gauge
        volume_bytes_free{volume_name="bin",volume_path="/bin"} 4.341569536e+10
        volume_bytes_free{volume_name="etc",volume_path="/etc"} 4.341569536e+10
        # HELP volume_bytes_total Total size of the volume/disk
        # TYPE volume_bytes_total gauge
        volume_bytes_total{volume_name="bin",volume_path="/bin"} 6.391887872e+10
        volume_bytes_total{volume_name="etc",volume_path="/etc"} 6.391887872e+10
        # HELP volume_bytes_used Used size of volume/disk
        # TYPE volume_bytes_used gauge
        volume_bytes_used{volume_name="bin",volume_path="/bin"} 2.050318336e+10
        volume_bytes_used{volume_name="etc",volume_path="/etc"} 2.050318336e+10
        # HELP volume_exporter_build_info A metric with a constant '1' value labeled by version, revision, branch, and goversion from which volume_exporter was built.
        # TYPE volume_exporter_build_info gauge
        volume_exporter_build_info{branch="",goversion="go1.15",revision="",version=""} 1
        # HELP volume_percentage_used Percentage of volume/disk Utilization
        # TYPE volume_percentage_used gauge
        volume_percentage_used{volume_name="bin",volume_path="/bin"} 32.07688208958619
        volume_percentage_used{volume_name="etc",volume_path="/etc"} 32.07688208958619

Refer this for more details有关更多详细信息,请参阅

Disclaimer : I am the owner免责声明:我是业主

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

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