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

时间:2018-07-20 11:00:52

标签: kubernetes prometheus

我有一个使用 vSphere 作为持久性存储提供程序的K8s 1.7集群。我还部署了 Prometheus node_exporter kube-state-metrics

我正在尝试找到一种使用 Prometheus 来监视持久卷的使用情况的方法。我已经为某些PV添加了自定义标签,例如。 app=rabbitmq-0

如何将kube_persistentvolume_labelsnode_filesystem_size指标结合使用,以便可以使用自定义标签查询PV使用量?

PS。
我知道K8s 1.8如How to monitor disk usage of kubernetes persistent volumes?中所述直接从kubelet公开了这些指标,但是当前无法进行集群升级。

2 个答案:

答案 0 :(得分:0)

kube-state-metrics 中的(v1.3.0-rc.0 / 2018-03-23)开始,两个可以转换PersistentVolume和{{3} }相应地向Prometheus标签添加了标签:

kube_persistentvolume_labels
kube_persistentvolumeclaim_lables

要获取有关基于标签实施指标汇总的更多详细信息,请考虑阅读以下文章:

答案 1 :(得分:0)

在某些情况下,主机路径无法挂载到 pod 或项目(命名空间)无法访问节点,在这种情况下无法部署节点导出器,在这种情况下 volume_exporter 会很有用。

您可以将其添加为侧车

      - 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

它将生成指标

        # 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

请参阅this了解更多详情

免责声明:我是业主