2021-12-05 20:28:49 +00:00
|
|
|
{ config, lib, options, pkgs, ... }:
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-08-11 10:16:19 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.graphite;
|
2021-12-05 20:28:49 +00:00
|
|
|
opt = options.services.graphite;
|
2017-04-17 20:48:10 +00:00
|
|
|
writeTextOrNull = f: t: mapNullable (pkgs.writeTextDir f) t;
|
2014-03-10 09:57:51 +00:00
|
|
|
|
|
|
|
dataDir = cfg.dataDir;
|
2017-09-30 19:12:24 +00:00
|
|
|
staticDir = cfg.dataDir + "/static";
|
|
|
|
|
2018-11-08 10:59:03 +00:00
|
|
|
graphiteLocalSettingsDir = pkgs.runCommand "graphite_local_settings" {
|
|
|
|
inherit graphiteLocalSettings;
|
2019-08-08 20:48:27 +00:00
|
|
|
preferLocalBuild = true;
|
2018-11-08 10:59:03 +00:00
|
|
|
} ''
|
2017-09-30 19:12:24 +00:00
|
|
|
mkdir -p $out
|
|
|
|
ln -s $graphiteLocalSettings $out/graphite_local_settings.py
|
|
|
|
'';
|
|
|
|
|
|
|
|
graphiteLocalSettings = pkgs.writeText "graphite_local_settings.py" (
|
|
|
|
"STATIC_ROOT = '${staticDir}'\n" +
|
2019-04-24 03:48:22 +00:00
|
|
|
optionalString (config.time.timeZone != null) "TIME_ZONE = '${config.time.timeZone}'\n"
|
2017-09-30 19:12:24 +00:00
|
|
|
+ cfg.web.extraConfig
|
|
|
|
);
|
2014-03-10 09:57:51 +00:00
|
|
|
|
2014-09-17 16:31:02 +00:00
|
|
|
seyrenConfig = {
|
|
|
|
SEYREN_URL = cfg.seyren.seyrenUrl;
|
|
|
|
MONGO_URL = cfg.seyren.mongoUrl;
|
|
|
|
GRAPHITE_URL = cfg.seyren.graphiteUrl;
|
|
|
|
} // cfg.seyren.extraConfig;
|
|
|
|
|
2014-03-10 09:57:51 +00:00
|
|
|
configDir = pkgs.buildEnv {
|
|
|
|
name = "graphite-config";
|
|
|
|
paths = lists.filter (el: el != null) [
|
|
|
|
(writeTextOrNull "carbon.conf" cfg.carbon.config)
|
2014-06-07 21:40:58 +00:00
|
|
|
(writeTextOrNull "storage-aggregation.conf" cfg.carbon.storageAggregation)
|
2014-03-10 09:57:51 +00:00
|
|
|
(writeTextOrNull "storage-schemas.conf" cfg.carbon.storageSchemas)
|
|
|
|
(writeTextOrNull "blacklist.conf" cfg.carbon.blacklist)
|
|
|
|
(writeTextOrNull "whitelist.conf" cfg.carbon.whitelist)
|
|
|
|
(writeTextOrNull "rewrite-rules.conf" cfg.carbon.rewriteRules)
|
|
|
|
(writeTextOrNull "relay-rules.conf" cfg.carbon.relayRules)
|
|
|
|
(writeTextOrNull "aggregation-rules.conf" cfg.carbon.aggregationRules)
|
|
|
|
];
|
|
|
|
};
|
2013-10-13 21:10:29 +00:00
|
|
|
|
|
|
|
carbonOpts = name: with config.ids; ''
|
2015-11-28 11:18:33 +00:00
|
|
|
--nodaemon --syslog --prefix=${name} --pidfile /run/${name}/${name}.pid ${name}
|
2013-10-13 21:10:29 +00:00
|
|
|
'';
|
2015-11-28 11:18:33 +00:00
|
|
|
|
2013-10-13 21:10:29 +00:00
|
|
|
carbonEnv = {
|
2016-03-12 00:53:15 +00:00
|
|
|
PYTHONPATH = let
|
2020-03-20 16:02:58 +00:00
|
|
|
cenv = pkgs.python3.buildEnv.override {
|
|
|
|
extraLibs = [ pkgs.python3Packages.carbon ];
|
2016-03-12 00:53:15 +00:00
|
|
|
};
|
2020-03-20 16:02:58 +00:00
|
|
|
in "${cenv}/${pkgs.python3.sitePackages}";
|
2013-10-13 21:10:29 +00:00
|
|
|
GRAPHITE_ROOT = dataDir;
|
2014-03-10 09:57:51 +00:00
|
|
|
GRAPHITE_CONF_DIR = configDir;
|
2013-11-07 10:29:18 +00:00
|
|
|
GRAPHITE_STORAGE_DIR = dataDir;
|
2013-10-13 21:10:29 +00:00
|
|
|
};
|
|
|
|
|
2013-08-11 10:16:19 +00:00
|
|
|
in {
|
|
|
|
|
2020-03-20 16:02:58 +00:00
|
|
|
imports = [
|
2022-07-10 09:03:35 +00:00
|
|
|
(mkRemovedOptionModule ["services" "graphite" "api"] "")
|
2022-07-09 07:07:48 +00:00
|
|
|
(mkRemovedOptionModule ["services" "graphite" "beacon"] "")
|
2020-03-20 16:02:58 +00:00
|
|
|
(mkRemovedOptionModule ["services" "graphite" "pager"] "")
|
|
|
|
];
|
|
|
|
|
2013-08-11 10:16:19 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.graphite = {
|
2014-03-10 09:57:51 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/db/graphite";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2014-03-10 09:57:51 +00:00
|
|
|
Data directory for graphite.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
web = {
|
|
|
|
enable = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable graphite web frontend.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2015-12-23 23:20:39 +00:00
|
|
|
listenAddress = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Graphite web frontend listen address.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = "127.0.0.1";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
port = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Graphite web frontend port.";
|
2014-03-10 09:57:51 +00:00
|
|
|
default = 8080;
|
2022-11-30 16:15:00 +00:00
|
|
|
type = types.port;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2017-09-30 19:12:24 +00:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2017-09-30 19:12:24 +00:00
|
|
|
Graphite webapp settings. See:
|
2022-07-28 21:19:15 +00:00
|
|
|
<http://graphite.readthedocs.io/en/latest/config-local-settings.html>
|
2017-09-30 19:12:24 +00:00
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
};
|
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
carbon = {
|
|
|
|
config = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Content of carbon configuration file.";
|
2013-10-11 09:44:26 +00:00
|
|
|
default = ''
|
|
|
|
[cache]
|
|
|
|
# Listen on localhost by default for security reasons
|
|
|
|
UDP_RECEIVER_INTERFACE = 127.0.0.1
|
|
|
|
PICKLE_RECEIVER_INTERFACE = 127.0.0.1
|
|
|
|
LINE_RECEIVER_INTERFACE = 127.0.0.1
|
|
|
|
CACHE_QUERY_INTERFACE = 127.0.0.1
|
2013-10-28 16:09:53 +00:00
|
|
|
# Do not log every update
|
|
|
|
LOG_UPDATES = False
|
|
|
|
LOG_CACHE_HITS = False
|
2013-10-11 09:44:26 +00:00
|
|
|
'';
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
enableCache = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable carbon cache, the graphite storage daemon.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
storageAggregation = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Defines how to aggregate data to lower-precision retentions.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = null;
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
example = ''
|
|
|
|
[all_min]
|
|
|
|
pattern = \.min$
|
|
|
|
xFilesFactor = 0.1
|
2013-10-13 21:10:29 +00:00
|
|
|
aggregationMethod = min
|
2013-08-19 02:14:53 +00:00
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
storageSchemas = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Defines retention rates for storing metrics.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = "";
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
example = ''
|
|
|
|
[apache_busyWorkers]
|
|
|
|
pattern = ^servers\.www.*\.workers\.busyWorkers$
|
|
|
|
retentions = 15s:7d,1m:21d,15m:5y
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
blacklist = mkOption {
|
2022-12-18 00:31:14 +00:00
|
|
|
description = lib.mdDoc "Any metrics received which match one of the expressions will be dropped.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = null;
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2019-09-17 00:19:28 +00:00
|
|
|
example = "^some\\.noisy\\.metric\\.prefix\\..*";
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
whitelist = mkOption {
|
2022-12-18 00:31:14 +00:00
|
|
|
description = lib.mdDoc "Only metrics received which match one of the expressions will be persisted.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = null;
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
example = ".*";
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
rewriteRules = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2014-06-09 09:26:22 +00:00
|
|
|
Regular expression patterns that can be used to rewrite metric names
|
|
|
|
in a search and replace fashion.
|
|
|
|
'';
|
2013-08-19 02:14:53 +00:00
|
|
|
default = null;
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
example = ''
|
|
|
|
[post]
|
|
|
|
_sum$ =
|
|
|
|
_avg$ =
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
enableRelay = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable carbon relay, the carbon replication and sharding service.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
relayRules = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Relay rules are used to send certain metrics to a certain backend.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = null;
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
example = ''
|
|
|
|
[example]
|
|
|
|
pattern = ^mydata\.foo\..+
|
|
|
|
servers = 10.1.2.3, 10.1.2.4:2004, myserver.mydomain.com
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
enableAggregator = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable carbon aggregator, the carbon buffering service.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
aggregationRules = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Defines if and how received metrics will be aggregated.";
|
2013-08-19 02:14:53 +00:00
|
|
|
default = null;
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.nullOr types.str;
|
2013-08-19 02:14:53 +00:00
|
|
|
example = ''
|
|
|
|
<env>.applications.<app>.all.requests (60) = sum <env>.applications.<app>.*.requests
|
|
|
|
<env>.applications.<app>.all.latency (60) = avg <env>.applications.<app>.*.latency
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2014-09-17 16:31:02 +00:00
|
|
|
|
|
|
|
seyren = {
|
|
|
|
enable = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Whether to enable seyren service.";
|
2014-09-17 16:31:02 +00:00
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2014-09-17 16:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Seyren listening port.";
|
2014-09-17 16:31:02 +00:00
|
|
|
default = 8081;
|
2022-11-30 16:15:00 +00:00
|
|
|
type = types.port;
|
2014-09-17 16:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
seyrenUrl = mkOption {
|
|
|
|
default = "http://localhost:${toString cfg.seyren.port}/";
|
2021-12-05 20:28:49 +00:00
|
|
|
defaultText = literalExpression ''"http://localhost:''${toString config.${opt.seyren.port}}/"'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Host where seyren is accessible.";
|
2014-09-17 16:31:02 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
graphiteUrl = mkOption {
|
2015-12-23 23:20:39 +00:00
|
|
|
default = "http://${cfg.web.listenAddress}:${toString cfg.web.port}";
|
2021-12-05 20:28:49 +00:00
|
|
|
defaultText = literalExpression ''"http://''${config.${opt.web.listenAddress}}:''${toString config.${opt.web.port}}"'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Host where graphite service runs.";
|
2014-09-17 16:31:02 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
mongoUrl = mkOption {
|
|
|
|
default = "mongodb://${config.services.mongodb.bind_ip}:27017/seyren";
|
2021-11-26 00:16:05 +00:00
|
|
|
defaultText = literalExpression ''"mongodb://''${config.services.mongodb.bind_ip}:27017/seyren"'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Mongodb connection string.";
|
2014-09-17 16:31:02 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = {};
|
2022-08-03 20:46:41 +00:00
|
|
|
description = lib.mdDoc ''
|
2014-09-17 16:31:02 +00:00
|
|
|
Extra seyren configuration. See
|
2022-08-03 20:46:41 +00:00
|
|
|
<https://github.com/scobal/seyren#config>
|
2014-09-17 16:31:02 +00:00
|
|
|
'';
|
|
|
|
type = types.attrsOf types.str;
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression ''
|
2014-09-17 16:31:02 +00:00
|
|
|
{
|
|
|
|
GRAPHITE_USERNAME = "user";
|
2014-11-02 11:40:00 +00:00
|
|
|
GRAPHITE_PASSWORD = "pass";
|
2014-09-17 16:31:02 +00:00
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
###### implementation
|
2014-04-17 13:40:02 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
config = mkMerge [
|
|
|
|
(mkIf cfg.carbon.enableCache {
|
2015-11-28 11:18:33 +00:00
|
|
|
systemd.services.carbonCache = let name = "carbon-cache"; in {
|
2014-10-20 11:27:21 +00:00
|
|
|
description = "Graphite Data Storage Backend";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:16 +00:00
|
|
|
after = [ "network.target" ];
|
2014-10-20 11:27:21 +00:00
|
|
|
environment = carbonEnv;
|
|
|
|
serviceConfig = {
|
2018-08-04 18:55:59 +00:00
|
|
|
RuntimeDirectory = name;
|
2020-03-20 16:02:58 +00:00
|
|
|
ExecStart = "${pkgs.python3Packages.twisted}/bin/twistd ${carbonOpts name}";
|
2014-10-20 11:27:21 +00:00
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
|
|
|
PermissionsStartOnly = true;
|
2015-11-28 11:18:33 +00:00
|
|
|
PIDFile="/run/${name}/${name}.pid";
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
2018-08-04 18:55:59 +00:00
|
|
|
preStart = ''
|
|
|
|
install -dm0700 -o graphite -g graphite ${cfg.dataDir}
|
|
|
|
install -dm0700 -o graphite -g graphite ${cfg.dataDir}/whisper
|
2014-09-11 11:39:48 +00:00
|
|
|
'';
|
|
|
|
};
|
2014-10-20 11:27:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.carbon.enableAggregator {
|
2015-11-28 11:18:33 +00:00
|
|
|
systemd.services.carbonAggregator = let name = "carbon-aggregator"; in {
|
2014-10-20 11:27:21 +00:00
|
|
|
enable = cfg.carbon.enableAggregator;
|
|
|
|
description = "Carbon Data Aggregator";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:16 +00:00
|
|
|
after = [ "network.target" ];
|
2014-10-20 11:27:21 +00:00
|
|
|
environment = carbonEnv;
|
|
|
|
serviceConfig = {
|
2018-08-04 18:55:59 +00:00
|
|
|
RuntimeDirectory = name;
|
2020-03-20 16:02:58 +00:00
|
|
|
ExecStart = "${pkgs.python3Packages.twisted}/bin/twistd ${carbonOpts name}";
|
2014-10-20 11:27:21 +00:00
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
2015-11-28 11:18:33 +00:00
|
|
|
PIDFile="/run/${name}/${name}.pid";
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.carbon.enableRelay {
|
2015-11-28 11:18:33 +00:00
|
|
|
systemd.services.carbonRelay = let name = "carbon-relay"; in {
|
2014-10-20 11:27:21 +00:00
|
|
|
description = "Carbon Data Relay";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:16 +00:00
|
|
|
after = [ "network.target" ];
|
2014-10-20 11:27:21 +00:00
|
|
|
environment = carbonEnv;
|
|
|
|
serviceConfig = {
|
2018-08-04 18:55:59 +00:00
|
|
|
RuntimeDirectory = name;
|
2020-03-20 16:02:58 +00:00
|
|
|
ExecStart = "${pkgs.python3Packages.twisted}/bin/twistd ${carbonOpts name}";
|
2014-10-20 11:27:21 +00:00
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
2015-11-28 11:18:33 +00:00
|
|
|
PIDFile="/run/${name}/${name}.pid";
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.carbon.enableCache || cfg.carbon.enableAggregator || cfg.carbon.enableRelay) {
|
|
|
|
environment.systemPackages = [
|
2020-03-20 16:02:58 +00:00
|
|
|
pkgs.python3Packages.carbon
|
2014-10-20 11:27:21 +00:00
|
|
|
];
|
|
|
|
})
|
|
|
|
|
2020-03-20 16:02:58 +00:00
|
|
|
(mkIf cfg.web.enable ({
|
2014-10-20 11:27:21 +00:00
|
|
|
systemd.services.graphiteWeb = {
|
|
|
|
description = "Graphite Web Interface";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:16 +00:00
|
|
|
after = [ "network.target" ];
|
2014-10-20 11:27:21 +00:00
|
|
|
path = [ pkgs.perl ];
|
|
|
|
environment = {
|
2016-03-12 00:53:15 +00:00
|
|
|
PYTHONPATH = let
|
2020-03-20 16:02:58 +00:00
|
|
|
penv = pkgs.python3.buildEnv.override {
|
2016-03-12 00:53:15 +00:00
|
|
|
extraLibs = [
|
2020-03-20 16:02:58 +00:00
|
|
|
pkgs.python3Packages.graphite-web
|
2016-03-12 00:53:15 +00:00
|
|
|
];
|
|
|
|
};
|
2020-03-20 16:02:58 +00:00
|
|
|
penvPack = "${penv}/${pkgs.python3.sitePackages}";
|
2017-09-30 19:12:24 +00:00
|
|
|
in concatStringsSep ":" [
|
|
|
|
"${graphiteLocalSettingsDir}"
|
|
|
|
"${penvPack}"
|
|
|
|
# explicitly adding pycairo in path because it cannot be imported via buildEnv
|
2020-03-20 16:02:58 +00:00
|
|
|
"${pkgs.python3Packages.pycairo}/${pkgs.python3.sitePackages}"
|
2017-09-30 19:12:24 +00:00
|
|
|
];
|
2014-10-20 11:27:21 +00:00
|
|
|
DJANGO_SETTINGS_MODULE = "graphite.settings";
|
2020-03-20 16:02:58 +00:00
|
|
|
GRAPHITE_SETTINGS_MODULE = "graphite_local_settings";
|
2014-10-20 11:27:21 +00:00
|
|
|
GRAPHITE_CONF_DIR = configDir;
|
|
|
|
GRAPHITE_STORAGE_DIR = dataDir;
|
2016-04-16 16:46:23 +00:00
|
|
|
LD_LIBRARY_PATH = "${pkgs.cairo.out}/lib";
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
2020-03-20 16:02:58 +00:00
|
|
|
${pkgs.python3Packages.waitress-django}/bin/waitress-serve-django \
|
2017-09-30 19:12:24 +00:00
|
|
|
--host=${cfg.web.listenAddress} --port=${toString cfg.web.port}
|
|
|
|
'';
|
2014-10-20 11:27:21 +00:00
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
if ! test -e ${dataDir}/db-created; then
|
|
|
|
mkdir -p ${dataDir}/{whisper/,log/webapp/}
|
|
|
|
chmod 0700 ${dataDir}/{whisper/,log/webapp/}
|
|
|
|
|
2020-03-20 16:02:58 +00:00
|
|
|
${pkgs.python3Packages.django}/bin/django-admin.py migrate --noinput
|
2014-10-20 11:27:21 +00:00
|
|
|
|
2017-09-30 19:12:24 +00:00
|
|
|
chown -R graphite:graphite ${dataDir}
|
2014-10-20 11:27:21 +00:00
|
|
|
|
2017-04-27 15:33:42 +00:00
|
|
|
touch ${dataDir}/db-created
|
2014-10-20 11:27:21 +00:00
|
|
|
fi
|
2017-09-30 19:12:24 +00:00
|
|
|
|
|
|
|
# Only collect static files when graphite_web changes.
|
2020-03-20 16:02:58 +00:00
|
|
|
if ! [ "${dataDir}/current_graphite_web" -ef "${pkgs.python3Packages.graphite-web}" ]; then
|
2017-09-30 19:12:24 +00:00
|
|
|
mkdir -p ${staticDir}
|
2020-03-20 16:02:58 +00:00
|
|
|
${pkgs.python3Packages.django}/bin/django-admin.py collectstatic --noinput --clear
|
2017-09-30 19:12:24 +00:00
|
|
|
chown -R graphite:graphite ${staticDir}
|
2020-03-20 16:02:58 +00:00
|
|
|
ln -sfT "${pkgs.python3Packages.graphite-web}" "${dataDir}/current_graphite_web"
|
2017-09-30 19:12:24 +00:00
|
|
|
fi
|
2014-10-20 11:27:21 +00:00
|
|
|
'';
|
|
|
|
};
|
2014-09-17 16:31:02 +00:00
|
|
|
|
2020-03-20 16:02:58 +00:00
|
|
|
environment.systemPackages = [ pkgs.python3Packages.graphite-web ];
|
2017-11-01 00:09:39 +00:00
|
|
|
}))
|
2014-10-20 11:27:21 +00:00
|
|
|
|
|
|
|
(mkIf cfg.seyren.enable {
|
|
|
|
systemd.services.seyren = {
|
|
|
|
description = "Graphite Alerting Dashboard";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:16 +00:00
|
|
|
after = [ "network.target" "mongodb.service" ];
|
2014-10-20 11:27:21 +00:00
|
|
|
environment = seyrenConfig;
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.seyren}/bin/seyren -httpPort ${toString cfg.seyren.port}";
|
|
|
|
WorkingDirectory = dataDir;
|
|
|
|
User = "graphite";
|
2014-11-02 11:40:00 +00:00
|
|
|
Group = "graphite";
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
if ! test -e ${dataDir}/db-created; then
|
|
|
|
mkdir -p ${dataDir}
|
2017-04-27 15:33:42 +00:00
|
|
|
chown graphite:graphite ${dataDir}
|
2014-10-20 11:27:21 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
services.mongodb.enable = mkDefault true;
|
|
|
|
})
|
|
|
|
|
2014-11-04 18:38:24 +00:00
|
|
|
(mkIf (
|
|
|
|
cfg.carbon.enableCache || cfg.carbon.enableAggregator || cfg.carbon.enableRelay ||
|
2022-07-10 09:03:35 +00:00
|
|
|
cfg.web.enable || cfg.seyren.enable
|
2014-11-04 18:38:24 +00:00
|
|
|
) {
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users.graphite = {
|
2014-11-04 18:38:24 +00:00
|
|
|
uid = config.ids.uids.graphite;
|
2021-08-08 12:00:00 +00:00
|
|
|
group = "graphite";
|
2014-11-04 18:38:24 +00:00
|
|
|
description = "Graphite daemon user";
|
|
|
|
home = dataDir;
|
|
|
|
};
|
2018-06-29 23:58:35 +00:00
|
|
|
users.groups.graphite.gid = config.ids.gids.graphite;
|
2014-11-04 18:38:24 +00:00
|
|
|
})
|
2014-10-20 11:27:21 +00:00
|
|
|
];
|
2013-08-11 10:16:19 +00:00
|
|
|
}
|