nixos/graphite: add seyren service, graphite alerting dashboard

+83 -1
+83 -1
nixos/modules/services/monitoring/graphite.nix
··· 18 18 ${cfg.api.extraConfig} 19 19 ''; 20 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 + 21 27 configDir = pkgs.buildEnv { 22 28 name = "graphite-config"; 23 29 paths = lists.filter (el: el != null) [ ··· 242 248 ''; 243 249 }; 244 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 + }; 245 298 }; 246 299 247 300 ###### implementation 248 301 249 - config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable || cfg.api.enable) { 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 + ) { 250 310 systemd.services.carbonCache = { 251 311 enable = cfg.carbon.enableCache; 252 312 description = "Graphite Data Storage Backend"; ··· 364 424 fi 365 425 ''; 366 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; 367 449 368 450 environment.systemPackages = [ 369 451 pkgs.pythonPackages.carbon