summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/longview.nix
blob: b55f43b437bc506493613d9e6bfd5232efceff85 (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
66
67
68
69
70
71
72
73
74
75
76
77
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.longview;

  pidFile = "/run/longview.pid";

  apacheConf =  ''
    #location http://127.0.0.1/server-status?auto
  '';
  mysqlConf = ''
    #username root
    #password example_password
  '';
  nginxConf = ''
    #location http://127.0.0.1/nginx_status
  '';

in

{
  options = {

    services.longview = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          If enabled, system metrics will be sent to Linode LongView.
        '';
      };

      apiKey = mkOption {
        type = types.str;
        description = ''
          Longview API key. To get this, look in Longview settings which
          are found at https://manager.linode.com/longview/.
        '';
      };

    };

  };

  config = mkIf cfg.enable {
    systemd.services.longview =
      { description = "Longview Metrics Collection";
        after = [ "network.target" ];
        wantedBy = [ "multi-user.target" ];
        serviceConfig.Type = "forking";
        serviceConfig.ExecStop = "-${pkgs.coreutils}/bin/kill -TERM $MAINPID";
        serviceConfig.ExecReload = "-${pkgs.coreutils}/bin/kill -HUP $MAINPID";
        serviceConfig.PIDFile = pidFile;
        serviceConfig.ExecStart = "${pkgs.longview}/bin/longview";
      };

    environment.etc."linode/longview.key" = {
      mode = "0400";
      text = cfg.apiKey;
    };
    environment.etc."linode/longview.d/Apache.conf" = {
      mode = "0400";
      text = apacheConf;
    };
    environment.etc."linode/longview.d/MySQL.conf" = {
      mode = "0400";
      text = mysqlConf;
    };
    environment.etc."linode/longview.d/Nginx.conf" = {
      mode = "0400";
      text = nginxConf;
    };
  };
}