11 changed files with 179 additions and 90 deletions
@ -0,0 +1,80 @@
|
||||
--- |
||||
title: Using Prometheus Operator |
||||
--- |
||||
|
||||
{{< toc >}} |
||||
|
||||
As an alternative to local files service discovery Prometheus also support discoveries form HTTP endpoints. In a Kubernetes setup, with the Prometheus operator, it makes more sense to use this [HTTP SD](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#http_sd_config) instead of mounting the output file of the `prometheus-pve-sd` to the container. |
||||
|
||||
The `prometheus-pve-sd` module doesn't have a dedicated HTTP endpoint, therefore you need to use a web server sidecar, that hosts the static file. The following deployment configuration can serve as a starting point for most setups, and just requires some minor adjustments, depending on your Kubernetes setup. |
||||
|
||||
## Kubernetes configuration |
||||
|
||||
Deployment configuration: |
||||
|
||||
```YAML |
||||
apiVersion: apps/v1 |
||||
kind: Deployment |
||||
metadata: |
||||
creationTimestamp: null |
||||
labels: |
||||
app: proxmox-service-discovery |
||||
name: proxmox-service-discovery |
||||
spec: |
||||
replicas: 1 |
||||
selector: |
||||
matchLabels: |
||||
app: proxmox-service-discovery |
||||
strategy: {} |
||||
template: |
||||
metadata: |
||||
creationTimestamp: null |
||||
labels: |
||||
app: proxmox-service-discovery |
||||
spec: |
||||
containers: |
||||
- image: nginx |
||||
name: webserver |
||||
resources: {} |
||||
ports: |
||||
- containerPort: 80 |
||||
protocol: TCP |
||||
name: http |
||||
volumeMounts: |
||||
- name: pve-sd-output |
||||
mountPath: /usr/share/nginx/html |
||||
- image: thegeeklab/prometheus-pve-sd |
||||
name: prometheus-pve-sd |
||||
resources: {} |
||||
env: |
||||
- name: PROMETHEUS_PVE_SD_OUTPUT_FILE |
||||
value: /tmp/pve/proxmox.json |
||||
# Add more configurations here, or use a configMap or secret to inject the remaining configs |
||||
volumeMounts: |
||||
- name: pve-sd-output |
||||
mountPath: /tmp/pve/ |
||||
volumes: |
||||
- name: pve-sd-output |
||||
emptyDir: {} |
||||
status: {} |
||||
``` |
||||
|
||||
Additionally you will need a service, that exposes the HTTP endpoint within Kubernetes so Prometheus can scrape it. |
||||
|
||||
Service configuration: |
||||
|
||||
```YAML |
||||
apiVersion: v1 |
||||
kind: Service |
||||
metadata: |
||||
name: pve-sd-service |
||||
spec: |
||||
selector: |
||||
app: proxmox-service-discovery |
||||
ports: |
||||
- protocol: TCP |
||||
port: 80 |
||||
targetPort: 80 |
||||
``` |
||||
|
||||
After configuring and starting the service, Prometheus need to be [configured](/usage/getting-started/#prometheus-configuration) to use the external service discovery. |
@ -0,0 +1,53 @@
|
||||
--- |
||||
title: Getting Started |
||||
--- |
||||
|
||||
{{< toc >}} |
||||
|
||||
## Prometheus relabeling |
||||
|
||||
### Use IP address labels |
||||
|
||||
Instead of `__meta_pve_name`, it is also possible to configure Prometheus to use the address provided by `__meta_pve_ipv4` or `__meta_pve_ipv4` for connections: |
||||
|
||||
```YAML |
||||
relabel_configs: |
||||
- replacement: ${1}:9273 |
||||
source_labels: |
||||
- __meta_pve_ipv4 |
||||
target_label: __address__ |
||||
``` |
||||
|
||||
### Convert tags to custom labels |
||||
|
||||
Tags of a node exposed by the `__meta_pve_tags` might be useful to build more complex configurations in Prometheus. As an example, an `alert` tag can be extracted to dine alerting routes based on the tag value. |
||||
|
||||
**Example:** |
||||
|
||||
Extract `group` and `alert` from a list of tags like this: `__meta_pve_tags="alert:team-1,group:cluster-1,node:node-1"` |
||||
|
||||
```YAML |
||||
relabel_configs: |
||||
- source_labels: |
||||
- __meta_pve_tags |
||||
regex: ".*group:([\w\-_]*)" |
||||
target_label: "group" |
||||
replacement: "${1}" |
||||
- source_labels: |
||||
- __meta_pve_tags |
||||
regex: ".*alert:([\w\-_]*)" |
||||
target_label: "alert" |
||||
replacement: "${1}" |
||||
``` |
||||
|
||||
Use the extracted `alert` label to set an Alertmanager route: |
||||
|
||||
```YAML |
||||
routes: |
||||
- receiver: "empty" |
||||
matchers: |
||||
- alert = muted |
||||
- receiver: "team-1" |
||||
matchers: |
||||
- alert = team-1 |
||||
``` |
Loading…
Reference in new issue