Skip to content

Commit

Permalink
Add more kube-state-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaj committed Apr 18, 2017
1 parent 96894fc commit af1ed2b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
Binary file modified kubernetes_state/ci/fixtures/prometheus/protobuf.bin
Binary file not shown.
72 changes: 53 additions & 19 deletions kubernetes_state/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,51 @@ class TestKubernetesState(AgentCheckTest):
CHECK_NAME = 'kubernetes_state'

METRICS = [
NAMESPACE + '.node.cpu_capacity',
NAMESPACE + '.node.memory_capacity',
NAMESPACE + '.node.pods_capacity',
NAMESPACE + '.node.cpu_allocatable',
NAMESPACE + '.node.memory_allocatable',
NAMESPACE + '.node.pods_allocatable',
NAMESPACE + '.node.status',
NAMESPACE + '.container.cpu_requested',
NAMESPACE + '.container.memory_requested',
NAMESPACE + '.container.cpu_limit',
NAMESPACE + '.container.memory_limit',
NAMESPACE + '.container.restarts',
NAMESPACE + '.deployment.replicas_available',
NAMESPACE + '.deployment.replicas_unavailable',
NAMESPACE + '.deployment.replicas_desired',
NAMESPACE + '.deployment.replicas_updated',
]
# nodes
NAMESPACE + '.node.cpu_capacity',
NAMESPACE + '.node.memory_capacity',
NAMESPACE + '.node.pods_capacity',
NAMESPACE + '.node.cpu_allocatable',
NAMESPACE + '.node.memory_allocatable',
NAMESPACE + '.node.pods_allocatable',
# deployments
NAMESPACE + '.deployment.replicas',
NAMESPACE + '.deployment.replicas_available',
NAMESPACE + '.deployment.replicas_unavailable',
NAMESPACE + '.deployment.replicas_updated',
NAMESPACE + '.deployment.replicas_desired',
NAMESPACE + '.deployment.paused',
NAMESPACE + '.deployment.rollingupdate.max_unavailable',
# daemonsets
NAMESPACE + '.daemonset.scheduled',
NAMESPACE + '.daemonset.misscheduled',
NAMESPACE + '.daemonset.desired',
# pods
NAMESPACE + '.pod.ready',
NAMESPACE + '.pod.scheduled',
NAMESPACE + '.pod.container.ready',
NAMESPACE + '.pod.container.running',
NAMESPACE + '.pod.container.terminated',
NAMESPACE + '.pod.container.waiting',
NAMESPACE + '.container.restarts',
NAMESPACE + '.container.cpu_requested',
NAMESPACE + '.container.memory_requested',
NAMESPACE + '.container.cpu_limit',
NAMESPACE + '.container.memory_limit',
# replicasets
NAMESPACE + '.replicaset.replicas',
NAMESPACE + '.replicaset.fully_labeled_replicas',
NAMESPACE + '.replicaset.replicas_ready',
NAMESPACE + '.replicaset.replicas_desired',
]

ZERO_METRICS = [
NAMESPACE + '.deployment.replicas_unavailable',
NAMESPACE + '.deployment.paused',
NAMESPACE + '.daemonset.misscheduled',
NAMESPACE + '.pod.container.terminated',
NAMESPACE + '.pod.container.waiting',

]

def test__get_kube_state(self):
Expand Down Expand Up @@ -93,13 +118,22 @@ def test__update_kube_state_metrics(self):
self.assertServiceCheck(NAMESPACE + '.node.ready', self.check.OK)
self.assertServiceCheck(NAMESPACE + '.node.out_of_disk', self.check.OK)
self.assertServiceCheck(NAMESPACE + '.pod.phase.running', self.check.OK)
self.assertServiceCheck(NAMESPACE + '.pod.phase.failed', self.check.CRITICAL)
self.assertServiceCheck(NAMESPACE + '.pod.phase.pending', self.check.WARNING)
# TODO: uncomment when any of these are in the test protobuf.bin
# self.assertServiceCheck(NAMESPACE + '.pod.phase.pending', self.check.WARNING)
# self.assertServiceCheck(NAMESPACE + '.pod.phase.succeeded', self.check.OK)
# self.assertServiceCheck(NAMESPACE + '.pod.phase.failed', self.check.CRITICAL)
# self.assertServiceCheck(NAMESPACE + '.pod.phase.unknown', self.check.UNKNOWN)

for metric in self.METRICS:
self.assertMetric(metric)
if metric not in self.ZERO_METRICS:
self.assertMetricNotAllZeros(metric)

self.assert_resourcequota()

def assert_resourcequota(self):
""" The metric name is created dynamically so we just check some exist. """
for m in self.metrics:
if 'kubernetes_state.resourcequota.' in m[0]:
return True
return False

0 comments on commit af1ed2b

Please sign in to comment.