Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubernetes persistentvolume metrics #1932

Merged
merged 8 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, name, init_config, agentConfig, instances=None):
'kube_pod_container_status_terminated': 'container.terminated',
'kube_pod_container_status_waiting': 'container.waiting',
'kube_persistentvolumeclaim_status_phase': 'persistentvolumeclaim.status',
'kube_persistentvolumeclaim_resource_requests_storage_bytes': 'persistentvolumeclaim.request_storage',
'kube_pod_container_resource_limits_cpu_cores': 'container.cpu_limit',
'kube_pod_container_resource_limits_memory_bytes': 'container.memory_limit',
'kube_pod_container_resource_requests_cpu_cores': 'container.cpu_requested',
Expand Down Expand Up @@ -161,6 +162,14 @@ def __init__(self, name, init_config, agentConfig, instances=None):
'kube_pod_info': {
'label_to_match': 'pod',
'labels_to_get': ['node']
},
'kube_persistentvolume_info': {
'label_to_match': 'persistentvolume',
'labels_to_get': ['storageclass']
},
'kube_persistentvolumeclaim_info': {
'label_to_match': 'persistentvolumeclaim',
'labels_to_get': ['storageclass']
}
}

Expand Down Expand Up @@ -581,3 +590,18 @@ def kube_limitrange(self, message, **kwargs):
self.gauge(metric_base_name.format(resource, constraint), val, tags)
else:
self.log.error("Metric type %s unsupported for metric %s" % (message.type, message.name))

def kube_persistentvolume_status_phase(self, message, **kwargs):
""" The persistent volumes by phase. """
metric_name = self.NAMESPACE + '.persistentvolumes.by_phase'
by_phase_counter = Counter()

for metric in message.metric:
tags = [
self._label_to_tag("storageclass", metric.label),
self._label_to_tag("phase", metric.label)
] + self.custom_tags
by_phase_counter[tuple(sorted(tags))] += metric.gauge.value

for tags, count in by_phase_counter.iteritems():
self.gauge(metric_name, count, tags=list(tags))
4 changes: 3 additions & 1 deletion kubernetes_state/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ kubernetes_state.node.memory_capacity,gauge,,byte,,The total memory resources of
kubernetes_state.node.pods_capacity,gauge,,,,The total pod resources of the node,0,kubernetes,k8s_state.node.pods_capacity
kubernetes_state.node.gpu.cards_allocatable,gauge,,,,The GPU resources of a node that are available for scheduling,0,kubernetes,k8s_state.node.gpu.cards_allocatable
kubernetes_state.node.gpu.cards_capacity,gauge,,,,The total GPU resources of the node,0,kubernetes,k8s_state.node.gpu.cards_capacity
kubernetes_state.persistentvolumeclaim.status,gauge,,,,The phase the persistent volume claim is currently in,-1,kubernetes,k8s_state.persistentvolumeclaim.status
kubernetes_state.persistentvolumeclaim.status,gauge,,,,The phase the persistent volume claim is currently in,-1,kubernetes,k8s_state.pvc.status
kubernetes_state.persistentvolumeclaim.request_storage,gauge,,byte,,Storage space request for a given pvc,0,kubernetes,k8s_state.pvc.request
kubernetes_state.persistentvolume.by_phase,gauge,,,,Number of persistent volumes to sum by phase and storageclass,0,kubernetes,k8s_state.pv.by_phase
kubernetes_state.node.cpu_allocatable,gauge,,cpu,,The CPU resources of a node that are available for scheduling,0,kubernetes,k8s_state.node.cpu_allocatable
kubernetes_state.node.memory_allocatable,gauge,,byte,,The memory resources of a node that are available for scheduling,0,kubernetes,k8s_state.node.memory_allocatable
kubernetes_state.node.pods_allocatable,gauge,,,,The pod resources of a node that are available for scheduling,0,kubernetes,k8s_state.node.pods_allocatable
Expand Down
15 changes: 15 additions & 0 deletions kubernetes_state/tests/fixtures/prometheus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,21 @@ kube_node_status_condition{condition="Ready",node="minikube",status="unknown"} 0
# HELP kube_node_status_network_unavailable Whether the network is correctly configured for the node.
# TYPE kube_node_status_network_unavailable gauge
kube_node_status_network_unavailable{node="127.0.0.1",condition="false"} 1
# TYPE kube_persistentvolume_status_phase gauge
kube_persistentvolume_status_phase{persistentvolume="local-pv-103fef5d",phase="Available"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-103fef5d",phase="Bound"} 1
kube_persistentvolume_status_phase{persistentvolume="local-pv-103fef5d",phase="Failed"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-103fef5d",phase="Pending"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-103fef5d",phase="Released"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Available"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Bound"} 1
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Failed"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Pending"} 0
kube_persistentvolume_status_phase{persistentvolume="local-pv-15d0a3a3",phase="Released"} 0
# HELP kube_persistentvolume_info Information about persistentvolume.
# TYPE kube_persistentvolume_info gauge
kube_persistentvolume_info{persistentvolume="local-pv-103fef5d",storageclass="local-data"} 1
kube_persistentvolume_info{persistentvolume="local-pv-15d0a3a3",storageclass="local-data"} 1
# HELP kube_persistentvolumeclaim_info Information about persistent volume claim.
# TYPE kube_persistentvolumeclaim_info gauge
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="task-pv-claim",storageclass="manual"} 1
Expand Down
16 changes: 16 additions & 0 deletions kubernetes_state/tests/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
NAMESPACE + '.replicaset.replicas_desired',
# persistentvolume claim
NAMESPACE + '.persistentvolumeclaim.status',
NAMESPACE + '.persistentvolumeclaim.request_storage',
# statefulset
NAMESPACE + '.statefulset.replicas',
NAMESPACE + '.statefulset.replicas_current',
Expand All @@ -94,6 +95,9 @@
'reason:CrashLoopBackOff',
'reason:ErrImagePull',
'reason:ImagePullBackoff'
],
NAMESPACE + '.persistentvolumeclaim.request_storage': [
'storageclass:manual'
]
}

Expand Down Expand Up @@ -237,6 +241,18 @@ def test_update_kube_state_metrics(aggregator, instance, check):
aggregator.assert_metric(NAMESPACE + '.pod.status_phase',
tags=['namespace:default', 'phase:Unknown', 'optional:tag1'], value=1)

# Persistentvolume counts
aggregator.assert_metric(NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:Available', 'optional:tag1'], value=0)
aggregator.assert_metric(NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:Bound', 'optional:tag1'], value=2)
aggregator.assert_metric(NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:Failed', 'optional:tag1'], value=0)
aggregator.assert_metric(NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:Pending', 'optional:tag1'], value=0)
aggregator.assert_metric(NAMESPACE + '.persistentvolumes.by_phase',
tags=['storageclass:local-data', 'phase:Released', 'optional:tag1'], value=0)

for metric in METRICS:
aggregator.assert_metric(metric, hostname=HOSTNAMES.get(metric, None))
for tag in TAGS.get(metric, []):
Expand Down