usage-metrics-collector

module
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2023 License: Apache-2.0

README

Usage Metrics Collector

The usage-metrics-collector is a Prometheus metrics collector optimized for collecting kube usage and capacity metrics.

Motivation

Why not just use promql and recording rules?

  • Scale
    • Aggregate at collection time to reduce prometheus work
    • Export aggregated metrics without the raw metrics to reduce prometheus storage
  • Insight
    • Join labels at collection time (e.g. set the priority class on pod metrics)
    • Set hard to resolve labels (e.g. set the workload kind on pod metrics)
    • View node-level cgroup utilization (e.g. kubepods vs system.slice metrics)
  • Fidelity
    • Scrape utilization at 1s intervals as raw metrics
    • Perform aggregations on the 1s interval metrics (e.g. get the p95 1s utilization sample for all replicas of a workload)

Exposed Metrics

A sample of the exposed metrics is available in METRICS.md.

Getting started

Note: No usage-metrics-collector container image is publicly hosted. Folks will need to build and publish this own until this is resolved.

Installing into a cluster
Kind cluster

Note: only cgroups v1 are currently supported.

  1. Create a kind cluster
  • kind create cluster
  1. Build the image
  • docker build . -t usage-metrics-collector:v0.0.0
  1. Load the image into kind
  • kind load docker-image usage-metrics-collector:v0.0.0
  1. Make sure the Kind cluster values config portion is uncommented in config/metrics-prometheus-collector/configmaps/sampler.yaml
  2. Install the config
  • kustomize build config | kubectl apply -f -
  1. Update your context to use the usage-metrics-collector namespace by default
  • kubectl config set-context --current --namespace=usage-metrics-collector
GKE cluster (cgroups v1: default on 1.25 or lower)

Note: Only cgroups v1 is supported for utilization right now. GKE clusters 1.26+ use cgroups v2 by default.

  1. Build the image
  • docker build . -t my-org/usage-metrics-collector:v0.0.0
  1. Push the image to a container repo
  • docker push my-org/usage-metrics-collector:v0.0.0
  1. Make sure the GKE cluster values config portion is uncommented in config/metrics-prometheus-collector/configmaps/sampler.yaml
  • Other cluster values should be commented
  1. Install the config
  • kustomize build config | kubectl apply -f -
  1. Update your context to use the usage-metrics-collector namespace by default
  • kubectl config set-context --current --namespace=usage-metrics-collector
Kicking the tires
  1. Make sure the pods are healthy
  • kubectl get pods
  1. Make sure the services have endpoints
  • kubectl describe services
  1. Get the metrics from the collector itself
  • kubectl exec -t -i $(kubectl get pods -o name -l app=metrics-prometheus-collector) -- curl localhost:8080/metrics
  • wait for service to be ready
  • kubectl port-forward service/metrics-prometheus-collector 8080:8080
  • visit localhost:8080/metrics in your browser
  1. Get the metrics from prometheus
  • kubectl port-forward $(kubectl get pods -o name -l app=prometheus) 9090:9090
  • visit localhost:9090/ in your browser
  1. View the metrics in Grafana
  • kubectl port-forward service/grafana 3000:3000
  • visit localhost:3000 in your browser
  • enter admin for the username and password
  • go to "Explore"
  • change the source to "prometheus"
  • enter kube_usage_ into the metric field
  • remove the label filters
  • click "Run Query"
Specifying aggregation rules
  1. Edit config/metrics-prometheus-collector/configmaps/collector.yaml
  2. Run make run-local
  3. View the updated metrics in grafana

TODO: Write more on this

Using containerd instead of cgroup walking

TODO: Write this

Configuring cgroup walking

TODO: Write this

Code of conduct

Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.

Directories

Path Synopsis
cmd
test-app Module
pkg
api
Package api defines the APIs.
Package api defines the APIs.
api/collectorcontrollerv1alpha1
Package collectorcontrollerv1alpha1 defines the MetricsPrometheusCollector API.
Package collectorcontrollerv1alpha1 defines the MetricsPrometheusCollector API.
api/quotamanagementv1alpha1
Package v1beta1 contains API Schema definitions for the usagemetricscollector.sigs.k8s.io API group +kubebuilder:object:generate=true +groupName=quotamanagement.usagemetricscollector.sigs.k8s.io +versionName=v1alpha1
Package v1beta1 contains API Schema definitions for the usagemetricscollector.sigs.k8s.io API group +kubebuilder:object:generate=true +groupName=quotamanagement.usagemetricscollector.sigs.k8s.io +versionName=v1alpha1
api/samplerserverv1alpha1
Package samplerserverv1alpha1 defines the MetricsNodeSampler API.
Package samplerserverv1alpha1 defines the MetricsNodeSampler API.
collector
Package collector implements the metrics-prometheus-collector which exports metrics to prometheus when scraped.
Package collector implements the metrics-prometheus-collector which exports metrics to prometheus when scraped.
log
Package log contains the shared logger used by the project
Package log contains the shared logger used by the project
sampler
Package sampler implements metrics-node-sampler which samples local utilization metrics from the node it is running on and serves aggregated values from a grpc API.
Package sampler implements metrics-node-sampler which samples local utilization metrics from the node it is running on and serves aggregated values from a grpc API.
sampler/api
Package api is a reverse proxy.
Package api is a reverse proxy.
scheme
Package scheme provides a shared scheme for Kubernetes types
Package scheme provides a shared scheme for Kubernetes types
testutil
Package testutil provides utilities for writing functional tests
Package testutil provides utilities for writing functional tests
version
Package version exports the build version for a component
Package version exports the build version for a component
watchconfig
Package watchconfig watches for config file changes
Package watchconfig watches for config file changes
tools module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL