This repository has no description
1.8 kB
51 lines
1# Home Assistant states into the monitoring (configs/monitoring): HA's
2# prometheus integration serves every entity on /api/prometheus, the Vector
3# agent scrapes it with a long-lived access token and writes it to
4# VictoriaMetrics like the host metrics (metric names homeassistant_*).
5{ config, pkgs, ... }:
6{
7 # Mounted as a package; configuration.yaml in the volume loads
8 # /config/packages (homeassistant: packages: !include_dir_named packages).
9 virtualisation.oci-containers.containers.homeassistant.volumes = [
10 "${
11 pkgs.writeText "prometheus.yaml" (builtins.toJSON { prometheus = { }; })
12 }:/config/packages/prometheus.yaml:ro"
13 ];
14
15 # Create in HA: profile -> security -> long-lived access tokens.
16 clan.core.vars.generators.hass-prometheus.prompts.token = {
17 description = "Home Assistant long-lived access token for the Vector scrape of /api/prometheus";
18 type = "hidden";
19 persist = true;
20 };
21
22 systemd.services.vector.serviceConfig.LoadCredential = [
23 "hass-token:${config.clan.core.vars.generators.hass-prometheus.files.token.path}"
24 ];
25
26 monitoring.extraMetrics = [ "hass_metrics" ];
27
28 services.vector.settings = {
29 secret.credentials = {
30 type = "directory";
31 path = "/run/credentials/vector.service";
32 };
33 sources.hass_raw = {
34 type = "prometheus_scrape";
35 endpoints = [ "http://127.0.0.1:8123/api/prometheus" ];
36 auth = {
37 strategy = "bearer";
38 token = "SECRET[credentials.hass-token]";
39 };
40 scrape_interval_secs = 60;
41 scrape_timeout_secs = 30;
42 };
43 transforms.hass_metrics = {
44 type = "remap";
45 inputs = [ "hass_raw" ];
46 source = ''
47 .tags.host = "${config.networking.hostName}"
48 '';
49 };
50 };
51}