2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, 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;
|
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-11 11:39:48 +00:00
|
|
|
graphiteApiConfig = pkgs.writeText "graphite-api.yaml" ''
|
|
|
|
search_index: ${dataDir}/index
|
2021-01-24 09:19:10 +00:00
|
|
|
${optionalString (config.time.timeZone != null) "time_zone: ${config.time.timeZone}"}
|
|
|
|
${optionalString (cfg.api.finders != []) "finders:"}
|
2014-09-11 11:39:48 +00:00
|
|
|
${concatMapStringsSep "\n" (f: " - " + f.moduleName) cfg.api.finders}
|
2021-01-24 09:19:10 +00:00
|
|
|
${optionalString (cfg.api.functions != []) "functions:"}
|
2014-09-11 11:39:48 +00:00
|
|
|
${concatMapStringsSep "\n" (f: " - " + f) cfg.api.functions}
|
|
|
|
${cfg.api.extraConfig}
|
|
|
|
'';
|
|
|
|
|
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 = [
|
|
|
|
(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";
|
|
|
|
description = ''
|
|
|
|
Data directory for graphite.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
web = {
|
|
|
|
enable = mkOption {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "Graphite web frontend port.";
|
2014-03-10 09:57:51 +00:00
|
|
|
default = 8080;
|
|
|
|
type = types.int;
|
2013-08-19 02:14:53 +00:00
|
|
|
};
|
2017-09-30 19:12:24 +00:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Graphite webapp settings. See:
|
|
|
|
<link xlink:href="http://graphite.readthedocs.io/en/latest/config-local-settings.html"/>
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
};
|
|
|
|
|
2014-09-11 11:39:48 +00:00
|
|
|
api = {
|
|
|
|
enable = mkOption {
|
2014-10-20 11:27:21 +00:00
|
|
|
description = ''
|
|
|
|
Whether to enable graphite api. Graphite api is lightweight alternative
|
|
|
|
to graphite web, with api and without dashboard. It's advised to use
|
|
|
|
grafana as alternative dashboard and influxdb as alternative to
|
|
|
|
graphite carbon.
|
|
|
|
|
|
|
|
For more information visit
|
2019-04-22 08:24:21 +00:00
|
|
|
<link xlink:href="https://graphite-api.readthedocs.org/en/latest/"/>
|
2014-10-20 11:27:21 +00:00
|
|
|
'';
|
2014-09-11 11:39:48 +00:00
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2014-09-11 11:39:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
finders = mkOption {
|
2014-10-20 11:27:21 +00:00
|
|
|
description = "List of finder plugins to load.";
|
2014-09-11 11:39:48 +00:00
|
|
|
default = [];
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression "[ pkgs.python3Packages.influxgraph ]";
|
2014-09-11 11:39:48 +00:00
|
|
|
type = types.listOf types.package;
|
|
|
|
};
|
|
|
|
|
|
|
|
functions = mkOption {
|
|
|
|
description = "List of functions to load.";
|
|
|
|
default = [
|
|
|
|
"graphite_api.functions.SeriesFunctions"
|
|
|
|
"graphite_api.functions.PieFunctions"
|
|
|
|
];
|
|
|
|
type = types.listOf types.str;
|
|
|
|
};
|
|
|
|
|
2015-12-23 23:20:39 +00:00
|
|
|
listenAddress = mkOption {
|
2014-09-15 09:38:39 +00:00
|
|
|
description = "Graphite web service listen address.";
|
|
|
|
default = "127.0.0.1";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Graphite api service port.";
|
|
|
|
default = 8080;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
2014-09-17 16:32:51 +00:00
|
|
|
package = mkOption {
|
|
|
|
description = "Package to use for graphite api.";
|
2020-03-20 16:02:58 +00:00
|
|
|
default = pkgs.python3Packages.graphite_api;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.python3Packages.graphite_api";
|
2014-09-17 16:32:51 +00:00
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
|
2014-09-11 11:39:48 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
description = "Extra configuration for graphite api.";
|
|
|
|
default = ''
|
|
|
|
whisper:
|
|
|
|
directories:
|
|
|
|
- ${dataDir}/whisper
|
|
|
|
'';
|
2016-01-17 18:34:55 +00:00
|
|
|
example = ''
|
2014-09-16 08:41:27 +00:00
|
|
|
allowed_origins:
|
|
|
|
- dashboard.example.com
|
|
|
|
cheat_times: true
|
|
|
|
influxdb:
|
|
|
|
host: localhost
|
|
|
|
port: 8086
|
|
|
|
user: influxdb
|
|
|
|
pass: influxdb
|
|
|
|
db: metrics
|
|
|
|
cache:
|
|
|
|
CACHE_TYPE: 'filesystem'
|
|
|
|
CACHE_DIR: '/tmp/graphite-api-cache'
|
|
|
|
'';
|
2016-10-23 17:33:41 +00:00
|
|
|
type = types.lines;
|
2014-09-11 11:39:48 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-08-19 02:14:53 +00:00
|
|
|
carbon = {
|
|
|
|
config = mkOption {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "Any metrics received which match one of the experssions 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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "Only metrics received which match one of the experssions 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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = ''
|
|
|
|
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 {
|
2014-06-09 09:26:22 +00:00
|
|
|
description = "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 {
|
|
|
|
description = "Relay rules are used to send certain metrics to a certain backend.";
|
|
|
|
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 {
|
2016-01-04 23:54:03 +00:00
|
|
|
description = "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 {
|
2016-01-04 23:54:03 +00:00
|
|
|
description = "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 {
|
|
|
|
description = "Whether to enable seyren service.";
|
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2014-09-17 16:31:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
description = "Seyren listening port.";
|
|
|
|
default = 8081;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
seyrenUrl = mkOption {
|
|
|
|
default = "http://localhost:${toString cfg.seyren.port}/";
|
|
|
|
description = "Host where seyren is accessible.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
graphiteUrl = mkOption {
|
2015-12-23 23:20:39 +00:00
|
|
|
default = "http://${cfg.web.listenAddress}:${toString cfg.web.port}";
|
2014-09-17 16:31:02 +00:00
|
|
|
description = "Host where graphite service runs.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
mongoUrl = mkOption {
|
|
|
|
default = "mongodb://${config.services.mongodb.bind_ip}:27017/seyren";
|
|
|
|
description = "Mongodb connection string.";
|
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Extra seyren configuration. See
|
|
|
|
<link xlink:href='https://github.com/scobal/seyren#config' />
|
|
|
|
'';
|
|
|
|
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
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2015-04-25 13:13:38 +00:00
|
|
|
beacon = {
|
2015-06-21 15:19:46 +00:00
|
|
|
enable = mkEnableOption "graphite beacon";
|
2015-04-25 13:13:38 +00:00
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
description = "Graphite beacon configuration.";
|
|
|
|
default = {};
|
|
|
|
type = types.attrs;
|
|
|
|
};
|
|
|
|
};
|
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
|
|
|
|
2014-11-02 11:40:00 +00:00
|
|
|
(mkIf cfg.api.enable {
|
2014-10-20 11:27:21 +00:00
|
|
|
systemd.services.graphiteApi = {
|
|
|
|
description = "Graphite Api Interface";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 18:13:16 +00:00
|
|
|
after = [ "network.target" ];
|
2014-10-20 11:27:21 +00:00
|
|
|
environment = {
|
2016-03-12 00:53:15 +00:00
|
|
|
PYTHONPATH = let
|
2020-03-20 16:02:58 +00:00
|
|
|
aenv = pkgs.python3.buildEnv.override {
|
|
|
|
extraLibs = [ cfg.api.package pkgs.cairo pkgs.python3Packages.cffi ] ++ cfg.api.finders;
|
2016-03-12 00:53:15 +00:00
|
|
|
};
|
2020-03-20 16:02:58 +00:00
|
|
|
in "${aenv}/${pkgs.python3.sitePackages}";
|
2014-10-20 11:27:21 +00:00
|
|
|
GRAPHITE_API_CONFIG = graphiteApiConfig;
|
2016-01-24 07:29:01 +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}/bin/waitress-serve \
|
2015-12-23 23:20:39 +00:00
|
|
|
--host=${cfg.api.listenAddress} --port=${toString cfg.api.port} \
|
2014-11-02 11:40:00 +00:00
|
|
|
graphite_api.app:app
|
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}/cache/
|
|
|
|
chmod 0700 ${dataDir}/cache/
|
|
|
|
|
2017-04-27 15:33:42 +00:00
|
|
|
chown graphite:graphite ${cfg.dataDir}
|
|
|
|
chown -R graphite:graphite ${cfg.dataDir}/cache
|
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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(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;
|
|
|
|
})
|
|
|
|
|
2015-04-25 13:13:38 +00:00
|
|
|
(mkIf cfg.beacon.enable {
|
|
|
|
systemd.services.graphite-beacon = {
|
|
|
|
description = "Grpahite Beacon Alerting Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
2020-03-20 16:02:58 +00:00
|
|
|
${pkgs.python3Packages.graphite_beacon}/bin/graphite-beacon \
|
2016-12-27 16:26:56 +00:00
|
|
|
--config=${pkgs.writeText "graphite-beacon.json" (builtins.toJSON cfg.beacon.config)}
|
2015-04-25 13:13:38 +00:00
|
|
|
'';
|
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2014-11-04 18:38:24 +00:00
|
|
|
(mkIf (
|
|
|
|
cfg.carbon.enableCache || cfg.carbon.enableAggregator || cfg.carbon.enableRelay ||
|
|
|
|
cfg.web.enable || cfg.api.enable ||
|
2020-03-20 16:02:58 +00:00
|
|
|
cfg.seyren.enable || cfg.beacon.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
|
|
|
}
|