{"id":16540931,"url":"https://github.com/itzg/kube-metrics-exporter","last_synced_at":"2025-10-28T14:31:42.997Z","repository":{"id":43406916,"uuid":"280034541","full_name":"itzg/kube-metrics-exporter","owner":"itzg","description":"Simple application that accesses the Kubernetes metrics API and exports the pod metrics for Prometheus scraping","archived":false,"fork":false,"pushed_at":"2022-03-03T02:55:05.000Z","size":31,"stargazers_count":6,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T15:40:50.507Z","etag":null,"topics":["kubernetes-monitoring","prometheus"],"latest_commit_sha":null,"homepage":"","language":"Go","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/itzg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-16T02:42:02.000Z","updated_at":"2023-01-16T15:20:09.000Z","dependencies_parsed_at":"2022-08-26T20:57:32.933Z","dependency_job_id":null,"html_url":"https://github.com/itzg/kube-metrics-exporter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fkube-metrics-exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fkube-metrics-exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fkube-metrics-exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzg%2Fkube-metrics-exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itzg","download_url":"https://codeload.github.com/itzg/kube-metrics-exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238663184,"owners_count":19509749,"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":["kubernetes-monitoring","prometheus"],"created_at":"2024-10-11T18:53:40.903Z","updated_at":"2025-10-28T14:31:42.590Z","avatar_url":"https://github.com/itzg.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![goreleaser](https://github.com/itzg/kube-metrics-exporter/workflows/goreleaser/badge.svg)](https://github.com/itzg/kube-metrics-exporter/actions?query=workflow%3Agoreleaser)\n[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/itzg/kube-metrics-exporter)](https://github.com/itzg/kube-metrics-exporter/releases/latest)\n[![Docker Pulls](https://img.shields.io/docker/pulls/itzg/kube-metrics-exporter)](https://hub.docker.com/r/itzg/kube-metrics-exporter)\n\nSimple application that accesses the [Kubernetes metrics API](https://github.com/kubernetes/metrics) and exports the pod metrics for Prometheus scraping.\n\nThe Metrics API is exposed by a deployed [Metrics Server](https://kubernetes.io/docs/tasks/debug-application-cluster/resource-metrics-pipeline/#metrics-server) which is included in most managed clusters. [It can also be deployed separately.](https://github.com/kubernetes-sigs/metrics-server).\n\n## Metrics\n\nThis services exports two metrics:\n- `container_cpu_usage_cores`\n- `container_mem_usage_bytes`\n\nBoth metrics include the labels:\n- `namespace`\n- `pod`\n- `container`\n\n### Prometheus label renaming\n\nBy default, Prometheus will rename the labels above to avoid conflicts with the same labels applied during export. As a result, the metric in Prometheus will appear as:\n\n```\ncontainer_cpu_usage_cores{container=\"kube-metrics-exporter\",endpoint=\"http\",exported_container=\"grafana\",exported_namespace=\"default\",exported_pod=\"grafana-0\",instance=\"10.40.1.109:8080\",job=\"thanos-poc/monitor-metrics-http\",namespace=\"default\",pod=\"kube-metrics-exporter-6d9b8f978d-84x6q\"}\n```\n\n### Example\n```\n# HELP container_cpu_usage_cores CPU cores used\n# TYPE container_cpu_usage_cores gauge\ncontainer_cpu_usage_cores{container=\"grafana\",namespace=\"default\",pod=\"grafana-0\"} 0.003\n# HELP container_memory_usage_bytes memory used\n# TYPE container_memory_usage_bytes gauge\ncontainer_memory_usage_bytes{container=\"grafana\",namespace=\"default\",pod=\"grafana-0\"} 6.0362752e+08\n```\n\n## Command-line\n\n```\n  -debug\n        enable debug logging (env DEBUG)\n  -http-binding string\n        binding of http listener for metrics export (env HTTP_BINDING) (default \":8080\")\n  -ignore-namespaces value\n    \twhen 'namespace' is empty, this lists namespaces to ignore (env IGNORE_NAMESPACES) (default kube-system)\n  -metrics-path string\n        http path for metrics export (env METRICS_PATH) (default \"/metrics\")\n  -namespace string\n        the namespace of the pods to collect (env NAMESPACE) (default \"default\")\n```\n\n## Stand-alone Usage\n\nThe `kube-metrics-exporter` executable can be executed outside of Kubernetes cluster, in which case it will locate and use the kubernetes configuration from the standard location(s).\n\n## In-cluster Usage\n\nWith a service account defined with the correct roles, [as described below](#service-account), the reporter can be deployed with a pod manifest such as the following to export metrics for pods in the same namespace:\n\n```yaml\n    metadata:\n      name: kube-metrics-exporter\n      labels:\n        app: kube-metrics-exporter\n    spec:\n      serviceAccountName: kube-metrics-monitor\n      containers:\n        - name: kube-metrics-exporter\n          image: itzg/kube-metrics-exporter\n          env:\n            - name: NAMESPACE\n              valueFrom:\n                fieldRef:\n                  fieldPath: metadata.namespace\n```\n\n## Service account\n\nSince this application accesses the metrics API of the kubernetes API service, the pod will need to be assigned a service account with an appropriate role.\n\n\u003e Service accounts must be present before the deployment, so either ensure the service account manifest is applied first or place the service account yaml documents before the deployment in the same manifest file.\n\nThe following shows how a service account could be declared:\n\n```yaml\n---\napiVersion: v1\nkind: ServiceAccount\nmetadata:\n  name: kube-metrics-monitor\n---\napiVersion: rbac.authorization.k8s.io/v1\nkind: Role\nmetadata:\n  name: kube-metrics-monitor\nrules:\n  - apiGroups: [\"metrics.k8s.io\"]\n    resources:\n      - pods\n    verbs: [\"get\", \"list\"]\n---\napiVersion: rbac.authorization.k8s.io/v1\nkind: RoleBinding\nmetadata:\n  name: kube-metrics-monitor\nroleRef:\n  apiGroup: rbac.authorization.k8s.io\n  kind: Role\n  name: kube-metrics-monitor\nsubjects:\n  - kind: ServiceAccount\n    name: kube-metrics-monitor\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzg%2Fkube-metrics-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitzg%2Fkube-metrics-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzg%2Fkube-metrics-exporter/lists"}