All Projects → cytopia → metrics-server-prom

cytopia / metrics-server-prom

Licence: MIT license
Prometheus adapter to scrape from Kubernetes metrics-server

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects
Dockerfile
14818 projects
Makefile
30231 projects

Projects that are alternatives of or similar to metrics-server-prom

Collectd
The system statistics collection daemon. Please send Pull Requests here!
Stars: ✭ 2,700 (+12172.73%)
Mutual labels:  prometheus-exporter, metrics-server
resoto
Resoto - Find leaky resources, manage quota limits, detect drift, and clean up!
Stars: ✭ 562 (+2454.55%)
Mutual labels:  prometheus-exporter, k8s
cratedb-prometheus-adapter
CrateDB Prometheus Adapter
Stars: ✭ 53 (+140.91%)
Mutual labels:  prometheus-exporter
kubernetes-reading-notes
Kubernetes源码阅读笔记
Stars: ✭ 96 (+336.36%)
Mutual labels:  k8s
bilrost
Kubernetes controller/operator to set up OAUTH2/OIDC security on any ingress based service
Stars: ✭ 17 (-22.73%)
Mutual labels:  k8s
kubernetes-workshop
Kubernetes Workshop
Stars: ✭ 20 (-9.09%)
Mutual labels:  k8s
nodejs-health-checker
This is a Node package that allows you to track the health of your application providing readiness and liveness functionalities.
Stars: ✭ 34 (+54.55%)
Mutual labels:  k8s
evolution
Evolution process of The Falco Project
Stars: ✭ 37 (+68.18%)
Mutual labels:  k8s
ansible-process exporter
Provision process exporter for prometheus monitoring tool
Stars: ✭ 16 (-27.27%)
Mutual labels:  prometheus-exporter
rpi exporter
A Raspberry Pi CPU temperature exporter.
Stars: ✭ 57 (+159.09%)
Mutual labels:  prometheus-exporter
configurator
Synchronize and Version Control ConfigMaps & Secrets across Deployment Rollouts.
Stars: ✭ 68 (+209.09%)
Mutual labels:  k8s
bamboo-prometheus-exporter
Prometheus Exporter For Bamboo
Stars: ✭ 18 (-18.18%)
Mutual labels:  prometheus-exporter
kube-lineage
A CLI tool to display all dependencies or dependents of an object in a Kubernetes cluster.
Stars: ✭ 238 (+981.82%)
Mutual labels:  k8s
kube-toolkit
Toolkit for creating gRPC-based CLI and web tools for Kubernetes
Stars: ✭ 74 (+236.36%)
Mutual labels:  k8s
terraform-provider-carvel
Carvel Terraform provider with resources for ytt and kapp to template and deploy to Kubernetes
Stars: ✭ 40 (+81.82%)
Mutual labels:  k8s
vultr-cloud-controller-manager
Kubernetes Cloud Controller Manager for Vultr
Stars: ✭ 51 (+131.82%)
Mutual labels:  k8s
codis-operator
Codis Operator creates and manages codis clusters(proxy based Redis cluster solution) running in kubernetes.(WIP)
Stars: ✭ 21 (-4.55%)
Mutual labels:  k8s
MLab
“云上炼丹师”中的云
Stars: ✭ 54 (+145.45%)
Mutual labels:  k8s
tezos-k8s
Deploy a Tezos Blockchain on Kubernetes
Stars: ✭ 43 (+95.45%)
Mutual labels:  k8s
scrumlr.io
Webapp for collaborative online retrospectives
Stars: ✭ 116 (+427.27%)
Mutual labels:  k8s

Kubernetes Metrics Server Prometheus Adapter

Motivation | Usage | Docker Compose | Metrics transformation | License

Build Status release

Motivation

What is provided

A Docker image on which Prometheus can scrape Kubernetes metrics provided by metrics-server. The image can run anywhere where Prometheus can use it as a target, even in Kubernetes itself.

Why is it needed

metrics-server seems to be the successor of heapster for Kubernetes monitoring. However, metrics-server currently only provides its metrics in JSON format via the Kubernetes API server.

Prometheus on the other hand expects a special text-based format. So in order for Prometheus to scrape those metrics, they must be transparently transformed from JSON to its own format on every request.

Differences

Other than metrics-server itself, this Docker container provides additional metrics metadata that are retrieved via kubectl API calls and included in the Prometheus output.

How does it work

The following diagram illustrates how the format transformation is achieved:

workflow

  1. Prometheus scrapes the Docker container on :9100/metrics
  2. Inside the Docker container uwsgi is proxying the request to kube proxy
  3. kube-proxy reads the provided config file and tunnels the request into Kubernetes to metrics-server
  4. metrics-server replies with JSON formatted metrics
  5. kube proxy forwards the request back to uwsgi
  6. uwsgi calls transform.py
  7. transform.py rewrites the JSON into Prometheus readable output and hands the result back to uwsgi
  8. uwsgi sends the final response back to Prometheus

Usage

Run metrics-server-prom

Simply run the Docker image with a kube config mounted into /etc/kube/config.

$ docker run -d \
    -p 9100:9100 \
    -v ${HOME}/.kube/config:/etc/kube/config:ro \
    cytopia/metrics-server-prom

If your kube config contains multiple contexts, you can tell metrics-server-prom what context to use, to connect to the cluster.

$ docker run -d \
    -p 9100:9100 \
    -v ${HOME}/.kube/config:/etc/kube/config:ro \
    -e KUBE_CONTEXT=my-context \
    cytopia/metrics-server-prom

Configure Prometheus

prometheus.yml:

scrape_configs:
  - job_name: 'kubernetes'
    scrape_interval: '15s'
    metrics_path: '/metrics'
    static_configs:
      - targets:
        - <DOCKER_IP_ADDRESS>:9100

Docker Compose

To test this out locally, this repository ships an example Docker Compose setup with metrics-server-prom and Prometheus.

  1. Navigate to example/
  2. Copy env-example to .env
  3. Adjust KUBE_CONTEXT in .env
  4. Run it docker-compose up

Metrics transformation

metrics-server provices metrics in the following format:

{
  "kind": "PodMetricsList",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/metrics.k8s.io/v1beta1/pods"
  },
  "items": [
    {
      "metadata": {
        "name": "etcd-server-events-abc",
        "namespace": "kube-system",
        "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/etcd-server-events-ip-10-30-78-99.eu-central-1.compute.internal",
        "creationTimestamp": "2018-08-20T03:19:05Z"
      },
      "timestamp": "2018-08-20T03:19:00Z",
      "window": "1m0s",
      "containers": [
        {
          "name": "etcd-container",
          "usage": {
            "cpu": "7m",
            "memory": "125448Ki"
          }
        }
      ]
    },

  ]
}

metrics-server-prom transforms it to the following format:

Note: Additional metadata (node and ip) have been added.

# HELP kube_metrics_server_pod_cpu The CPU time of a pod in seconds.
# TYPE kube_metrics_server_pod_cpu gauge
kube_metrics_server_pod_cpu{node="ip-10-30-78-99.eu-central-1.compute.internal",pod="etcd-server-events-abc",ip="10.30.62.138",container="etcd-container",namespace="kube-system"} 420
# HELP kube_metrics_server_pod_mem The memory of a pod in KiloBytes.
# TYPE kube_metrics_server_pod_mem gauge
kube_metrics_server_pod_mem{node="ip-10-30-78-99.eu-central-1.compute.internal",pod="etcd-server-events-abc",ip="10.30.62.138",container="etcd-container",namespace="kube-system"} 128475136

License

MIT License

Copyright (c) 2018 cytopia

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].