mirror of
https://github.com/hassio-addons/addon-prometheus.git
synced 2025-05-04 19:21:35 +00:00
feat: implement remote write support
This change adds support to define remote write destinations. Fixes #51.
This commit is contained in:
parent
d0e295dc83
commit
fcf226ceda
4 changed files with 29 additions and 3 deletions
|
@ -19,7 +19,7 @@ comparison to installing any other Home Assistant add-on.
|
||||||
|
|
||||||
There are no configuration options for the addon.
|
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:
|
Example:
|
||||||
|
|
||||||
|
@ -36,6 +36,22 @@ static_configs:
|
||||||
|
|
||||||
**Note**: _This is just an example, don't copy and paste it! Create your own!_
|
**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.
|
The job names `home-assistant` and `prometheus` are already defined by default.
|
||||||
For the `homeassistant` target you must add add the following to
|
For the `homeassistant` target you must add add the following to
|
||||||
the Home Assistant configuration:
|
the Home Assistant configuration:
|
||||||
|
|
|
@ -38,5 +38,9 @@ if ! bashio::fs.directory_exists /share/prometheus/targets; then
|
||||||
mkdir -p /share/prometheus/targets
|
mkdir -p /share/prometheus/targets
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! bashio::fs.directory_exists /share/prometheus/remotes; then
|
||||||
|
mkdir -p /share/prometheus/remotes
|
||||||
|
fi
|
||||||
|
|
||||||
# Run Prometheus
|
# Run Prometheus
|
||||||
exec /usr/local/bin/prometheus "${options[@]}"
|
exec /usr/local/bin/prometheus "${options[@]}"
|
||||||
|
|
|
@ -22,6 +22,11 @@ def generateConfig():
|
||||||
)
|
)
|
||||||
del data[".scrape_configs_static"]
|
del data[".scrape_configs_static"]
|
||||||
del data[".scrape_configs_included"]
|
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="")
|
return yaml.dump(data, default_flow_style=False, default_style="")
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +57,7 @@ def writeConfig(config, file):
|
||||||
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
paths_to_watch = ["/share/prometheus/targets/"]
|
paths_to_watch = ["/share/prometheus/targets/", "/share/prometheus/remotes"]
|
||||||
|
|
||||||
lock = asyncio.Lock()
|
lock = asyncio.Lock()
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ alerting:
|
||||||
rule_files:
|
rule_files:
|
||||||
- "/share/prometheus/rules/*.yaml"
|
- "/share/prometheus/rules/*.yaml"
|
||||||
|
|
||||||
|
|
||||||
.scrape_configs_included: !include targets/*.yaml
|
.scrape_configs_included: !include targets/*.yaml
|
||||||
.scrape_configs_static:
|
.scrape_configs_static:
|
||||||
- job_name: 'home-assistant'
|
- job_name: 'home-assistant'
|
||||||
|
@ -36,3 +35,5 @@ rule_files:
|
||||||
|
|
||||||
static_configs:
|
static_configs:
|
||||||
- targets: ['localhost:9090']
|
- targets: ['localhost:9090']
|
||||||
|
|
||||||
|
.remote_write_included: !include remotes/*.yaml
|
Loading…
Add table
Add a link
Reference in a new issue