diff options
author | Luca Bruno <lethalman88@gmail.com> | 2015-11-25 21:31:09 +0100 |
---|---|---|
committer | Luca Bruno <lethalman88@gmail.com> | 2015-11-25 21:37:30 +0100 |
commit | a41292792498e03024d682d092947c2153290073 (patch) | |
tree | b937402b60ea79cfa0e5562dad3268127a491d81 /nixos/modules/services/monitoring | |
parent | 8a664fd5bc6b170bdf809030de6871fd6a454f5a (diff) | |
parent | b34a6c96ee14518b82648c5a8c1b29225c15d9df (diff) | |
download | nixlib-a41292792498e03024d682d092947c2153290073.tar nixlib-a41292792498e03024d682d092947c2153290073.tar.gz nixlib-a41292792498e03024d682d092947c2153290073.tar.bz2 nixlib-a41292792498e03024d682d092947c2153290073.tar.lz nixlib-a41292792498e03024d682d092947c2153290073.tar.xz nixlib-a41292792498e03024d682d092947c2153290073.tar.zst nixlib-a41292792498e03024d682d092947c2153290073.zip |
Merge remote-tracking branch 'origin/master' into closure-size
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r-- | nixos/modules/services/monitoring/bosun.nix | 28 | ||||
-rw-r--r-- | nixos/modules/services/monitoring/grafana.nix | 193 | ||||
-rw-r--r-- | nixos/modules/services/monitoring/heapster.nix | 57 | ||||
-rw-r--r-- | nixos/modules/services/monitoring/longview.nix | 118 |
4 files changed, 246 insertions, 150 deletions
diff --git a/nixos/modules/services/monitoring/bosun.nix b/nixos/modules/services/monitoring/bosun.nix index ebe4741f01bd..214a19d9483f 100644 --- a/nixos/modules/services/monitoring/bosun.nix +++ b/nixos/modules/services/monitoring/bosun.nix @@ -6,9 +6,11 @@ let cfg = config.services.bosun; configFile = pkgs.writeText "bosun.conf" '' - tsdbHost = ${cfg.opentsdbHost} + ${optionalString (cfg.opentsdbHost !=null) "tsdbHost = ${cfg.opentsdbHost}"} + ${optionalString (cfg.influxHost !=null) "influxHost = ${cfg.influxHost}"} httpListen = ${cfg.listenAddress} stateFile = ${cfg.stateFile} + ledisDir = ${cfg.ledisDir} checkFrequency = ${cfg.checkFrequency} ${cfg.extraConfig} @@ -54,10 +56,20 @@ in { }; opentsdbHost = mkOption { - type = types.string; + type = types.nullOr types.string; default = "localhost:4242"; description = '' Host and port of the OpenTSDB database that stores bosun data. + To disable opentsdb you can pass null as parameter. + ''; + }; + + influxHost = mkOption { + type = types.nullOr types.string; + default = null; + example = "localhost:8086"; + description = '' + Host and port of the influxdb database. ''; }; @@ -70,13 +82,21 @@ in { }; stateFile = mkOption { - type = types.string; + type = types.path; default = "/var/lib/bosun/bosun.state"; description = '' Path to bosun's state file. ''; }; + ledisDir = mkOption { + type = types.path; + default = "/var/lib/bosun/ledis_data"; + description = '' + Path to bosun's ledis data dir + ''; + }; + checkFrequency = mkOption { type = types.str; default = "5m"; @@ -103,7 +123,7 @@ in { }; config = mkIf cfg.enable { - + systemd.services.bosun = { description = "bosun metrics collector (part of Bosun)"; wantedBy = [ "multi-user.target" ]; diff --git a/nixos/modules/services/monitoring/grafana.nix b/nixos/modules/services/monitoring/grafana.nix index 5302728eae91..6053990e8d3b 100644 --- a/nixos/modules/services/monitoring/grafana.nix +++ b/nixos/modules/services/monitoring/grafana.nix @@ -7,150 +7,37 @@ let b2s = val: if val then "true" else "false"; - cfgFile = pkgs.writeText "grafana.ini" '' - app_name = grafana - app_mode = production - - [server] - ; protocol (http or https) - protocol = ${cfg.protocol} - ; the ip address to bind to, empty will bind to all interfaces - http_addr = ${cfg.addr} - ; the http port to use - http_port = ${toString cfg.port} - ; The public facing domain name used to access grafana from a browser - domain = ${cfg.domain} - ; the full public facing url - root_url = ${cfg.rootUrl} - router_logging = false - ; the path relative to the binary where the static (html/js/css) files are placed - static_root_path = ${cfg.staticRootPath} - ; enable gzip - enable_gzip = false - ; https certs & key file - cert_file = ${cfg.certFile} - cert_key = ${cfg.certKey} - - [analytics] - # Server reporting, sends usage counters to stats.grafana.org every 24 hours. - # No ip addresses are being tracked, only simple counters to track - # running instances, dashboard and error counts. It is very helpful to us. - # Change this option to false to disable reporting. - reporting_enabled = true - ; Google Analytics universal tracking code, only enabled if you specify an id here - google_analytics_ua_id = - - [database] - ; Either "mysql", "postgres" or "sqlite3", it's your choice - type = ${cfg.database.type} - host = ${cfg.database.host} - name = ${cfg.database.name} - user = ${cfg.database.user} - password = ${cfg.database.password} - ; For "postgres" only, either "disable", "require" or "verify-full" - ssl_mode = disable - ; For "sqlite3" only - path = ${cfg.database.path} - - [session] - ; Either "memory", "file", "redis", "mysql", default is "memory" - provider = file - ; Provider config options - ; memory: not have any config yet - ; file: session file path, e.g. `data/sessions` - ; redis: config like redis server addr, poolSize, password, e.g. `127.0.0.1:6379,100,grafana` - ; mysql: go-sql-driver/mysql dsn config string, e.g. `user:password@tcp(127.0.0.1)/database_name` - provider_config = data/sessions - ; Session cookie name - cookie_name = grafana_sess - ; If you use session in https only, default is false - cookie_secure = false - ; Session life time, default is 86400 - session_life_time = 86400 - ; session id hash func, Either "sha1", "sha256" or "md5" default is sha1 - session_id_hashfunc = sha1 - ; Session hash key, default is use random string - session_id_hashkey = - - [security] - ; default admin user, created on startup - admin_user = ${cfg.security.adminUser} - ; default admin password, can be changed before first start of grafana, or in profile settings - admin_password = ${cfg.security.adminPassword} - ; used for signing - secret_key = ${cfg.security.secretKey} - ; Auto-login remember days - login_remember_days = 7 - cookie_username = grafana_user - cookie_remember_name = grafana_remember - - [users] - ; disable user signup / registration - allow_sign_up = ${b2s cfg.users.allowSignUp} - ; Allow non admin users to create organizations - allow_org_create = ${b2s cfg.users.allowOrgCreate} - # Set to true to automatically assign new users to the default organization (id 1) - auto_assign_org = ${b2s cfg.users.autoAssignOrg} - ; Default role new users will be automatically assigned (if disabled above is set to true) - auto_assign_org_role = ${cfg.users.autoAssignOrgRole} - - [auth.anonymous] - ; enable anonymous access - enabled = ${b2s cfg.auth.anonymous.enable} - ; specify organization name that should be used for unauthenticated users - org_name = Main Org. - ; specify role for unauthenticated users - org_role = Viewer - - [auth.github] - enabled = false - client_id = some_id - client_secret = some_secret - scopes = user:email - auth_url = https://github.com/login/oauth/authorize - token_url = https://github.com/login/oauth/access_token - - [auth.google] - enabled = false - client_id = some_client_id - client_secret = some_client_secret - scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email - auth_url = https://accounts.google.com/o/oauth2/auth - token_url = https://accounts.google.com/o/oauth2/token - - [log] - root_path = data/log - ; Either "console", "file", default is "console" - ; Use comma to separate multiple modes, e.g. "console, file" - mode = console - ; Buffer length of channel, keep it as it is if you don't know what it is. - buffer_len = 10000 - ; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace" - level = Info - - ; For "console" mode only - [log.console] - level = - - ; For "file" mode only - [log.file] - level = - ; This enables automated log rotate(switch of following options), default is true - log_rotate = true - ; Max line number of single file, default is 1000000 - max_lines = 1000000 - ; Max size shift of single file, default is 28 means 1 << 28, 256MB - max_lines_shift = 28 - ; Segment log daily, default is true - daily_rotate = true - ; Expired days of log file(delete after max days), default is 7 - max_days = 7 - - [event_publisher] - enabled = false - rabbitmq_url = amqp://localhost/ - exchange = grafana_events - ''; + envOptions = { + PATHS_DATA = cfg.dataDir; + PATHS_LOGS = "${cfg.dataDir}/log"; + + SERVER_PROTOCOL = cfg.protocol; + SERVER_HTTP_ADDR = cfg.addr; + SERVER_HTTP_PORT = cfg.port; + SERVER_DOMAIN = cfg.domain; + SERVER_ROOT_URL = cfg.rootUrl; + SERVER_STATIC_ROOT_PATH = cfg.staticRootPath; + SERVER_CERT_FILE = cfg.certFile; + SERVER_CERT_KEY = cfg.certKey; + + DATABASE_TYPE = cfg.database.type; + DATABASE_HOST = cfg.database.host; + DATABASE_NAME = cfg.database.name; + DATABASE_USER = cfg.database.user; + DATABASE_PASSWORD = cfg.database.password; + DATABASE_PATH = cfg.database.path; + + SECURITY_ADMIN_USER = cfg.security.adminUser; + SECURITY_ADMIN_PASSWORD = cfg.security.adminPassword; + SECURITY_SECRET_KEY = cfg.security.secretKey; + + USERS_ALLOW_SIGN_UP = b2s cfg.users.allowSignUp; + USERS_ALLOW_ORG_CREATE = b2s cfg.users.allowOrgCreate; + USERS_AUTO_ASSIGN_ORG = b2s cfg.users.autoAssignOrg; + USERS_AUTO_ASSIGN_ORG_ROLE = cfg.users.autoAssignOrgRole; + + AUTH_ANONYMOUS_ENABLE = b2s cfg.auth.anonymous.enable; + } // cfg.extraOptions; in { options.services.grafana = { @@ -306,6 +193,16 @@ in { type = types.bool; }; }; + + extraOptions = mkOption { + description = '' + Extra configuration options passed as env variables as specified in + <link xlink:href="http://docs.grafana.org/installation/configuration/">documentation</link>, + but without GF_ prefix + ''; + default = {}; + type = types.attrsOf types.str; + }; }; config = mkIf cfg.enable { @@ -317,11 +214,15 @@ in { description = "Grafana Service Daemon"; wantedBy = ["multi-user.target"]; after = ["networking.target"]; + environment = mapAttrs' (n: v: nameValuePair "GF_${n}" (toString v)) envOptions; serviceConfig = { - ExecStart = "${cfg.package}/bin/grafana --config ${cfgFile} web"; + ExecStart = "${cfg.package}/bin/grafana -homepath ${cfg.dataDir}"; WorkingDirectory = cfg.dataDir; User = "grafana"; }; + preStart = '' + ln -fs ${cfg.package}/share/grafana/conf ${cfg.dataDir} + ''; }; users.extraUsers.grafana = { @@ -331,7 +232,7 @@ in { createHome = true; }; - services.grafana.staticRootPath = mkDefault "${cfg.package.out}/share/go/src/github.com/grafana/grafana/public"; + services.grafana.staticRootPath = mkDefault "${cfg.package}/share/grafana/public"; }; } diff --git a/nixos/modules/services/monitoring/heapster.nix b/nixos/modules/services/monitoring/heapster.nix new file mode 100644 index 000000000000..74b8c9ccd3ed --- /dev/null +++ b/nixos/modules/services/monitoring/heapster.nix @@ -0,0 +1,57 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.heapster; +in { + options.services.heapster = { + enable = mkOption { + description = "Whether to enable heapster monitoring"; + default = false; + type = types.bool; + }; + + source = mkOption { + description = "Heapster metric source"; + example = "kubernetes:https://kubernetes.default"; + type = types.string; + }; + + sink = mkOption { + description = "Heapster metic sink"; + example = "influxdb:http://localhost:8086"; + type = types.string; + }; + + extraOpts = mkOption { + description = "Heapster extra options"; + default = ""; + type = types.string; + }; + + package = mkOption { + description = "Package to use by heapster"; + default = pkgs.heapster; + type = types.package; + }; + }; + + config = mkIf cfg.enable { + systemd.services.heapster = { + wantedBy = ["multi-user.target"]; + after = ["cadvisor.service" "kube-apiserver.service"]; + + serviceConfig = { + ExecStart = "${cfg.package}/bin/heapster --source=${cfg.source} --sink=${cfg.sink} ${cfg.extraOpts}"; + User = "heapster"; + }; + }; + + users.extraUsers = singleton { + name = "heapster"; + uid = config.ids.uids.heapster; + description = "Heapster user"; + }; + }; +} diff --git a/nixos/modules/services/monitoring/longview.nix b/nixos/modules/services/monitoring/longview.nix new file mode 100644 index 000000000000..770d56e60efb --- /dev/null +++ b/nixos/modules/services/monitoring/longview.nix @@ -0,0 +1,118 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.longview; + + pidFile = "/run/longview.pid"; + + apacheConf = optionalString (cfg.apacheStatusUrl != "") '' + location ${cfg.apacheStatusUrl}?auto + ''; + mysqlConf = optionalString (cfg.mysqlUser != "") '' + username ${cfg.mysqlUser} + password ${cfg.mysqlPassword} + ''; + nginxConf = optionalString (cfg.nginxStatusUrl != "") '' + location ${cfg.nginxStatusUrl} + ''; + +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; + example = "01234567-89AB-CDEF-0123456789ABCDEF"; + description = '' + Longview API key. To get this, look in Longview settings which + are found at https://manager.linode.com/longview/. + ''; + }; + + apacheStatusUrl = mkOption { + type = types.str; + default = ""; + example = "http://127.0.0.1/server-status"; + description = '' + The Apache status page URL. If provided, Longview will + gather statistics from this location. This requires Apache + mod_status to be loaded and enabled. + ''; + }; + + nginxStatusUrl = mkOption { + type = types.str; + default = ""; + example = "http://127.0.0.1/nginx_status"; + description = '' + The Nginx status page URL. Longview will gather statistics + from this URL. This requires the Nginx stub_status module to + be enabled and configured at the given location. + ''; + }; + + mysqlUser = mkOption { + type = types.str; + default = ""; + description = '' + The user for connecting to the MySQL database. If provided, + Longview will connect to MySQL and collect statistics about + queries, etc. This user does not need to have been granted + any extra privileges. + ''; + }; + + mysqlPassword = mkOption { + type = types.str; + description = '' + The password corresponding to mysqlUser. Warning: this is + stored in cleartext in the Nix store! + ''; + }; + }; + + }; + + 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; + }; + }; +} |