nixos/graphite: add seyren service, graphite alerting dashboard

+83 -1
+83 -1
nixos/modules/services/monitoring/graphite.nix
··· 18 ${cfg.api.extraConfig} 19 ''; 20 21 configDir = pkgs.buildEnv { 22 name = "graphite-config"; 23 paths = lists.filter (el: el != null) [ ··· 242 ''; 243 }; 244 }; 245 }; 246 247 ###### implementation 248 249 - config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable || cfg.api.enable) { 250 systemd.services.carbonCache = { 251 enable = cfg.carbon.enableCache; 252 description = "Graphite Data Storage Backend"; ··· 364 fi 365 ''; 366 }; 367 368 environment.systemPackages = [ 369 pkgs.pythonPackages.carbon
··· 18 ${cfg.api.extraConfig} 19 ''; 20 21 + seyrenConfig = { 22 + SEYREN_URL = cfg.seyren.seyrenUrl; 23 + MONGO_URL = cfg.seyren.mongoUrl; 24 + GRAPHITE_URL = cfg.seyren.graphiteUrl; 25 + } // cfg.seyren.extraConfig; 26 + 27 configDir = pkgs.buildEnv { 28 name = "graphite-config"; 29 paths = lists.filter (el: el != null) [ ··· 248 ''; 249 }; 250 }; 251 + 252 + seyren = { 253 + enable = mkOption { 254 + description = "Whether to enable seyren service."; 255 + default = false; 256 + type = types.uniq types.bool; 257 + }; 258 + 259 + port = mkOption { 260 + description = "Seyren listening port."; 261 + default = 8081; 262 + type = types.int; 263 + }; 264 + 265 + seyrenUrl = mkOption { 266 + default = "http://localhost:${toString cfg.seyren.port}/"; 267 + description = "Host where seyren is accessible."; 268 + type = types.str; 269 + }; 270 + 271 + graphiteUrl = mkOption { 272 + default = "http://${cfg.web.host}:${toString cfg.web.port}"; 273 + description = "Host where graphite service runs."; 274 + type = types.str; 275 + }; 276 + 277 + mongoUrl = mkOption { 278 + default = "mongodb://${config.services.mongodb.bind_ip}:27017/seyren"; 279 + description = "Mongodb connection string."; 280 + type = types.str; 281 + }; 282 + 283 + extraConfig = mkOption { 284 + default = {}; 285 + description = '' 286 + Extra seyren configuration. See 287 + <link xlink:href='https://github.com/scobal/seyren#config' /> 288 + ''; 289 + type = types.attrsOf types.str; 290 + example = literalExample '' 291 + { 292 + GRAPHITE_USERNAME = "user"; 293 + GRAPHITE_PASSWORD = "pass"; 294 + } 295 + ''; 296 + }; 297 + }; 298 }; 299 300 ###### implementation 301 302 + config = mkIf ( 303 + cfg.carbon.enableAggregator || 304 + cfg.carbon.enableCache || 305 + cfg.carbon.enableRelay || 306 + cfg.web.enable || 307 + cfg.api.enable || 308 + cfg.seyren.enable 309 + ) { 310 systemd.services.carbonCache = { 311 enable = cfg.carbon.enableCache; 312 description = "Graphite Data Storage Backend"; ··· 424 fi 425 ''; 426 }; 427 + 428 + systemd.services.seyren = { 429 + enable = cfg.seyren.enable; 430 + description = "Graphite Alerting Dashboard"; 431 + wantedBy = [ "multi-user.target" ]; 432 + after = [ "network-interfaces.target" "mongodb.service" ]; 433 + environment = seyrenConfig; 434 + serviceConfig = { 435 + ExecStart = "${pkgs.seyren}/bin/seyren -httpPort ${toString cfg.seyren.port}"; 436 + WorkingDirectory = dataDir; 437 + User = "graphite"; 438 + Group = "graphite"; 439 + }; 440 + preStart = '' 441 + if ! test -e ${dataDir}/db-created; then 442 + mkdir -p ${dataDir} 443 + chown -R graphite:graphite ${dataDir} 444 + fi 445 + ''; 446 + }; 447 + 448 + services.mongodb.enable = mkDefault cfg.seyren.enable; 449 450 environment.systemPackages = [ 451 pkgs.pythonPackages.carbon