Skip to content

Exports Kubernetes services selectors as Prometheus metrics

License

Notifications You must be signed in to change notification settings

hystax/kube-service-selectors

Repository files navigation

Kubernetes services selectors exporter

Exports Kubernetes services selectors as metrics.

Uses Kubernetes API to collect services info.

Source Code | Docker Image | Helm chart

Metrics description

Metric name Metric type Description Labels/tags
kube_service_selectors Gauge Kubernetes selectors converted to Prometheus labels service=<service-name>
namespace=<service-namespace>
uid=<service-uid>
label_SELECTOR_LABEL=<SELECTOR_LABEL>
kube_service_selectors_total Counter Counted exporter workflow result (succeeded and failed) result=<result>

kube_service_selectors transforms Kubernetes labels according to Prometheus labels naming convention and resolves possible conflicts in kube-state-metrics way.

Usage

usage: main.py [-h] [--port PORT] [--namespaces NAMESPACES] [--debug DEBUG]
               [--timeout TIMEOUT] [--kubeconfig KUBECONFIG]

optional arguments:
  -h, --help            show this help message and exit
  --port PORT           server port
  --namespaces NAMESPACES
                        list of comma-separated namespaces (will be listed
                        from all if not provided)
  --debug DEBUG         enable debug logging
  --timeout TIMEOUT     kubernetes requests timeout
  --kubeconfig KUBECONFIG
                        kubernetes config file path. Service account will be
                        used if config missing

From source

The exporter requires Python 3.6 or above and Pip 3 to install requirements:

> pip3 install -r requirements.txt

By default server listens on 30091. Kubernetes config should be placed behind executable with kubeconfig name or passed as --kubeconfig argument when running outside Kubernetes:

> PYTHONPATH=.. python3 main.py --kubeconfig <kubeconfig_path>

Using Docker

> docker run -d -v <kubeconfig_path>:/usr/src/app/kube_service_selectors/kubeconfig -p 30091:30091 --name kss_exporter  hystax/kube-service-selectors