|
| 1 | +// Grafana Alloy configuration for Linera validator observability |
| 2 | +// Collects metrics, logs, and traces and forwards to central stack |
| 3 | + |
| 4 | +// ==================== Prometheus Metrics Scraping ==================== |
| 5 | + |
| 6 | +// Scrape metrics from proxy service |
| 7 | +prometheus.scrape "proxy_metrics" { |
| 8 | + targets = [{ |
| 9 | + __address__ = "proxy:21100", |
| 10 | + job = "linera-proxy", |
| 11 | + instance = env("HOSTNAME"), |
| 12 | + }] |
| 13 | + |
| 14 | + // Forward to OTLP converter for remote push if configured |
| 15 | + forward_to = [otelcol.receiver.prometheus.default.receiver] |
| 16 | + |
| 17 | + scrape_interval = "15s" |
| 18 | + scrape_timeout = "10s" |
| 19 | +} |
| 20 | + |
| 21 | +// Scrape metrics from shard services (all 4 replicas) |
| 22 | +prometheus.scrape "shard_metrics" { |
| 23 | + targets = [ |
| 24 | + { |
| 25 | + __address__ = "shard:21100", |
| 26 | + job = "linera-shard", |
| 27 | + instance = env("HOSTNAME"), |
| 28 | + }, |
| 29 | + ] |
| 30 | + |
| 31 | + // Forward to OTLP converter for remote push if configured |
| 32 | + forward_to = [otelcol.receiver.prometheus.default.receiver] |
| 33 | + |
| 34 | + scrape_interval = "15s" |
| 35 | + scrape_timeout = "10s" |
| 36 | +} |
| 37 | + |
| 38 | +// Expose Alloy's own metrics |
| 39 | +prometheus.exporter.self "alloy" {} |
| 40 | + |
| 41 | +prometheus.scrape "alloy_metrics" { |
| 42 | + targets = prometheus.exporter.self.alloy.targets |
| 43 | + // Forward to OTLP converter for remote push if configured |
| 44 | + forward_to = [otelcol.receiver.prometheus.default.receiver] |
| 45 | +} |
| 46 | + |
| 47 | +// ==================== Prometheus Metrics Export (Optional) ==================== |
| 48 | + |
| 49 | +// Convert Prometheus metrics to OTLP and send to central (Prometheus 3.x uses OTLP) |
| 50 | +// To enable, set these environment variables: |
| 51 | +// PROMETHEUS_OTLP_URL: https://your-prometheus-endpoint/otlp |
| 52 | +// PROMETHEUS_OTLP_USER: your-username |
| 53 | +// PROMETHEUS_OTLP_PASS: your-password |
| 54 | + |
| 55 | +// Export Prometheus metrics as OTLP |
| 56 | +otelcol.exporter.otlphttp "prometheus" { |
| 57 | + client { |
| 58 | + endpoint = env("PROMETHEUS_OTLP_URL") |
| 59 | + |
| 60 | + auth = otelcol.auth.basic.prometheus_credentials.handler |
| 61 | + |
| 62 | + tls { |
| 63 | + insecure_skip_verify = false |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +// Basic auth for Prometheus OTLP |
| 69 | +otelcol.auth.basic "prometheus_credentials" { |
| 70 | + username = env("PROMETHEUS_OTLP_USER") |
| 71 | + password = env("PROMETHEUS_OTLP_PASS") |
| 72 | +} |
| 73 | + |
| 74 | +// Convert Prometheus metrics to OTLP format |
| 75 | +otelcol.receiver.prometheus "default" { |
| 76 | + output { |
| 77 | + metrics = [otelcol.exporter.otlphttp.prometheus.input] |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +// ==================== Loki Logs Collection ==================== |
| 82 | + |
| 83 | +// Discover docker containers |
| 84 | +discovery.docker "containers" { |
| 85 | + host = "unix:///var/run/docker.sock" |
| 86 | +} |
| 87 | + |
| 88 | +// Relabel discovered containers |
| 89 | +discovery.relabel "docker_logs" { |
| 90 | + targets = discovery.docker.containers.targets |
| 91 | + |
| 92 | + rule { |
| 93 | + source_labels = ["__meta_docker_container_name"] |
| 94 | + target_label = "container" |
| 95 | + } |
| 96 | + |
| 97 | + rule { |
| 98 | + source_labels = ["__meta_docker_container_label_com_docker_compose_service"] |
| 99 | + target_label = "service" |
| 100 | + } |
| 101 | + |
| 102 | + rule { |
| 103 | + source_labels = ["__meta_docker_container_label_com_docker_compose_project"] |
| 104 | + target_label = "project" |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +// Read docker logs |
| 109 | +loki.source.docker "containers" { |
| 110 | + host = "unix:///var/run/docker.sock" |
| 111 | + targets = discovery.relabel.docker_logs.output |
| 112 | + forward_to = [loki.write.central.receiver] |
| 113 | +} |
| 114 | + |
| 115 | +// Write logs to central Loki (optional - only if env vars are set) |
| 116 | +// To enable, set these environment variables: |
| 117 | +// LOKI_PUSH_URL: https://your-loki-endpoint/loki/api/v1/push |
| 118 | +// LOKI_PUSH_USER: your-username |
| 119 | +// LOKI_PUSH_PASS: your-password |
| 120 | +loki.write "central" { |
| 121 | + endpoint { |
| 122 | + url = env("LOKI_PUSH_URL") |
| 123 | + |
| 124 | + basic_auth { |
| 125 | + username = env("LOKI_PUSH_USER") |
| 126 | + password = env("LOKI_PUSH_PASS") |
| 127 | + } |
| 128 | + |
| 129 | + tls_config { |
| 130 | + insecure_skip_verify = false |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + external_labels = { |
| 135 | + cluster = "validator-docker-compose", |
| 136 | + validator = env("HOSTNAME"), |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | +// ==================== Tempo Traces Collection ==================== |
| 141 | + |
| 142 | +// OTLP receiver for traces |
| 143 | +otelcol.receiver.otlp "default" { |
| 144 | + grpc { |
| 145 | + endpoint = "0.0.0.0:4317" |
| 146 | + } |
| 147 | + |
| 148 | + http { |
| 149 | + endpoint = "0.0.0.0:4318" |
| 150 | + } |
| 151 | + |
| 152 | + output { |
| 153 | + traces = [otelcol.exporter.otlphttp.central.input] |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +// Export traces to central Tempo (optional - only if env vars are set) |
| 158 | +// To enable, set these environment variables: |
| 159 | +// TEMPO_OTLP_URL: https://your-tempo-endpoint/tempo/otlp |
| 160 | +// TEMPO_OTLP_USER: your-username |
| 161 | +// TEMPO_OTLP_PASS: your-password |
| 162 | +otelcol.exporter.otlphttp "central" { |
| 163 | + client { |
| 164 | + endpoint = env("TEMPO_OTLP_URL") |
| 165 | + |
| 166 | + auth = otelcol.auth.basic.credentials.handler |
| 167 | + |
| 168 | + tls { |
| 169 | + insecure_skip_verify = false |
| 170 | + } |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +// Basic auth for OTLP |
| 175 | +otelcol.auth.basic "credentials" { |
| 176 | + username = env("TEMPO_OTLP_USER") |
| 177 | + password = env("TEMPO_OTLP_PASS") |
| 178 | +} |
| 179 | + |
| 180 | +// ==================== Metrics Exposition ==================== |
| 181 | + |
| 182 | +// Expose Prometheus-compatible metrics endpoint for central Prometheus to scrape |
| 183 | +// This runs on port 12345 and exposes all collected metrics |
| 184 | +// Note: Alloy's own metrics are already exposed via prometheus.exporter.self |
0 commit comments