| 1 | { config, pkgs, ... }: |
| 2 | |
| 3 | { |
| 4 | services.prometheus = { |
| 5 | exporters.json = { |
| 6 | enable = true; |
| 7 | listenAddress = "localhost"; |
| 8 | |
| 9 | configFile = (pkgs.formats.yaml { }).generate "json-exporter-config.yml" { |
| 10 | modules.matrix-federation-checker = { |
| 11 | metrics = [ |
| 12 | { |
| 13 | name = "matrix_homeserver_federation_ok"; |
| 14 | path = "{.FederationOK}"; |
| 15 | help = "False if there's any problem with federation reported."; |
| 16 | type = "value"; |
| 17 | value_type = "gauge"; |
| 18 | } |
| 19 | ]; |
| 20 | }; |
| 21 | }; |
| 22 | }; |
| 23 | |
| 24 | scrapeConfigs = [ |
| 25 | { |
| 26 | job_name = "matrix-federation-checker"; |
| 27 | metrics_path = "/probe"; |
| 28 | params = { |
| 29 | module = [ "matrix-federation-checker" ]; |
| 30 | }; |
| 31 | relabel_configs = [ |
| 32 | { |
| 33 | source_labels = [ "__address__" ]; |
| 34 | target_label = "__param_target"; |
| 35 | } |
| 36 | { |
| 37 | source_labels = [ "__address__" ]; |
| 38 | target_label = "instance"; |
| 39 | } |
| 40 | { |
| 41 | target_label = "__address__"; |
| 42 | replacement = "localhost:${toString config.services.prometheus.exporters.json.port}"; |
| 43 | } |
| 44 | ]; |
| 45 | |
| 46 | static_configs = [ |
| 47 | { |
| 48 | targets = [ "https://federationtester.matrix.org/api/report?server_name=nixos.org" ]; |
| 49 | labels.matrix_instance = "nixos.org"; |
| 50 | } |
| 51 | ]; |
| 52 | } |
| 53 | ]; |
| 54 | |
| 55 | ruleFiles = [ |
| 56 | (pkgs.writeText "matrix-federation.rules" ( |
| 57 | builtins.toJSON { |
| 58 | groups = [ |
| 59 | { |
| 60 | name = "matrix-federation"; |
| 61 | rules = [ |
| 62 | { |
| 63 | alert = "MatrixFederationFailure"; |
| 64 | expr = "matrix_homeserver_federation_ok < 1"; |
| 65 | for = "30m"; |
| 66 | labels.severity = "warning"; |
| 67 | annotations.summary = "Matrix federation for {{ $labels.matrix_instance }} appears to be failing."; |
| 68 | } |
| 69 | ]; |
| 70 | } |
| 71 | ]; |
| 72 | } |
| 73 | )) |
| 74 | ]; |
| 75 | }; |
| 76 | } |