graphite: Refactor options, serve with waitress

This commit is contained in:
Jaka Hudoklin 2013-08-19 04:14:53 +02:00
parent b244a47185
commit 4628fd8434

View File

@ -13,130 +13,145 @@ in {
###### interface ###### interface
options.services.graphite = { options.services.graphite = {
carbon = mkOption { web = {
description = "Content of carbon configuration file"; enable = mkOption {
default = ""; description = "Whether to enable graphite web frontend";
type = types.uniq types.string; default = false;
type = types.uniq types.bool;
};
host = mkOption {
description = "Graphite web frontend listen address";
default = "127.0.0.1";
types = type.uniq types.string;
};
port = mkOption {
description = "Graphite web frontend port";
default = "8080";
types = type.uniq types.string;
};
}; };
enableCarbonCache = mkOption { carbon = {
description = "Whether to enable carbon cache, the graphite storage daemon"; config = mkOption {
default = false; description = "Content of carbon configuration file";
type = types.uniq types.bool; default = "";
}; type = types.uniq types.string;
};
storageAggregation = mkOption { enableCache = mkOption {
description = "Defines how to aggregate data to lower-precision retentions"; description = "Whether to enable carbon cache, the graphite storage daemon";
default = null; default = false;
type = types.uniq (types.nullOr types.string); type = types.uniq types.bool;
example = '' };
[all_min]
pattern = \.min$
xFilesFactor = 0.1
aggregationMethod = min
'';
};
storageSchemas = mkOption { storageAggregation = mkOption {
description = "Defines retention rates for storing metrics"; description = "Defines how to aggregate data to lower-precision retentions";
default = ""; default = null;
type = types.uniq (types.nullOr types.string); type = types.uniq (types.nullOr types.string);
example = '' example = ''
[apache_busyWorkers] [all_min]
pattern = ^servers\.www.*\.workers\.busyWorkers$ pattern = \.min$
retentions = 15s:7d,1m:21d,15m:5y xFilesFactor = 0.1
''; aggregationMethod = min
}; '';
};
blacklist = mkOption { storageSchemas = mkOption {
description = "Any metrics received which match one of the experssions will be dropped"; description = "Defines retention rates for storing metrics";
default = null; default = "";
type = types.uniq (types.nullOr types.string); type = types.uniq (types.nullOr types.string);
example = "^some\.noisy\.metric\.prefix\..*"; example = ''
}; [apache_busyWorkers]
pattern = ^servers\.www.*\.workers\.busyWorkers$
retentions = 15s:7d,1m:21d,15m:5y
'';
};
whitelist = mkOption { blacklist = mkOption {
description = "Only metrics received which match one of the experssions will be persisted"; description = "Any metrics received which match one of the experssions will be dropped";
default = null; default = null;
type = types.uniq (types.nullOr types.string); type = types.uniq (types.nullOr types.string);
example = ".*"; example = "^some\.noisy\.metric\.prefix\..*";
}; };
rewriteRules = mkOption { whitelist = mkOption {
description = "Regular expression patterns that can be used to rewrite metric names in a search and replace fashion"; description = "Only metrics received which match one of the experssions will be persisted";
default = null; default = null;
type = types.uniq (types.nullOr types.string); type = types.uniq (types.nullOr types.string);
example = '' example = ".*";
[post] };
_sum$ =
_avg$ =
'';
};
enableCarbonRelay = mkOption { rewriteRules = mkOption {
description = "Whether to enable carbon relay, the carbon replication and sharding service"; description = "Regular expression patterns that can be used to rewrite metric names in a search and replace fashion";
default = false; default = null;
type = types.uniq types.bool; type = types.uniq (types.nullOr types.string);
}; example = ''
[post]
_sum$ =
_avg$ =
'';
};
relayRules = mkOption { enableRelay = mkOption {
description = "Relay rules are used to send certain metrics to a certain backend."; description = "Whether to enable carbon relay, the carbon replication and sharding service";
default = null; default = false;
type = types.uniq (types.nullOr types.string); type = types.uniq types.bool;
example = '' };
[example]
pattern = ^mydata\.foo\..+
servers = 10.1.2.3, 10.1.2.4:2004, myserver.mydomain.com
'';
};
enableCarbonAggregator = mkOption { relayRules = mkOption {
description = "Whether to enable carbon agregator, the carbon buffering service"; description = "Relay rules are used to send certain metrics to a certain backend.";
default = false; default = null;
type = types.uniq types.bool; 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
'';
};
aggregationRules = mkOption { enableAggregator = mkOption {
description = "Defines if and how received metrics will be agregated"; description = "Whether to enable carbon agregator, the carbon buffering service";
default = null; default = false;
type = types.uniq (types.nullOr types.string); type = types.uniq types.bool;
example = '' };
<env>.applications.<app>.all.requests (60) = sum <env>.applications.<app>.*.requests
<env>.applications.<app>.all.latency (60) = avg <env>.applications.<app>.*.latency
'';
};
enableGraphiteWeb = mkOption { aggregationRules = mkOption {
description = "Whether to enable graphite web frontend"; description = "Defines if and how received metrics will be agregated";
default = false; default = null;
type = types.uniq types.bool; 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
'';
};
}; };
}; };
###### implementation ###### implementation
config = mkIf (cfg.enableCarbonAggregator || cfg.enableCarbonCache || cfg.enableCarbonRelay || cfg.enableGraphiteWeb) { config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.cabon.enableRelay || cfg.web.enable) {
environment.etc = lists.filter (el: el.source != null) [ environment.etc = lists.filter (el: el.source != null) [
{ source = writeTextOrNull "carbon.conf" cfg.carbon; { source = writeTextOrNull "carbon.conf" cfg.carbon.config;
target = "graphite/carbon.conf"; } target = "graphite/carbon.conf"; }
{ source = writeTextOrNull "storage-agregation.conf" cfg.storageAggregation; { source = writeTextOrNull "storage-agregation.conf" cfg.carbon.storageAggregation;
target = "graphite/storage-agregation.conf"; } target = "graphite/storage-agregation.conf"; }
{ source = writeTextOrNull "storage-schemas.conf" cfg.storageSchemas; { source = writeTextOrNull "storage-schemas.conf" cfg.carbon.storageSchemas;
target = "graphite/storage-schemas.conf"; } target = "graphite/storage-schemas.conf"; }
{ source = writeTextOrNull "blacklist.conf" cfg.blacklist; { source = writeTextOrNull "blacklist.conf" cfg.carbon.blacklist;
target = "graphite/blacklist.conf"; } target = "graphite/blacklist.conf"; }
{ source = writeTextOrNull "whitelist.conf" cfg.whitelist; { source = writeTextOrNull "whitelist.conf" cfg.carbon.whitelist;
target = "graphite/whitelist.conf"; } target = "graphite/whitelist.conf"; }
{ source = writeTextOrNull "rewrite-rules.conf" cfg.rewriteRules; { source = writeTextOrNull "rewrite-rules.conf" cfg.carbon.rewriteRules;
target = "graphite/rewrite-rules.conf"; } target = "graphite/rewrite-rules.conf"; }
{ source = writeTextOrNull "relay-rules.conf" cfg.relayRules; { source = writeTextOrNull "relay-rules.conf" cfg.carbon.relayRules;
target = "graphite/relay-rules.conf"; } target = "graphite/relay-rules.conf"; }
{ source = writeTextOrNull "aggregation-rules.conf" cfg.aggregationRules; { source = writeTextOrNull "aggregation-rules.conf" cfg.carbon.aggregationRules;
target = "graphite/aggregation-rules.conf"; } target = "graphite/aggregation-rules.conf"; }
]; ];
systemd.services.carbonCache = mkIf cfg.enableCarbonCache { systemd.services.carbonCache = mkIf cfg.carbon.enableCache {
description = "Graphite data storage backend"; description = "Graphite data storage backend";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ]; after = [ "network-interfaces.target" ];
@ -150,15 +165,15 @@ in {
Group = "graphite"; Group = "graphite";
}; };
restartTriggers = [ restartTriggers = [
pkgs.pythonPackages.carbon cfg.carbon pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.storageAggregation
cfg.storageAggregation cfg.storageSchemas cfg.rewriteRules cfg.carbon.storageSchemas cfg.carbon.rewriteRules
]; ];
preStart = '' preStart = ''
mkdir -p ${dataDir}/whisper mkdir -p ${dataDir}/whisper
''; '';
}; };
systemd.services.carbonAggregator = mkIf cfg.enableCarbonAggregator { systemd.services.carbonAggregator = mkIf cfg.carbon.enableAggregator {
description = "Carbon data aggregator"; description = "Carbon data aggregator";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ]; after = [ "network-interfaces.target" ];
@ -171,10 +186,12 @@ in {
User = "graphite"; User = "graphite";
Group = "graphite"; Group = "graphite";
}; };
restartTriggers = [ pkgs.pythonPackages.carbon cfg.carbon cfg.aggregationRules ]; restartTriggers = [
pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.aggregationRules
];
}; };
systemd.services.carbonRelay = mkIf cfg.enableCarbonRelay { systemd.services.carbonRelay = mkIf cfg.carbon.enableRelay {
description = "Carbon data relay"; description = "Carbon data relay";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ]; after = [ "network-interfaces.target" ];
@ -187,19 +204,26 @@ in {
User = "graphite"; User = "graphite";
Group = "graphite"; Group = "graphite";
}; };
restartTriggers = [ pkgs.pythonPackages.carbon cfg.carbon cfg.relayRules ]; restartTriggers = [
pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.relayRules
];
}; };
systemd.services.graphiteWeb = mkIf cfg.enableGraphiteWeb { systemd.services.graphiteWeb = mkIf cfg.web.enable {
description = "Graphite web interface"; description = "Graphite web interface";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ]; after = [ "network-interfaces.target" ];
environment = { environment = {
PYTHONPATH = "${pkgs.python27Packages.graphite_web}/lib/python2.7/site-packages";
DJANGO_SETTINGS_MODULE = "graphite.settings";
GRAPHITE_CONF_DIR = "/etc/graphite/"; GRAPHITE_CONF_DIR = "/etc/graphite/";
GRAPHITE_STORAGE_DIR = "${dataDir}"; GRAPHITE_STORAGE_DIR = "${dataDir}";
}; };
serviceConfig = { serviceConfig = {
ExecStart = "${pkgs.pythonPackages.graphite_web}/bin/run-graphite-devel-server.py ${pkgs.pythonPackages.graphite_web}"; ExecStart = ''
${pkgs.python27Packages.waitress}/bin/waitress-serve \
--host=${cfg.web.host} --port=${cfg.web.port} \
--call django.core.handlers.wsgi:WSGIHandler'';
User = "graphite"; User = "graphite";
Group = "graphite"; Group = "graphite";
}; };
@ -208,19 +232,22 @@ in {
mkdir -p ${dataDir}/{whisper/,log/webapp/} mkdir -p ${dataDir}/{whisper/,log/webapp/}
# populate database # populate database
${pkgs.pythonPackages.graphite_web}/bin/manage-graphite.py syncdb --noinput ${pkgs.python27Packages.graphite_web}/bin/manage-graphite.py syncdb --noinput
# create index # create index
${pkgs.pythonPackages.graphite_web}/bin/build-index.sh ${pkgs.python27Packages.graphite_web}/bin/build-index.sh
touch ${dataDir}/db-created touch ${dataDir}/db-created
fi fi
''; '';
restartTriggers = [ pkgs.pythonPackages.graphite_web ]; restartTriggers = [
pkgs.python27Packages.graphite_web pkgs.python27Packages.waitress
];
}; };
environment.systemPackages = [ environment.systemPackages = [
pkgs.pythonPackages.carbon pkgs.pythonPackages.graphite_web pkgs.pythonPackages.django_1_3 pkgs.pythonPackages.carbon pkgs.python27Packages.graphite_web
pkgs.python27Packages.waitress
]; ];
users.extraUsers = singleton { users.extraUsers = singleton {