telemetry: added loki

This commit is contained in:
Tigor Hutasuhut 2024-08-29 11:51:08 +07:00
parent 860884c688
commit 224c83fe82
4 changed files with 85 additions and 6 deletions

View file

@ -1,6 +1,8 @@
{ ... }:
{
imports = [
./telemetry
./caddy.nix
./cockpit.nix
./forgejo.nix
@ -15,6 +17,5 @@
./syncthing.nix
./wireguard.nix
./photoprism.nix
./telemetry.nix
];
}

View file

@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./grafana.nix
./loki.nix
];
}

View file

@ -1,6 +1,6 @@
{ config, lib, pkgs, ... }:
let
cfg = config.profile.services.telemetry;
cfg = config.profile.services.telemetry.grafana;
inherit (lib) mkIf;
grafanaDomain = "grafana.tigor.web.id";
in
@ -8,20 +8,23 @@ in
config = mkIf cfg.enable {
sops.secrets =
let
opts = { sopsFile = ../../secrets/telemetry.yaml; owner = "grafana"; };
opts = {
sopsFile = ../../../secrets/telemetry.yaml;
owner = "grafana";
};
in
mkIf cfg.grafana.enable {
{
"grafana/admin_user" = opts;
"grafana/admin_password" = opts;
"grafana/admin_email" = opts;
"grafana/secret_key" = opts;
};
services.caddy.virtualHosts.${grafanaDomain}.extraConfig = mkIf cfg.grafana.enable ''
services.caddy.virtualHosts.${grafanaDomain}.extraConfig = ''
reverse_proxy ${config.services.grafana.settings.server.http_addr}:${toString config.services.grafana.settings.server.http_port}
'';
services.grafana = mkIf cfg.grafana.enable {
services.grafana = {
enable = true;
package = pkgs.grafana;
settings = {

View file

@ -0,0 +1,68 @@
{ config, lib, ... }:
let
cfg = config.profile.services.telemetry.loki;
inherit (lib) mkIf;
in
{
config = mkIf cfg.enable {
services.loki =
let
dataDir = config.services.loki.dataDir;
in
{
enable = true;
configuration = {
# https://grafana.com/docs/loki/latest/configure/examples/configuration-examples/
auth_enabled = false; # Loki will not be exposed to the public internet
server = {
http_listen_address = "0.0.0.0";
http_listen_port = 3100;
grpc_listen_port = 9095;
};
common = {
path_prefix = dataDir;
replication_factor = 1;
ring = {
instance_addr = "127.0.0.1";
kvstore.store = "inmemory";
};
};
schema_config = {
configs = [
{
from = "2024-08-29";
store = "tsdb";
object_store = "filesystem";
schema = "v13";
index = {
prefix = "index_";
period = "24h";
};
}
];
};
storage_config = {
filesystem = {
directory = "${dataDir}/chunks";
};
};
};
};
# https://grafana.com/docs/grafana/latest/datasources/loki/
services.grafana.provision.datasources.settings.datasources = [
{
name = "Loki";
type = "loki";
access = "proxy";
url = "http://${config.services.loki.configuration.server.http_listen_address}:${toString config.services.loki.configuration.server.http_listen_port}";
jsonData = {
timeout = 60;
maxLines = 1000;
};
}
];
};
}