---
title: "Our journey taking Kubernetes state metrics to the next level"
description: "Datadog's Containers team made kube-state-metrics usable as a library: an upstream PR made the KSM Builder extensible so the MetricStore could be swapped out, with neutral-to-slightly-better benchmark results."
url: "https://swe.quest/articles/our-journey-taking-kubernetes-state-metrics-to-the-next-level-53c89d582db9c1aa"
canonical: "https://www.datadoghq.com/blog/engineering/our-journey-taking-kubernetes-state-metrics-to-the-next-level/"
source: "Datadog Engineering"
published: "2021-10-15"
difficulty: "medium"
kind: "Case study"
reading_minutes: 12
tags: ["kubernetes","observability","go","performance","open-source"]
---

# Our journey taking Kubernetes state metrics to the next level

A post on [Datadog Engineering](https://swe.quest/sources/datadog.md), published 2021-10-15, 12 min read, Case study. Original: [https://www.datadoghq.com/blog/engineering/our-journey-taking-kubernetes-state-metrics-to-the-next-level/](https://www.datadoghq.com/blog/engineering/our-journey-taking-kubernetes-state-metrics-to-the-next-level/)

## Summary

Datadog's Containers team made kube-state-metrics usable as a library: an upstream PR made the KSM Builder extensible so the MetricStore could be swapped out, with neutral-to-slightly-better benchmark results. Embedding KSM's informers directly in the Datadog Agent as a long-running Go core check, run on Cluster Check Runners or the Cluster Agent, removed the costly crawl of the /metrics endpoint. Large clusters had been producing millions of metrics every 15 seconds, and this change cut collection time 15x and halved memory and CPU footprint. It also required extending the Agent collector's interface to support long-lived check threads.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Kubernetes](https://swe.quest/tags/kubernetes.md) (Infrastructure)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Go](https://swe.quest/tags/go.md) (Languages)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Open source](https://swe.quest/tags/open-source.md) (Engineering practices)

## Prerequisites

- Kubernetes informers ([easy posts on Kubernetes](https://swe.quest/tags/kubernetes.md?difficulty=easy))
- Prometheus/OpenMetrics format
- Go ([easy posts on Go](https://swe.quest/tags/go.md?difficulty=easy))

## Keywords

kube-state-metrics, Datadog Agent, Cluster Check Runner, Datadog Cluster Agent, OpenMetrics

## Related posts

- [How we scaled metrics aggregation by moving durable state into storage](https://swe.quest/articles/how-we-scaled-metrics-aggregation-by-moving-durable-state-into-storage-09bea3fd544962da.md): Datadog Engineering · 2026-11-17 · Medium · 12 min read · Stream processing, Scaling, Observability, Storage engines, Distributed systems
  Datadog's metrics aggregation service, which merges DDSketch distributions to reduce tag dimensions, went through three generations as volume grew roughly 10× each time.
- [Scaling down to speed up: How we improved efficiency of live process metrics by 100x](https://swe.quest/articles/scaling-down-to-speed-up-how-we-improved-efficiency-of-live-process-metrics-by-db520ecc99ab0c49.md): Datadog Engineering · 2025-08-12 · Medium · 8 min read · Observability, Scaling, Cost optimization, Queues & messaging, System design
  Datadog cut real-time process and container metric traffic by about 100x by enabling 2-second live collection only on hosts whose processes a user is actually viewing (at most 50 per user), instead of on every host in the tenant.
- [Kubernetes v1.36: PSI Metrics for Kubernetes Graduates to GA](https://swe.quest/articles/kubernetes-v1-36-psi-metrics-for-kubernetes-graduates-to-ga-62230281bb0c800e.md): Kubernetes Blog · 2026-05-12 · Medium · 6 min read · Kubernetes, Observability, Linux, Performance engineering
  Pressure Stall Information (PSI) metrics in the kubelet are generally available in Kubernetes v1.36, exposing CPU, memory and I/O stall time at node, pod and container level with no feature gate needed.
- [Open sourcing kubenetmon: how we monitor data transfer in ClickHouse Cloud](https://swe.quest/articles/open-sourcing-kubenetmon-how-we-monitor-data-transfer-in-clickhouse-cloud-b1818230173f499e.md): ClickHouse · 2025-01-30 · Medium · 20 min read · Observability, Kubernetes, Networking, Cost optimization, Linux
  kubenetmon, now open source, is ClickHouse Cloud's in-house tool for monitoring data transfer across many Kubernetes clusters on AWS, GCP and Azure.
- [Node.js and the tale of worker threads](https://swe.quest/articles/node-js-and-the-tale-of-worker-threads-2f7f52d719f58af7.md): Zalando Engineering · 2024-07-24 · Medium · 10 min read · JavaScript, Kubernetes, Incidents & postmortems, Debugging, Observability
  A Node.js service using cluster mode called os.cpus().length inside a Kubernetes container, which returns the host's core count, not the pod's CPU allocation.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
