2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2013-08-11 12:16:19 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.graphite;
|
2014-03-10 10:57:51 +01:00
|
|
|
writeTextOrNull = f: t: if t == null then null else pkgs.writeTextDir f t;
|
|
|
|
|
|
|
|
dataDir = cfg.dataDir;
|
|
|
|
|
|
|
|
configDir = pkgs.buildEnv {
|
|
|
|
name = "graphite-config";
|
|
|
|
paths = lists.filter (el: el != null) [
|
|
|
|
(writeTextOrNull "carbon.conf" cfg.carbon.config)
|
2014-06-07 23:40:58 +02:00
|
|
|
(writeTextOrNull "storage-aggregation.conf" cfg.carbon.storageAggregation)
|
2014-03-10 10:57:51 +01: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 23:10:29 +02:00
|
|
|
|
|
|
|
carbonOpts = name: with config.ids; ''
|
2014-03-10 10:57:51 +01:00
|
|
|
--nodaemon --syslog --prefix=${name} --pidfile ${dataDir}/${name}.pid ${name}
|
2013-10-13 23:10:29 +02:00
|
|
|
'';
|
|
|
|
carbonEnv = {
|
|
|
|
PYTHONPATH = "${pkgs.python27Packages.carbon}/lib/python2.7/site-packages";
|
|
|
|
GRAPHITE_ROOT = dataDir;
|
2014-03-10 10:57:51 +01:00
|
|
|
GRAPHITE_CONF_DIR = configDir;
|
2013-11-07 11:29:18 +01:00
|
|
|
GRAPHITE_STORAGE_DIR = dataDir;
|
2013-10-13 23:10:29 +02:00
|
|
|
};
|
|
|
|
|
2013-08-11 12:16:19 +02:00
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.graphite = {
|
2014-03-10 10:57:51 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/db/graphite";
|
|
|
|
description = ''
|
|
|
|
Data directory for graphite.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
web = {
|
|
|
|
enable = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Whether to enable graphite web frontend.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
host = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Graphite web frontend listen address.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = "127.0.0.1";
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-19 04:14:53 +02:00
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
port = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Graphite web frontend port.";
|
2014-03-10 10:57:51 +01:00
|
|
|
default = 8080;
|
|
|
|
type = types.int;
|
2013-08-19 04:14:53 +02:00
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
carbon = {
|
|
|
|
config = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Content of carbon configuration file.";
|
2013-10-11 11:44:26 +02: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 17:09:53 +01:00
|
|
|
# Do not log every update
|
|
|
|
LOG_UPDATES = False
|
|
|
|
LOG_CACHE_HITS = False
|
2013-10-11 11:44:26 +02:00
|
|
|
'';
|
2013-10-30 11:02:04 +01:00
|
|
|
type = types.str;
|
2013-08-19 04:14:53 +02:00
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
enableCache = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Whether to enable carbon cache, the graphite storage daemon.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
storageAggregation = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Defines how to aggregate data to lower-precision retentions.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
example = ''
|
|
|
|
[all_min]
|
|
|
|
pattern = \.min$
|
|
|
|
xFilesFactor = 0.1
|
2013-10-13 23:10:29 +02:00
|
|
|
aggregationMethod = min
|
2013-08-19 04:14:53 +02:00
|
|
|
'';
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
storageSchemas = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Defines retention rates for storing metrics.";
|
2013-08-19 04:14:53 +02: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 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
blacklist = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Any metrics received which match one of the experssions will be dropped.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
example = "^some\.noisy\.metric\.prefix\..*";
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
whitelist = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Only metrics received which match one of the experssions will be persisted.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
example = ".*";
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
rewriteRules = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = ''
|
|
|
|
Regular expression patterns that can be used to rewrite metric names
|
|
|
|
in a search and replace fashion.
|
|
|
|
'';
|
2013-08-19 04:14:53 +02:00
|
|
|
default = null;
|
|
|
|
type = types.uniq (types.nullOr types.string);
|
|
|
|
example = ''
|
|
|
|
[post]
|
|
|
|
_sum$ =
|
|
|
|
_avg$ =
|
|
|
|
'';
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
enableRelay = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Whether to enable carbon relay, the carbon replication and sharding service.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02: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 12:16:19 +02:00
|
|
|
|
2013-08-19 04:14:53 +02:00
|
|
|
enableAggregator = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Whether to enable carbon agregator, the carbon buffering service.";
|
2013-08-19 04:14:53 +02:00
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
};
|
|
|
|
|
|
|
|
aggregationRules = mkOption {
|
2014-06-09 11:26:22 +02:00
|
|
|
description = "Defines if and how received metrics will be agregated.";
|
2013-08-19 04:14:53 +02: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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2013-08-19 10:21:31 +02:00
|
|
|
config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable) {
|
2014-03-10 10:57:51 +01:00
|
|
|
systemd.services.carbonCache = {
|
|
|
|
enable = cfg.carbon.enableCache;
|
2013-11-09 20:06:01 +01:00
|
|
|
description = "Graphite Data Storage Backend";
|
2013-08-11 12:16:19 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
2013-10-13 23:10:29 +02:00
|
|
|
environment = carbonEnv;
|
2014-03-10 10:57:51 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-cache"}";
|
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
2014-04-17 15:40:02 +02:00
|
|
|
PermissionsStartOnly = true;
|
2014-03-10 10:57:51 +01:00
|
|
|
};
|
2013-08-11 12:16:19 +02:00
|
|
|
restartTriggers = [
|
2013-10-03 16:20:48 +02:00
|
|
|
pkgs.pythonPackages.carbon
|
2014-06-09 11:29:05 +02:00
|
|
|
configDir
|
2013-08-11 12:16:19 +02:00
|
|
|
];
|
|
|
|
preStart = ''
|
2014-04-17 15:49:46 +02:00
|
|
|
mkdir -p ${cfg.dataDir}/whisper
|
|
|
|
chmod 0700 ${cfg.dataDir}/whisper
|
2014-04-17 15:40:02 +02:00
|
|
|
chown -R graphite:graphite ${cfg.dataDir}
|
2013-08-11 12:16:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-03-10 10:57:51 +01:00
|
|
|
systemd.services.carbonAggregator = {
|
|
|
|
enable = cfg.carbon.enableAggregator;
|
2013-11-09 20:06:01 +01:00
|
|
|
description = "Carbon Data Aggregator";
|
2013-08-11 12:16:19 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
2013-10-13 23:10:29 +02:00
|
|
|
environment = carbonEnv;
|
2014-03-10 10:57:51 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-aggregator"}";
|
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
|
|
|
};
|
2013-08-19 04:14:53 +02:00
|
|
|
restartTriggers = [
|
2014-06-09 11:29:05 +02:00
|
|
|
pkgs.pythonPackages.carbon
|
|
|
|
configDir
|
2013-08-19 04:14:53 +02:00
|
|
|
];
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
|
2014-03-10 10:57:51 +01:00
|
|
|
systemd.services.carbonRelay = {
|
|
|
|
enable = cfg.carbon.enableRelay;
|
2013-11-09 20:06:01 +01:00
|
|
|
description = "Carbon Data Relay";
|
2013-08-11 12:16:19 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
2013-10-13 23:10:29 +02:00
|
|
|
environment = carbonEnv;
|
2014-03-10 10:57:51 +01:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-relay"}";
|
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
|
|
|
};
|
2013-08-19 04:14:53 +02:00
|
|
|
restartTriggers = [
|
2014-06-09 11:29:05 +02:00
|
|
|
pkgs.pythonPackages.carbon
|
|
|
|
configDir
|
2013-08-19 04:14:53 +02:00
|
|
|
];
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
|
2014-03-10 10:57:51 +01:00
|
|
|
systemd.services.graphiteWeb = {
|
|
|
|
enable = cfg.web.enable;
|
2013-11-09 20:06:01 +01:00
|
|
|
description = "Graphite Web Interface";
|
2013-08-11 12:16:19 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-interfaces.target" ];
|
2014-04-17 15:40:02 +02:00
|
|
|
path = [ pkgs.perl ];
|
2013-08-11 12:16:19 +02:00
|
|
|
environment = {
|
2013-08-19 04:14:53 +02:00
|
|
|
PYTHONPATH = "${pkgs.python27Packages.graphite_web}/lib/python2.7/site-packages";
|
|
|
|
DJANGO_SETTINGS_MODULE = "graphite.settings";
|
2013-08-11 12:16:19 +02:00
|
|
|
GRAPHITE_CONF_DIR = "/etc/graphite/";
|
2013-10-13 23:10:29 +02:00
|
|
|
GRAPHITE_STORAGE_DIR = dataDir;
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
serviceConfig = {
|
2013-08-19 04:14:53 +02:00
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.python27Packages.waitress}/bin/waitress-serve \
|
2014-03-10 10:57:51 +01:00
|
|
|
--host=${cfg.web.host} --port=${toString cfg.web.port} \
|
2013-08-19 04:14:53 +02:00
|
|
|
--call django.core.handlers.wsgi:WSGIHandler'';
|
2013-08-11 12:16:19 +02:00
|
|
|
User = "graphite";
|
|
|
|
Group = "graphite";
|
2014-04-17 15:40:02 +02:00
|
|
|
PermissionsStartOnly = true;
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
if ! test -e ${dataDir}/db-created; then
|
2014-04-17 15:49:46 +02:00
|
|
|
mkdir -p ${dataDir}/{whisper/,log/webapp/}
|
|
|
|
chmod 0700 ${dataDir}/{whisper/,log/webapp/}
|
2013-08-11 12:16:19 +02:00
|
|
|
|
|
|
|
# populate database
|
2013-08-19 04:14:53 +02:00
|
|
|
${pkgs.python27Packages.graphite_web}/bin/manage-graphite.py syncdb --noinput
|
2013-08-11 12:16:19 +02:00
|
|
|
|
|
|
|
# create index
|
2013-08-19 04:14:53 +02:00
|
|
|
${pkgs.python27Packages.graphite_web}/bin/build-index.sh
|
2013-08-11 12:16:19 +02:00
|
|
|
|
|
|
|
touch ${dataDir}/db-created
|
2014-04-17 15:40:02 +02:00
|
|
|
|
|
|
|
chown -R graphite:graphite ${cfg.dataDir}
|
2013-08-11 12:16:19 +02:00
|
|
|
fi
|
|
|
|
'';
|
2013-08-19 04:14:53 +02:00
|
|
|
restartTriggers = [
|
2013-10-03 16:20:48 +02:00
|
|
|
pkgs.python27Packages.graphite_web
|
2013-08-19 04:14:53 +02:00
|
|
|
];
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [
|
2013-10-03 16:20:48 +02:00
|
|
|
pkgs.pythonPackages.carbon
|
|
|
|
pkgs.python27Packages.graphite_web
|
2013-08-19 04:14:53 +02:00
|
|
|
pkgs.python27Packages.waitress
|
2013-08-11 12:16:19 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
users.extraUsers = singleton {
|
|
|
|
name = "graphite";
|
|
|
|
uid = config.ids.uids.graphite;
|
|
|
|
description = "Graphite daemon user";
|
2013-10-13 23:10:29 +02:00
|
|
|
home = dataDir;
|
2013-08-11 12:16:19 +02:00
|
|
|
};
|
|
|
|
users.extraGroups.graphite.gid = config.ids.gids.graphite;
|
|
|
|
};
|
|
|
|
}
|