nixos: add graphite api to graphite functionality

This commit is contained in:
Jaka Hudoklin 2014-09-11 13:39:48 +02:00
parent dbae0b628e
commit 19ea435cf8
2 changed files with 86 additions and 20 deletions

View File

@ -8,6 +8,16 @@ let
dataDir = cfg.dataDir;
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}
'';
configDir = pkgs.buildEnv {
name = "graphite-config";
paths = lists.filter (el: el != null) [
@ -65,6 +75,40 @@ in {
};
};
api = {
enable = mkOption {
description = "Whether to enable graphite api.";
default = false;
type = types.uniq types.bool;
};
finders = mkOption {
description = "List of finder plugins load.";
default = [];
example = [ pkgs.python27Packages.graphite_influxdb ];
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;
};
extraConfig = mkOption {
description = "Extra configuration for graphite api.";
default = ''
whisper:
directories:
- ${dataDir}/whisper
'';
type = types.str;
};
};
carbon = {
config = mkOption {
description = "Content of carbon configuration file.";
@ -176,7 +220,7 @@ in {
###### implementation
config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable) {
config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable || cfg.api.enable) {
systemd.services.carbonCache = {
enable = cfg.carbon.enableCache;
description = "Graphite Data Storage Backend";
@ -189,10 +233,6 @@ in {
Group = "graphite";
PermissionsStartOnly = true;
};
restartTriggers = [
pkgs.pythonPackages.carbon
configDir
];
preStart = ''
mkdir -p ${cfg.dataDir}/whisper
chmod 0700 ${cfg.dataDir}/whisper
@ -211,10 +251,6 @@ in {
User = "graphite";
Group = "graphite";
};
restartTriggers = [
pkgs.pythonPackages.carbon
configDir
];
};
systemd.services.carbonRelay = {
@ -228,10 +264,6 @@ in {
User = "graphite";
Group = "graphite";
};
restartTriggers = [
pkgs.pythonPackages.carbon
configDir
];
};
systemd.services.graphiteWeb = {
@ -243,7 +275,7 @@ in {
environment = {
PYTHONPATH = "${pkgs.python27Packages.graphite_web}/lib/python2.7/site-packages";
DJANGO_SETTINGS_MODULE = "graphite.settings";
GRAPHITE_CONF_DIR = "/etc/graphite/";
GRAPHITE_CONF_DIR = configDir;
GRAPHITE_STORAGE_DIR = dataDir;
};
serviceConfig = {
@ -271,9 +303,40 @@ in {
chown -R graphite:graphite ${cfg.dataDir}
fi
'';
restartTriggers = [
pkgs.python27Packages.graphite_web
];
};
systemd.services.graphiteApi = {
enable = cfg.api.enable;
description = "Graphite Api Interface";
wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ];
environment = {
PYTHONPATH =
"${pkgs.python27Packages.graphite_api}/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 \
--host=${cfg.web.host} --port=${toString cfg.web.port} \
graphite_api.app:app
'';
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
'';
};
environment.systemPackages = [

View File

@ -10372,9 +10372,10 @@ rec {
graphite_api = buildPythonPackage rec {
name = "graphite-api-1.0.1";
src = fetchurl {
url = "https://pypi.python.org/packages/source/g/graphite-api/${name}.tar.gz";
md5 = "466c13a902744bed09a054da452140f0";
src = fetchgit {
url = "https://github.com/brutasse/graphite-api.git";
rev = "b6f75e8a08fae695c094fece6de611b893fc65fb";
sha256 = "41b90d5f35e99a020a6b1b77938690652521d1841b3165574fcfcee807ce4e6a";
};
# ImportError: No module named tests
@ -10410,6 +10411,8 @@ rec {
propagatedBuildInputs = [ influxdb graphite_api ];
passthru.moduleName = "graphite_influxdb.InfluxdbFinder";
meta = {
description = "An influxdb backend for Graphite-web and graphite-api";
homepage = https://github.com/vimeo/graphite-influxdb;