From: Martin Pitt Date: Fri, 21 May 2021 08:40:32 +0000 (+0200) Subject: Add custom prometheus data source from host X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=762850f8170ad2411fe014b5af63d4820ac9301f;p=learn-metrics.git Add custom prometheus data source from host Export http/metrics into prometheus via an intermediate web server in the pod, and configuring it as an additional source. You can manually provide metrics by copying http/metrics.template to http/metrics and edit the numbers while prometheus is running. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea404d0 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +http/metrics diff --git a/conf-prometheus/prometheus.yml b/conf-prometheus/prometheus.yml new file mode 100644 index 0000000..592ac7a --- /dev/null +++ b/conf-prometheus/prometheus.yml @@ -0,0 +1,22 @@ +global: + scrape_interval: 5s + scrape_timeout: 5s + evaluation_interval: 15s +alerting: + alertmanagers: + - static_configs: + - targets: [] + scheme: http + timeout: 10s + api_version: v1 +scrape_configs: +- job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + +- job_name: host-http + honor_timestamps: true + metrics_path: /metrics + scheme: http + static_configs: + - targets: ['localhost:8080'] diff --git a/http/README b/http/README new file mode 100644 index 0000000..d1b49ee --- /dev/null +++ b/http/README @@ -0,0 +1,2 @@ +This directory will be served by lighttpd in the pod +Intended for exporting metrics diff --git a/http/metrics.template b/http/metrics.template new file mode 100644 index 0000000..a81fec0 --- /dev/null +++ b/http/metrics.template @@ -0,0 +1,7 @@ +# HELP thing_count how many things ran +# TYPE thing_count counter +thing_count 0 + +# HELP thing_failures how many things failed +# TYPE thing_failures counter +thing_failures 0 diff --git a/learn-metrics.yaml b/learn-metrics.yaml index 4d76cf9..6966d78 100644 --- a/learn-metrics.yaml +++ b/learn-metrics.yaml @@ -26,9 +26,27 @@ spec: - containerPort: 9090 hostPort: 3001 protocol: TCP + volumeMounts: + - name: prometheus-config + mountPath: /etc/prometheus/prometheus.yml + readOnly: true + + - image: quay.io/bitnami/nginx + name: httpd + volumeMounts: + - name: http + mountPath: /app + readOnly: true volumes: - hostPath: path: ./conf-grafana/datasource.yaml type: File name: grafana-datasource + - hostPath: + path: ./conf-prometheus/prometheus.yml + type: File + name: prometheus-config + - hostPath: + path: ./http + name: http