Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
feat: implement remote write support
Browse files Browse the repository at this point in the history
This change adds support to define remote write destinations.

Fixes #51.
  • Loading branch information
lupino3 committed Aug 21, 2023
1 parent d0e295d commit fcf226c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
18 changes: 17 additions & 1 deletion prometheus/DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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: <your username>
password: <Your API key>
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:
Expand Down
4 changes: 4 additions & 0 deletions prometheus/rootfs/etc/services.d/prometheus/run
Original file line number Diff line number Diff line change
Expand Up @@ -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[@]}"
7 changes: 6 additions & 1 deletion prometheus/rootfs/opt/prometheus-configgen/combiner
Original file line number Diff line number Diff line change
Expand Up @@ -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="")


Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ alerting:
rule_files:
- "/share/prometheus/rules/*.yaml"


.scrape_configs_included: !include targets/*.yaml
.scrape_configs_static:
- job_name: 'home-assistant'
Expand All @@ -36,3 +35,5 @@ rule_files:

static_configs:
- targets: ['localhost:9090']

.remote_write_included: !include remotes/*.yaml

0 comments on commit fcf226c

Please sign in to comment.