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;
|
2014-03-10 09:57:51 +00:00
|
|
|
writeTextOrNull = f: t: if t == null then null else pkgs.writeTextDir f t;
|
|
|
|
|
|
|
|
dataDir = cfg.dataDir;
|
|
|
|
|
2014-09-11 11:39:48 +00:00
|
|
|
graphiteApiConfig = pkgs.writeText "graphite-api.yaml" ''
|
|
|
|
time_zone: ${config.time.timeZone}
|
|
|
|
search_index: ${dataDir}/index
|
|
|
|
${optionalString (cfg.api.finders != []) ''finders:''}
|
|
|
|
${concatMapStringsSep "\n" (f: " - " + f.moduleName) cfg.api.finders}
|
|
|
|
${optionalString (cfg.api.functions != []) ''functions:''}
|
|
|
|
${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-10-20 11:27:21 +00:00
|
|
|
pagerConfig = pkgs.writeText "alarms.yaml" cfg.pager.alerts;
|
|
|
|
|
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
|
|
|
|
|
|
|
mkPidFileDir = name: ''
|
|
|
|
mkdir -p /run/${name}
|
|
|
|
chmod 0700 /run/${name}
|
|
|
|
chown -R graphite:graphite /run/${name}
|
|
|
|
'';
|
|
|
|
|
2013-10-13 21:10:29 +00:00
|
|
|
carbonEnv = {
|
|
|
|
PYTHONPATH = "${pkgs.python27Packages.carbon}/lib/python2.7/site-packages";
|
|
|
|
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 {
|
|
|
|
|
|
|
|
###### 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
|
|
|
};
|
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
|
2014-10-20 11:32:58 +00:00
|
|
|
<link xlink:href="http://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 = [];
|
2016-01-17 18:34:55 +00:00
|
|
|
example = literalExample "[ pkgs.python27Packages.graphite_influxdb ]";
|
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.";
|
|
|
|
default = pkgs.python27Packages.graphite_api;
|
2016-01-17 18:34:55 +00:00
|
|
|
defaultText = "pkgs.python27Packages.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'
|
|
|
|
'';
|
2014-09-11 11:39:48 +00:00
|
|
|
type = types.str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
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 = "";
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
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;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
example = "^some\.noisy\.metric\.prefix\..*";
|
|
|
|
};
|
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;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
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;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
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;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
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;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
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;
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
pager = {
|
|
|
|
enable = mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to enable graphite-pager service. For more information visit
|
|
|
|
<link xlink:href="https://github.com/seatgeek/graphite-pager"/>
|
|
|
|
'';
|
|
|
|
default = false;
|
2015-06-15 16:10:26 +00:00
|
|
|
type = types.bool;
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
redisUrl = mkOption {
|
|
|
|
description = "Redis connection string.";
|
|
|
|
default = "redis://localhost:${toString config.services.redis.port}/";
|
|
|
|
type = types.str;
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
graphiteUrl = mkOption {
|
|
|
|
description = "URL to your graphite service.";
|
2015-12-23 23:20:39 +00:00
|
|
|
default = "http://${cfg.web.listenAddress}:${toString cfg.web.port}";
|
2014-10-20 11:27:21 +00:00
|
|
|
type = types.str;
|
2014-03-10 09:57:51 +00:00
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
alerts = mkOption {
|
|
|
|
description = "Alerts configuration for graphite-pager.";
|
|
|
|
default = ''
|
|
|
|
alerts:
|
|
|
|
- target: constantLine(100)
|
|
|
|
warning: 90
|
|
|
|
critical: 200
|
|
|
|
name: Test
|
|
|
|
'';
|
2016-01-17 18:34:55 +00:00
|
|
|
example = ''
|
2014-11-02 11:40:00 +00:00
|
|
|
pushbullet_key: pushbullet_api_key
|
2014-10-20 11:27:21 +00:00
|
|
|
alerts:
|
|
|
|
- target: stats.seatgeek.app.deal_quality.venue_info_cache.hit
|
|
|
|
warning: .5
|
|
|
|
critical: 1
|
|
|
|
name: Deal quality venue cache hits
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
2014-03-10 09:57:51 +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" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
environment = carbonEnv;
|
|
|
|
serviceConfig = {
|
2015-11-28 11:18:33 +00:00
|
|
|
ExecStart = "${pkgs.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
|
|
|
};
|
2015-11-28 11:18:33 +00:00
|
|
|
preStart = mkPidFileDir name + ''
|
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
mkdir -p ${cfg.dataDir}/whisper
|
|
|
|
chmod 0700 ${cfg.dataDir}/whisper
|
2014-04-17 13:40:02 +00:00
|
|
|
chown -R graphite:graphite ${cfg.dataDir}
|
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" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
environment = carbonEnv;
|
|
|
|
serviceConfig = {
|
2015-11-28 11:18:33 +00:00
|
|
|
ExecStart = "${pkgs.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
|
|
|
};
|
2015-11-28 11:18:33 +00:00
|
|
|
preStart = mkPidFileDir name;
|
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" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
environment = carbonEnv;
|
|
|
|
serviceConfig = {
|
2015-11-28 11:18:33 +00:00
|
|
|
ExecStart = "${pkgs.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
|
|
|
};
|
2015-11-28 11:18:33 +00:00
|
|
|
preStart = mkPidFileDir name;
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.carbon.enableCache || cfg.carbon.enableAggregator || cfg.carbon.enableRelay) {
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.pythonPackages.carbon
|
|
|
|
];
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.web.enable {
|
|
|
|
systemd.services.graphiteWeb = {
|
|
|
|
description = "Graphite Web Interface";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
path = [ pkgs.perl ];
|
|
|
|
environment = {
|
|
|
|
PYTHONPATH = "${pkgs.python27Packages.graphite_web}/lib/python2.7/site-packages";
|
|
|
|
DJANGO_SETTINGS_MODULE = "graphite.settings";
|
|
|
|
GRAPHITE_CONF_DIR = configDir;
|
|
|
|
GRAPHITE_STORAGE_DIR = dataDir;
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.python27Packages.waitress}/bin/waitress-serve \
|
2015-12-23 23:20:39 +00:00
|
|
|
--host=${cfg.web.listenAddress} --port=${toString cfg.web.port} \
|
2014-10-20 11:27:21 +00:00
|
|
|
--call django.core.handlers.wsgi:WSGIHandler'';
|
|
|
|
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/}
|
|
|
|
|
|
|
|
# populate database
|
|
|
|
${pkgs.python27Packages.graphite_web}/bin/manage-graphite.py syncdb --noinput
|
|
|
|
|
|
|
|
# create index
|
|
|
|
${pkgs.python27Packages.graphite_web}/bin/build-index.sh
|
|
|
|
|
|
|
|
touch ${dataDir}/db-created
|
|
|
|
|
|
|
|
chown -R graphite:graphite ${cfg.dataDir}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2014-09-17 16:31:02 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
environment.systemPackages = [ pkgs.python27Packages.graphite_web ];
|
|
|
|
})
|
|
|
|
|
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" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
|
|
|
environment = {
|
|
|
|
PYTHONPATH =
|
|
|
|
"${cfg.api.package}/lib/python2.7/site-packages:" +
|
|
|
|
concatMapStringsSep ":" (f: f + "/lib/python2.7/site-packages") cfg.api.finders;
|
|
|
|
GRAPHITE_API_CONFIG = graphiteApiConfig;
|
|
|
|
LD_LIBRARY_PATH = "${pkgs.cairo}/lib";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.python27Packages.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/
|
|
|
|
|
|
|
|
touch ${dataDir}/db-created
|
|
|
|
|
|
|
|
chown -R graphite:graphite ${cfg.dataDir}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.seyren.enable {
|
|
|
|
systemd.services.seyren = {
|
|
|
|
description = "Graphite Alerting Dashboard";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" "mongodb.service" ];
|
|
|
|
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}
|
|
|
|
chown -R graphite:graphite ${dataDir}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 10:16:19 +00:00
|
|
|
|
2014-10-20 11:27:21 +00:00
|
|
|
services.mongodb.enable = mkDefault true;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf cfg.pager.enable {
|
|
|
|
systemd.services.graphitePager = {
|
|
|
|
description = "Graphite Pager Alerting Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" "redis.service" ];
|
|
|
|
environment = {
|
|
|
|
REDIS_URL = cfg.pager.redisUrl;
|
|
|
|
GRAPHITE_URL = cfg.pager.graphiteUrl;
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.pythonPackages.graphite_pager}/bin/graphite-pager --config ${pagerConfig}";
|
|
|
|
User = "graphite";
|
2014-11-02 11:40:00 +00:00
|
|
|
Group = "graphite";
|
2014-10-20 11:27:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.redis.enable = mkDefault true;
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.pythonPackages.graphite_pager ];
|
|
|
|
})
|
|
|
|
|
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 = ''
|
|
|
|
${pkgs.pythonPackages.graphite_beacon}/bin/graphite-beacon \
|
|
|
|
--config ${pkgs.writeText "graphite-beacon.json" (builtins.toJSON cfg.beacon.config)}
|
|
|
|
'';
|
|
|
|
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 ||
|
2015-04-25 13:13:38 +00:00
|
|
|
cfg.seyren.enable || cfg.pager.enable || cfg.beacon.enable
|
2014-11-04 18:38:24 +00:00
|
|
|
) {
|
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = "graphite";
|
|
|
|
uid = config.ids.uids.graphite;
|
|
|
|
description = "Graphite daemon user";
|
|
|
|
home = dataDir;
|
|
|
|
};
|
|
|
|
users.extraGroups.graphite.gid = config.ids.gids.graphite;
|
|
|
|
})
|
2014-10-20 11:27:21 +00:00
|
|
|
];
|
2013-08-11 10:16:19 +00:00
|
|
|
}
|