Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Kubernetes Blog 8 min read How-to mediumAdept

Building a Custom Metrics Exporter for Kubernetes

A Prometheus metrics exporter is a small HTTP server exposing application state on /metrics, letting Kubernetes workloads surface signals like queue depth or job latency beyond CPU and memory. A Go exporter built with client_golang registers a counter, gauge and histogram named <namespace>_<name>_<unit>, refreshes them in a polling loop shorter than the 15s scrape interval, and serves a separate /healthz probe. The setup ships as a multi-stage distroless image, runs as a Deployment plus a named-port Service, and is scraped via a ServiceMonitor whose release label must match the Prometheus selector, or via annotation-based discovery. Prometheus Adapter is the next step for feeding these metrics to the HorizontalPodAutoscaler.

Related posts

  • Enhanced ClickHouse Cloud Monitoring with Prometheus

    ClickHouse mediumAdept

    ClickHouse Cloud now exposes a Prometheus metrics endpoint through its Cloud API, authenticated with organization-level Developer API keys. Routing scrapes through the control plane means agents never wake idle instances. Scrape queries come from a limited-permission user that the data plane ignores when deciding whether to idle. Rather than querying system tables on every scrape, a Refreshable Materialized View runs the expensive multi-table query once a minute into a Memory-engine table (system.custom_metrics), which caps query load from misconfigured agents. Example configs show Prometheus (with honor_labels: true) and Datadog OpenMetrics scraping over 1000 metrics.

  • Kubernetes v1.37: Native Histograms Graduates to Beta

    Kubernetes Blog mediumAdept

    Kubernetes v1.37 promotes native histogram support (KEP-5808) to Beta, on by default, so control plane and node components expose Prometheus Native Histograms with exponential buckets alongside classic ones. The implementation lives in k8s.io/component-base/metrics, defaults to BucketFactor 1.1 (about 5% worst-case quantile error) and MaxBucketNumber 160, and uses dual exposition over Protobuf so existing dashboards keep working. To migrate, enable scrape_native_histograms per job in Prometheus 3.x and keep always_scrape_classic_histograms: true during the transition. Native histograms let PromQL histogram_quantile run on the metric name directly without _bucket suffixes or sum by (le).

  • Kubernetes v1.37: Metrics API graduates to stable

    Kubernetes Blog mediumAdept

    Kubernetes v1.37 graduates the metrics.k8s.io resource Metrics API, which supplies node and Pod CPU and memory usage to kubectl top and the HorizontalPodAutoscaler, to stable v1. The v1 surface is identical to v1beta1, with the same NodeMetrics and PodMetrics types and no field or semantic changes. kubectl top prefers v1 and falls back to v1beta1, but the HPA controller still only supports v1beta1. Metrics implementations such as metrics-server must serve v1 and register a v1.metrics.k8s.io APIService, and should keep serving both versions during the transition.

  • Monitor your ClickHouse Cloud services with the new Prometheus/Grafana Mix-in

    ClickHouse mediumAdept

    ClickHouse Cloud now offers a Prometheus/Grafana mix-in: a pre-built Grafana dashboard, nearly identical to ClickHouse's internal one, fed by the cloud API's Prometheus endpoint. That endpoint federates metrics from every service in an organization and handles stopped or idling services, which per-instance scraping of system tables cannot. Its `filtered_metrics` parameter trims the 1000+ available metrics to about 125 critical ones, cutting scrape cost and noise. Setup is a Prometheus scrape config with basic auth and `honor_labels: true`, then importing the dashboard from Grafana.com or GitHub.

  • Kubernetes v1.37: Scale Workloads to Zero with HorizontalPodAutoscaler

    Kubernetes Blog mediumAdept

    Kubernetes v1.37 promotes HPA scale-to-zero to Beta and enables it by default, so a HorizontalPodAutoscaler with minReplicas: 0 can scale workloads to zero and back based on object or external metrics such as queue length. Resource metrics like CPU and memory cannot do this, because they come from running Pods and disappear at zero. The controller records a ScaledToZero status condition to tell its own scale-downs apart from manual pauses, and it will not wake a workload an operator set to zero. A worked example uses Prometheus Adapter to expose a queue-lag metric, with caveats: cold-start latency, Services don't buffer HTTP requests while no Pods are ready, and both control-plane components need the feature gate during version-skewed upgrades. Before downgrading, set minReplicas back to at least one.

The quest for software engineering knowledge.

Look:
Layout: