2024-10-21 12:31:30 +07:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
unstable,
|
|
|
|
...
|
|
|
|
}:
|
2024-09-06 21:13:31 +07:00
|
|
|
let
|
|
|
|
cfg = config.profile.services.telemetry.alloy;
|
|
|
|
webguiListenAddress = "0.0.0.0:5319";
|
2024-10-29 21:45:05 +07:00
|
|
|
otelcolHTTPListenAddress = "192.168.100.5:4318";
|
|
|
|
otelcolGRPCListenAddress = "192.168.100.5:4317";
|
2024-09-06 21:13:31 +07:00
|
|
|
domain = "alloy.tigor.web.id";
|
|
|
|
in
|
|
|
|
{
|
2024-11-24 11:02:56 +07:00
|
|
|
# imports = [
|
|
|
|
# # Grafana Alloy is still in unstable options.
|
|
|
|
# "${inputs.nixpkgs-unstable}/nixos/modules/services/monitoring/alloy.nix"
|
|
|
|
# ];
|
2024-09-06 21:13:31 +07:00
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.alloy = {
|
|
|
|
enable = true;
|
2024-10-21 12:31:30 +07:00
|
|
|
extraFlags = [ ''--server.http.listen-addr=${webguiListenAddress}'' ];
|
2024-09-06 21:13:31 +07:00
|
|
|
package = unstable.grafana-alloy;
|
|
|
|
};
|
|
|
|
services.caddy.virtualHosts.${domain}.extraConfig = ''
|
|
|
|
@require_auth not remote_ip private_ranges
|
|
|
|
|
2024-10-28 21:38:34 +07:00
|
|
|
basic_auth @require_auth {
|
|
|
|
{$AUTH_USERNAME} {$AUTH_PASSWORD}
|
2024-09-06 21:13:31 +07:00
|
|
|
}
|
2024-10-21 12:31:30 +07:00
|
|
|
|
2024-09-06 21:13:31 +07:00
|
|
|
reverse_proxy ${webguiListenAddress}
|
|
|
|
'';
|
|
|
|
|
2024-10-29 21:45:05 +07:00
|
|
|
services.caddy.virtualHosts."otelhttp.tigor.web.id".extraConfig = ''
|
|
|
|
@require_auth not remote_ip private_ranges
|
|
|
|
|
|
|
|
basic_auth @require_auth {
|
|
|
|
{$AUTH_USERNAME} {$AUTH_PASSWORD}
|
|
|
|
}
|
|
|
|
|
|
|
|
reverse_proxy ${otelcolHTTPListenAddress}
|
|
|
|
'';
|
|
|
|
|
|
|
|
services.caddy.virtualHosts."otelgrpc.tigor.web.id".extraConfig = ''
|
|
|
|
@require_auth not remote_ip private_ranges
|
|
|
|
|
|
|
|
basic_auth @require_auth {
|
|
|
|
{$AUTH_USERNAME} {$AUTH_PASSWORD}
|
|
|
|
}
|
|
|
|
|
2024-10-29 21:56:27 +07:00
|
|
|
reverse_proxy ${otelcolGRPCListenAddress} {
|
|
|
|
transport http {
|
|
|
|
tls
|
|
|
|
tls_insecure_skip_verify
|
|
|
|
}
|
|
|
|
}
|
2024-10-29 21:45:05 +07:00
|
|
|
'';
|
|
|
|
|
2024-09-16 10:32:43 +07:00
|
|
|
systemd.services.alloy.serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
};
|
|
|
|
|
2024-09-06 21:13:31 +07:00
|
|
|
environment.etc."alloy/config.alloy".text =
|
|
|
|
let
|
|
|
|
lokiConfig = config.services.loki.configuration;
|
2024-10-29 21:45:05 +07:00
|
|
|
tempoProtocols = config.services.tempo.settings.distributor.receivers.otlp.protocols;
|
2024-09-07 10:41:59 +07:00
|
|
|
mimirServer = config.services.mimir.configuration.server;
|
2024-09-06 21:13:31 +07:00
|
|
|
in
|
2024-10-21 12:31:30 +07:00
|
|
|
# hcl
|
|
|
|
''
|
2024-09-06 21:13:31 +07:00
|
|
|
otelcol.receiver.otlp "homeserver" {
|
|
|
|
grpc {
|
2024-10-29 21:45:05 +07:00
|
|
|
endpoint = "${otelcolGRPCListenAddress}"
|
2024-09-06 21:13:31 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
http {
|
2024-10-29 21:45:05 +07:00
|
|
|
endpoint = "${otelcolHTTPListenAddress}"
|
2024-09-06 21:13:31 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
output {
|
2024-09-07 10:41:59 +07:00
|
|
|
metrics = [otelcol.processor.batch.default.input]
|
2024-09-06 21:13:31 +07:00
|
|
|
logs = [otelcol.processor.batch.default.input]
|
2024-09-07 08:59:44 +07:00
|
|
|
traces = [otelcol.processor.batch.default.input]
|
2024-09-06 21:13:31 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
otelcol.processor.batch "default" {
|
|
|
|
output {
|
2024-09-07 10:41:59 +07:00
|
|
|
metrics = [otelcol.exporter.prometheus.mimir.input]
|
2024-09-06 21:13:31 +07:00
|
|
|
logs = [otelcol.exporter.loki.default.input]
|
2024-09-07 08:59:44 +07:00
|
|
|
traces = [otelcol.exporter.otlp.tempo.input]
|
2024-09-06 21:13:31 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
otelcol.exporter.loki "default" {
|
|
|
|
forward_to = [loki.write.default.receiver]
|
|
|
|
}
|
|
|
|
|
2024-09-07 10:41:59 +07:00
|
|
|
otelcol.exporter.prometheus "mimir" {
|
|
|
|
forward_to = [prometheus.remote_write.mimir.receiver]
|
|
|
|
}
|
|
|
|
|
2024-09-06 21:13:31 +07:00
|
|
|
loki.write "default" {
|
|
|
|
endpoint {
|
2024-09-09 17:53:38 +07:00
|
|
|
url = "http://${lokiConfig.server.http_listen_address}:${toString lokiConfig.server.http_listen_port}/loki/api/v1/push"
|
2024-09-06 21:13:31 +07:00
|
|
|
}
|
|
|
|
}
|
2024-09-07 08:59:44 +07:00
|
|
|
|
2024-09-09 17:53:38 +07:00
|
|
|
loki.relabel "journal" {
|
|
|
|
forward_to = []
|
|
|
|
rule {
|
|
|
|
source_labels = ["__journal__systemd_unit"]
|
|
|
|
target_label = "unit"
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
source_labels = ["__journal__hostname"]
|
|
|
|
target_label = "host"
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
source_labels = [ "__journal__systemd_user_unit" ]
|
|
|
|
target_label = "user_unit"
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
source_labels = [ "__journal__transport" ]
|
|
|
|
target_label = "transport"
|
|
|
|
}
|
|
|
|
rule {
|
|
|
|
source_labels = [ "__journal_priority_keyword" ]
|
|
|
|
target_label = "severity"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loki.source.journal "read" {
|
2024-09-17 13:13:30 +07:00
|
|
|
forward_to = [loki.process.general_json_pipeline.receiver]
|
2024-09-09 17:53:38 +07:00
|
|
|
relabel_rules = loki.relabel.journal.rules
|
|
|
|
labels = {
|
|
|
|
job = "systemd-journal",
|
|
|
|
component = "loki.source.journal",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-17 13:13:30 +07:00
|
|
|
loki.process "general_json_pipeline" {
|
|
|
|
forward_to = [loki.write.default.receiver]
|
|
|
|
|
|
|
|
stage.json {
|
|
|
|
expressions = {
|
|
|
|
level = "level",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage.labels {
|
|
|
|
values = {
|
|
|
|
level = "",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-07 08:59:44 +07:00
|
|
|
otelcol.exporter.otlp "tempo" {
|
|
|
|
client {
|
2024-10-29 21:45:05 +07:00
|
|
|
endpoint = "${tempoProtocols.grpc.endpoint}"
|
|
|
|
tls {
|
|
|
|
insecure = true
|
|
|
|
insecure_skip_verify = true
|
|
|
|
}
|
2024-09-07 08:59:44 +07:00
|
|
|
}
|
|
|
|
}
|
2024-09-07 10:41:59 +07:00
|
|
|
|
2024-09-09 17:53:38 +07:00
|
|
|
prometheus.exporter.unix "system" {}
|
|
|
|
|
|
|
|
prometheus.scrape "system" {
|
|
|
|
targets = prometheus.exporter.unix.system.targets
|
|
|
|
forward_to = [prometheus.remote_write.mimir.receiver]
|
|
|
|
}
|
|
|
|
|
2024-10-30 16:58:15 +07:00
|
|
|
prometheus.exporter.self "alloy" {}
|
|
|
|
|
|
|
|
prometheus.scrape "alloy" {
|
|
|
|
targets = prometheus.exporter.self.alloy.targets
|
|
|
|
forward_to = [prometheus.remote_write.mimir.receiver]
|
|
|
|
}
|
|
|
|
|
2024-09-10 12:09:50 +07:00
|
|
|
prometheus.scrape "caddy" {
|
|
|
|
targets = [{
|
|
|
|
__address__ = "localhost:2019",
|
|
|
|
}]
|
|
|
|
|
|
|
|
job_name = "caddy"
|
|
|
|
|
|
|
|
forward_to = [prometheus.remote_write.mimir.receiver]
|
|
|
|
}
|
|
|
|
|
2024-09-07 10:41:59 +07:00
|
|
|
prometheus.remote_write "mimir" {
|
|
|
|
endpoint {
|
2024-09-09 17:53:38 +07:00
|
|
|
url = "http://${mimirServer.http_listen_address}:${toString mimirServer.http_listen_port}/api/v1/push"
|
2024-09-07 10:41:59 +07:00
|
|
|
}
|
|
|
|
}
|
2024-09-06 21:13:31 +07:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|