summaryrefslogtreecommitdiffstats
path: root/makefu/2configs/elchos/stats.nix
blob: feb8c5bae46150ec8ef630629cc01fe3001f1d2a (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ config, lib, pkgs, ... }:

# requires nsupdate to get correct hostname (from ./search.nix)
# graphite-web on port 8080
# carbon cache on port 2003 (tcp/udp)

with import <stockholm/lib>;
{

  services.nginx = {
    enable = mkDefault true;
    virtualHosts = {
      "stats.nsupdate.info" = {
        enableACME = true;
        forceSSL = true;

        locations = {
          "/"  = {
            proxyPass  = "http://localhost:3000/";
            extraConfig = ''
              proxy_set_header   Host             $host;
              proxy_set_header   X-Real-IP        $remote_addr;
              proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            '';
          };
        };
      };
    };
  };

  services.grafana = {
    enable = true;
    addr = "127.0.0.1";
    users.allowSignUp = false;
    users.allowOrgCreate = false;
    users.autoAssignOrg = false;
    auth.anonymous.enable = true;
    security = import <secrets/grafana_security.nix>; # { AdminUser = ""; adminPassword = ""}
  };

  services.graphite = {
    beacon = {
      enable = true;
      config = {
        graphite_url = "http://localhost:18080";

        no_data = "critical";
        loading_error = "normal";

        prefix = "[elchos]";

        cli = {
          command = ''${pkgs.irc-announce}/bin/irc-announce irc.freenode.org 6667 alert0r \#elchos ' [elchos] ''${level} ''${name} ''${value}' '';
        };
        #smtp = {
        #  from = "beacon@mors.r";
        #  to = [
        #    "lass@mors.r"
        #  ];
        #};
        normal_handlers = [
          # "smtp"
          "cli"
        ];
        warning_handlers = [
          # "smtp"
          "cli"
        ];
        critical_handlers = [
          # "smtp"
          "cli"
        ];
        alerts = let
          high-load = hostid: let
              host = "elch-${toString hostid}"; in {
              name = "high-cpu-load-${host}";
              query = "aliasByNode(perSecond(elchos.${host}.cpu.0.cpu.idle),1)";
              method = "average";
              interval = "1minute";
              logging = "info";
              repeat_interval = "5minute";
              rules = [
  #              "warning: < 30.0"
                "critical: < 1.0"
              ];
            };
          in map high-load [ 1 2 3 4 5 6 7 8 ];
      };
   };
   api = {
      enable = true;
      package = pkgs.graphiteApi;
      listenAddress = "127.0.0.1";
      port = 18080;
    };
    carbon = {
      enableCache = true;
      # save disk usage by restricting to 1 bulk update per second
      config = ''
        [cache]
        MAX_CACHE_SIZE = inf
        MAX_UPDATES_PER_SECOND = 10
        MAX_CREATES_PER_MINUTE = 5000
        '';
      storageSchemas = ''
        [carbon]
        pattern = ^carbon\.
        retentions = 60:90d

        [elchos]
        patterhn = ^elchos\.
        retentions = 10s:30d,60s:3y


        [default]
        pattern = ^krebs\.
        retentions = 1s:30d,30s:3m,300s:1y
        [default]
        pattern = .*
        retentions = 30s:30d,300s:1y
        '';
    };
  };

  networking.firewall = {
    allowedTCPPorts = [ 2003 80 443 ];
    allowedUDPPorts = [ 2003 ];
  };
}