about summary refs log tree commit diff
path: root/modules/services/monitoring/promtail.nix
blob: 85d34dc4c7c61250d3dc901e98b568c3680854bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ config, lib, pkgs, ... }:
let
  cfg = config.my.services.monitoring.promtail;
in
{
  options.my.services.monitoring.promtail = with lib; {
    enable = mkEnableOption "promtail logs exporter";
  };

  config = lib.mkIf cfg.enable {
    services.promtail = {
      enable = true;
      configuration = {
        clients = [{ url = "http://192.168.6.40:3100/loki/api/v1/push"; }];
        scrape_configs = [
          {
            job_name = "journal";
            journal = {
              json = true;
              path = "/var/log/journal";
              max_age = "12h";
              labels = {
                host = config.networking.hostName;
                job = "journal";
                "__path__" = "/var/log/journal";
              };
            };

            relabel_configs = [
              {
                source_labels = [ "__journal__systemd_unit" ];
                target_label = "unit";
              }
              {
                source_labels = [ "__journal_priority" ];
                target_label = "priority";
              }
              {
                source_labels = [ "__journal_syslog_identifier" ];
                target_label = "syslog_id";
              }
            ];
          }

          {
            job_name = "nginx";
            static_configs = [{
              labels = {
                host = config.networking.hostName;
                job = "nginx";
                __path__ = "/var/log/nginx/*";
              };
            }];
          }
        ];

        server = {
          http_listen_port = 9832;
          http_path_prefix = "/promtail";
          grpc_listen_port = 0;
        };
      };
    };
  };
}