{"id":15659151,"url":"https://github.com/cytopia/metrics-server-prom","last_synced_at":"2025-05-05T17:21:50.426Z","repository":{"id":147859316,"uuid":"145361320","full_name":"cytopia/metrics-server-prom","owner":"cytopia","description":"Prometheus adapter to scrape from Kubernetes metrics-server","archived":false,"fork":false,"pushed_at":"2019-11-04T17:38:47.000Z","size":110,"stargazers_count":21,"open_issues_count":1,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T22:41:13.008Z","etag":null,"topics":["docker","k8s","kube-proxy","kubernetes","metrics","metrics-server","metrics-transformation","monitoring","prometheus","prometheus-exporter"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cytopia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-20T03:25:21.000Z","updated_at":"2023-03-17T14:40:17.000Z","dependencies_parsed_at":"2023-05-27T17:30:12.830Z","dependency_job_id":null,"html_url":"https://github.com/cytopia/metrics-server-prom","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytopia%2Fmetrics-server-prom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytopia%2Fmetrics-server-prom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytopia%2Fmetrics-server-prom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cytopia%2Fmetrics-server-prom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cytopia","download_url":"https://codeload.github.com/cytopia/metrics-server-prom/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252542090,"owners_count":21764909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","k8s","kube-proxy","kubernetes","metrics","metrics-server","metrics-transformation","monitoring","prometheus","prometheus-exporter"],"created_at":"2024-10-03T13:15:23.750Z","updated_at":"2025-05-05T17:21:50.403Z","avatar_url":"https://github.com/cytopia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kubernetes Metrics Server Prometheus Adapter\n\n**[Motivation](#motivation)** |\n**[Usage](#usage)** |\n**[Docker Compose](#docker-compose)** |\n**[Metrics transformation](#metrics-transformation)** |\n**[License](#license)**\n\n[![Build Status](https://travis-ci.org/cytopia/metrics-server-prom.svg?branch=master)](https://travis-ci.org/cytopia/metrics-server-prom)\n[![release](https://img.shields.io/github/tag/cytopia/metrics-server-prom.svg)](https://github.com/cytopia/metrics-server-prom/releases)\n\n\u003ca target=\"_blank\" title=\"DockerHub\" href=\"https://hub.docker.com/r/cytopia/metrics-server-prom/\"\u003e\u003cimg src=\"https://dockeri.co/image/cytopia/metrics-server-prom\" /\u003e\u003c/a\u003e\n\n## Motivation\n\n### What is provided\n\nA Docker image on which [Prometheus](https://github.com/prometheus/prometheus) can scrape Kubernetes metrics provided by **[metrics-server](https://github.com/kubernetes-incubator/metrics-server)**. The image can run anywhere where Prometheus can use it as a target, even in Kubernetes itself.\n\n### Why is it needed\n\nmetrics-server seems to be the [successor of heapster](https://github.com/kubernetes/heapster) for Kubernetes monitoring. However, metrics-server currently only provides its metrics in JSON format via the Kubernetes API server.\n\nPrometheus on the other hand expects a special [text-based format](https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information).\nSo in order for Prometheus to scrape those metrics, they must be transparently transformed from JSON to its own format on every request.\n\n### Differences\n\nOther than metrics-server itself, this Docker container provides additional metrics metadata that are\nretrieved via `kubectl` API calls and included in the Prometheus output.\n\n### How does it work\n\nThe following diagram illustrates how the format transformation is achieved:\n\n[![workflow](doc/metrics-server-prom-adapter.png)](doc/metrics-server-prom-adapter.png)\n\n1. Prometheus scrapes the Docker container on `:9100/metrics`\n2. Inside the Docker container [uwsgi](https://github.com/unbit/uwsgi) is proxying the request to [kube proxy](https://kubernetes.io/docs/reference/command-line-tools-reference/kube-proxy/)\n3. kube-proxy reads the provided config file and tunnels the request into Kubernetes to metrics-server\n4. metrics-server replies with JSON formatted metrics\n5. kube proxy forwards the request back to uwsgi\n6. uwsgi calls [transform.py](data/src/transform.py)\n7. transform.py rewrites the JSON into Prometheus readable output and hands the result back to uwsgi\n8. uwsgi sends the final response back to Prometheus\n\n\n## Usage\n\n### Run metrics-server-prom\n\nSimply run the Docker image with a kube config mounted into `/etc/kube/config`.\n\n```bash\n$ docker run -d \\\n    -p 9100:9100 \\\n    -v ${HOME}/.kube/config:/etc/kube/config:ro \\\n    cytopia/metrics-server-prom\n```\nIf your kube config contains multiple contexts, you can tell `metrics-server-prom` what context\nto use, to connect to the cluster.\n\n```bash\n$ docker run -d \\\n    -p 9100:9100 \\\n    -v ${HOME}/.kube/config:/etc/kube/config:ro \\\n    -e KUBE_CONTEXT=my-context \\\n    cytopia/metrics-server-prom\n```\n\n### Configure Prometheus\n\n`prometheus.yml`:\n```yml\nscrape_configs:\n  - job_name: 'kubernetes'\n    scrape_interval: '15s'\n    metrics_path: '/metrics'\n    static_configs:\n      - targets:\n        - \u003cDOCKER_IP_ADDRESS\u003e:9100\n```\n\n## Docker Compose\n\nTo test this out locally, this repository ships an example Docker Compose setup with\nmetrics-server-prom and Prometheus.\n\n1. Navigate to [example/](example/)\n2. Copy `env-example` to `.env`\n3. Adjust `KUBE_CONTEXT` in `.env`\n4. Run it `docker-compose up`\n\n\n## Metrics transformation\n\nmetrics-server provices metrics in the following format:\n```json\n{\n  \"kind\": \"PodMetricsList\",\n  \"apiVersion\": \"metrics.k8s.io/v1beta1\",\n  \"metadata\": {\n    \"selfLink\": \"/apis/metrics.k8s.io/v1beta1/pods\"\n  },\n  \"items\": [\n    {\n      \"metadata\": {\n        \"name\": \"etcd-server-events-abc\",\n        \"namespace\": \"kube-system\",\n        \"selfLink\": \"/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/etcd-server-events-ip-10-30-78-99.eu-central-1.compute.internal\",\n        \"creationTimestamp\": \"2018-08-20T03:19:05Z\"\n      },\n      \"timestamp\": \"2018-08-20T03:19:00Z\",\n      \"window\": \"1m0s\",\n      \"containers\": [\n        {\n          \"name\": \"etcd-container\",\n          \"usage\": {\n            \"cpu\": \"7m\",\n            \"memory\": \"125448Ki\"\n          }\n        }\n      ]\n    },\n\n  ]\n}\n```\n\nmetrics-server-prom transforms it to the following format:\n\n**Note:** Additional metadata (`node` and `ip`) have been added.\n```\n# HELP kube_metrics_server_pod_cpu The CPU time of a pod in seconds.\n# TYPE kube_metrics_server_pod_cpu gauge\nkube_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\n# HELP kube_metrics_server_pod_mem The memory of a pod in KiloBytes.\n# TYPE kube_metrics_server_pod_mem gauge\nkube_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\n```\n\n## License\n\n[MIT License](LICENSE)\n\nCopyright (c) 2018 [cytopia](https://github.com/cytopia)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcytopia%2Fmetrics-server-prom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcytopia%2Fmetrics-server-prom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcytopia%2Fmetrics-server-prom/lists"}