diff --git a/prometheus/DOCS.md b/prometheus/DOCS.md index 07974a7..78ffe1e 100644 --- a/prometheus/DOCS.md +++ b/prometheus/DOCS.md @@ -19,7 +19,7 @@ comparison to installing any other Home Assistant add-on. There are no configuration options for the addon. -To add additional scrape targets you need to create a file per target in /share/prometheus/targets. +To add additional scrape targets you need to create a file per target in `/share/prometheus/targets`. Example: @@ -36,6 +36,22 @@ static_configs: **Note**: _This is just an example, don't copy and paste it! Create your own!_ +Similarly, to set up remotes for Prometheus `remote_write` feature, you need to create a file per remote in `/share/prometheus/remotes`. + +Example to write to a Grafana Cloud Prometheus endpoint: + +```yaml +url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push +basic_auth: + username: + password: +write_relabel_configs: + - target_label: instance + replacement: dev-container +``` + +The above example also changes the `instance` label to the `dev-container` value. + The job names `home-assistant` and `prometheus` are already defined by default. For the `homeassistant` target you must add add the following to the Home Assistant configuration: diff --git a/prometheus/rootfs/etc/services.d/prometheus/run b/prometheus/rootfs/etc/services.d/prometheus/run index ded5762..d42501f 100755 --- a/prometheus/rootfs/etc/services.d/prometheus/run +++ b/prometheus/rootfs/etc/services.d/prometheus/run @@ -38,5 +38,9 @@ if ! bashio::fs.directory_exists /share/prometheus/targets; then mkdir -p /share/prometheus/targets fi +if ! bashio::fs.directory_exists /share/prometheus/remotes; then + mkdir -p /share/prometheus/remotes +fi + # Run Prometheus exec /usr/local/bin/prometheus "${options[@]}" diff --git a/prometheus/rootfs/opt/prometheus-configgen/combiner b/prometheus/rootfs/opt/prometheus-configgen/combiner index 2553527..1927e31 100644 --- a/prometheus/rootfs/opt/prometheus-configgen/combiner +++ b/prometheus/rootfs/opt/prometheus-configgen/combiner @@ -22,6 +22,11 @@ def generateConfig(): ) del data[".scrape_configs_static"] del data[".scrape_configs_included"] + + if len(data[".remote_write_included"]) > 0: + data["remote_write"] = data[".remote_write_included"] + + del data[".remote_write_included"] return yaml.dump(data, default_flow_style=False, default_style="") @@ -52,7 +57,7 @@ def writeConfig(config, file): loop = asyncio.get_event_loop() -paths_to_watch = ["/share/prometheus/targets/"] +paths_to_watch = ["/share/prometheus/targets/", "/share/prometheus/remotes"] lock = asyncio.Lock() diff --git a/prometheus/rootfs/opt/prometheus-configgen/prometheus.template b/prometheus/rootfs/opt/prometheus-configgen/prometheus.template index 7589935..7858d9b 100644 --- a/prometheus/rootfs/opt/prometheus-configgen/prometheus.template +++ b/prometheus/rootfs/opt/prometheus-configgen/prometheus.template @@ -16,7 +16,6 @@ alerting: rule_files: - "/share/prometheus/rules/*.yaml" - .scrape_configs_included: !include targets/*.yaml .scrape_configs_static: - job_name: 'home-assistant' @@ -36,3 +35,5 @@ rule_files: static_configs: - targets: ['localhost:9090'] + +.remote_write_included: !include remotes/*.yaml \ No newline at end of file