Merge pull request #71406 from astro/collectd

collectd: plugins configuration, buildMinimalPackage
This commit is contained in:
Franz Pletz 2019-10-21 10:34:34 +00:00 committed by GitHub
commit cc9b18f223
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 392 additions and 57 deletions

View file

@ -16,13 +16,29 @@ let
NotifyLevel "OKAY"
</Plugin>
${concatStrings (mapAttrsToList (plugin: pluginConfig: ''
LoadPlugin ${plugin}
<Plugin "${plugin}">
${pluginConfig}
</Plugin>
'') cfg.plugins)}
${concatMapStrings (f: ''
Include "${f}"
Include "${f}"
'') cfg.include}
${cfg.extraConfig}
'';
package =
if cfg.buildMinimalPackage
then minimalPackage
else cfg.package;
minimalPackage = cfg.package.override {
enabledPlugins = [ "syslog" ] ++ builtins.attrNames cfg.plugins;
};
in {
options.services.collectd = with types; {
enable = mkEnableOption "collectd agent";
@ -33,7 +49,15 @@ in {
description = ''
Which collectd package to use.
'';
type = package;
type = types.package;
};
buildMinimalPackage = mkOption {
default = false;
description = ''
Build a minimal collectd package with only the configured `services.collectd.plugins`
'';
type = types.bool;
};
user = mkOption {
@ -68,6 +92,15 @@ in {
type = listOf str;
};
plugins = mkOption {
default = {};
example = { cpu = ""; memory = ""; network = "Server 192.168.1.1 25826"; };
description = ''
Attribute set of plugin names to plugin config segments
'';
type = types.attrsOf types.str;
};
extraConfig = mkOption {
default = "";
description = ''
@ -89,7 +122,7 @@ in {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${cfg.package}/sbin/collectd -C ${conf} -f";
ExecStart = "${package}/sbin/collectd -C ${conf} -f";
User = cfg.user;
Restart = "on-failure";
RestartSec = 3;

View file

@ -1,45 +1,12 @@
{ stdenv, fetchurl, fetchpatch, darwin
{ stdenv, fetchurl, fetchpatch, darwin, callPackage
, autoreconfHook
, pkgconfig
, curl
, iptables
, jdk
, libapparmor
, libatasmart
, libcap_ng
, libcredis
, libdbi
, libgcrypt
, libmemcached, cyrus_sasl
, libmicrohttpd
, libmodbus
, libnotify, gdk-pixbuf
, liboping
, libpcap
, libsigrok
, libvirt
, libxml2
, libtool
, lm_sensors
, lvm2
, libmysqlclient
, numactl
, postgresql
, protobufc
, python
, rabbitmq-c
, riemann_c_client
, rrdtool
, udev
, varnish
, yajl
, net_snmp
, hiredis
, libmnl
, mosquitto
, rdkafka
, mongoc
}:
, ...
}@args:
let
plugins = callPackage ./plugins.nix args;
in
stdenv.mkDerivation rec {
version = "5.8.1";
pname = "collectd";
@ -58,27 +25,15 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ pkgconfig autoreconfHook ];
buildInputs = [
curl libdbi libgcrypt libmemcached
cyrus_sasl libnotify gdk-pixbuf liboping libpcap libvirt
libxml2 postgresql protobufc rrdtool
varnish yajl jdk libtool python hiredis libmicrohttpd
riemann_c_client mosquitto rdkafka mongoc
] ++ stdenv.lib.optionals (libmysqlclient != null) [ libmysqlclient
] ++ stdenv.lib.optionals stdenv.isLinux [
iptables libatasmart libcredis libmodbus libsigrok
lm_sensors lvm2 rabbitmq-c udev net_snmp libmnl
# those might be no longer required when https://github.com/NixOS/nixpkgs/pull/51767
# is merged
libapparmor numactl libcap_ng
libtool
] ++ stdenv.lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.IOKit
darwin.apple_sdk.frameworks.ApplicationServices
];
] ++ plugins.buildInputs;
configureFlags = [
"--localstatedir=/var"
"--disable-werror"
];
] ++ plugins.configureFlags;
# do not create directories in /var during installPhase
postConfigure = ''

View file

@ -0,0 +1,347 @@
{ stdenv
, curl
, darwin
, hiredis
, iptables
, jdk
, libatasmart
, libdbi
, libgcrypt
, libmemcached, cyrus_sasl
, libmodbus
, libmicrohttpd
, libmnl
, libmysqlclient
, libnotify, gdk-pixbuf
, liboping
, libpcap
, libsigrok
, libvirt
, libxml2
, libapparmor, libcap_ng, numactl
, lvm2
, lua
, lm_sensors
, mongoc
, mosquitto
, net_snmp
, postgresql
, protobufc
, python
, rabbitmq-c
, rdkafka
, riemann_c_client
, rrdtool
, udev
, varnish
, yajl
# Defaults to `null` for all supported plugins,
# list of plugin names for a custom build
, enabledPlugins ? null
, ...
}:
let
# All plugins and their dependencies.
# Please help complete this!
plugins = {
aggregation = {};
amqp = {
buildInputs = [ yajl ] ++
stdenv.lib.optionals stdenv.isLinux [ rabbitmq-c ];
};
apache = {
buildInputs = [ curl ];
};
apcups = {};
apple_sensors = {};
aquaero = {};
ascent = {
buildInputs = [ curl libxml2 ];
};
barometer = {};
battery = {
buildInputs = stdenv.lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.IOKit
];
};
bind = {
buildInputs = [ curl libxml2 ];
};
ceph = {
buildInputs = [ yajl ];
};
cgroups = {};
chrony = {};
conntrack = {};
contextswitch = {};
cpu = {};
cpufreq = {};
cpusleep = {};
csv = {};
curl = {
buildInputs = [ curl ];
};
curl_json = {
buildInputs = [ curl yajl ];
};
curl_xml = {
buildInputs = [ curl libxml2 ];
};
dbi = {
buildInputs = [ libdbi ];
};
df = {};
disk = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [
udev
] ++ stdenv.lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.IOKit
];
};
dns = {
buildInputs = [ libpcap ];
};
dpdkevents = {};
dpdkstat = {};
drbd = {};
email = {};
entropy = {};
ethstat = {};
exec = {};
fhcount = {};
filecount = {};
fscache = {};
gmond = {};
gps = {};
grpc = {};
hddtemp = {};
hugepages = {};
intel_pmu = {};
intel_rdt = {};
interface = {};
ipc = {};
ipmi = {};
iptables = {
buildInputs = [
libpcap
] ++ stdenv.lib.optionals stdenv.isLinux [
iptables libmnl
];
};
ipvs = {};
irq = {};
java = {
buildInputs = [ jdk libgcrypt libxml2 ];
};
load = {};
logfile = {};
log_logstash = {
buildInputs = [ yajl ];
};
lpar = {};
lua = {
buildInputs = [ lua ];
};
lvm = {};
madwifi = {};
match_empty_counter = {};
match_hashed = {};
match_regex = {};
match_timediff = {};
match_value = {};
mbmon = {};
mcelog = {};
md = {};
memcachec = {
buildInputs = [ libmemcached cyrus_sasl ];
};
memcached = {};
memory = {};
mic = {};
modbus = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [ libmodbus ];
};
mqtt = {
buildInputs = [ mosquitto ];
};
multimeter = {};
mysql = {
buildInputs = stdenv.lib.optionals (libmysqlclient != null) [
libmysqlclient
];
};
netapp = {};
netlink = {
buildInputs = [
libpcap
] ++ stdenv.lib.optionals stdenv.isLinux [
libmnl
];
};
network = {
buildInputs = [ libgcrypt ];
};
nfs = {};
nginx = {
buildInputs = [ curl ];
};
notify_desktop = {
buildInputs = [ libnotify gdk-pixbuf ];
};
notify_email = {};
notify_nagios = {};
ntpd = {};
numa = {};
nut = {};
olsrd = {};
onewire = {};
openldap = {};
openvpn = {};
oracle = {};
ovs_events = {
buildInputs = [ yajl ];
};
ovs_stats = {
buildInputs = [ yajl ];
};
perl = {};
pf = {};
pinba = {
buildInputs = [ protobufc ];
};
ping = {
buildInputs = [ liboping ];
};
postgresql = {
buildInputs = [ postgresql ];
};
powerdns = {};
processes = {};
protocols = {};
python = {
buildInputs = [ python ];
};
redis = {
buildInputs = [ hiredis ];
};
routeros = {};
rrdcached = {
buildInputs = [ rrdtool libxml2 ];
};
rrdtool = {
buildInputs = [ rrdtool libxml2 ];
};
sensors = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [ lm_sensors ];
};
serial = {};
sigrok = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [ libsigrok udev ];
};
smart = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [ libatasmart udev ];
};
snmp = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [ net_snmp ];
};
snmp_agent = {
buildInputs = stdenv.lib.optionals stdenv.isLinux [ net_snmp ];
};
statsd = {};
swap = {};
synproxy = {};
syslog = {};
table = {};
tail_csv = {};
tail = {};
tape = {};
target_notification = {};
target_replace = {};
target_scale = {};
target_set = {};
target_v5upgrade = {};
tcpconns = {};
teamspeak2 = {};
ted = {};
thermal = {};
threshold = {};
tokyotyrant = {};
turbostat = {};
unixsock = {};
uptime = {};
users = {};
uuid = {};
varnish = {
buildInputs = [ curl varnish ];
};
virt = {
buildInputs = [ libvirt libxml2 yajl ] ++
stdenv.lib.optionals stdenv.isLinux [ lvm2 udev
# those might be no longer required when https://github.com/NixOS/nixpkgs/pull/51767
# is merged
libapparmor numactl libcap_ng
];
};
vmem = {};
vserver = {};
wireless = {};
write_graphite = {};
write_http = {
buildInputs = [ curl yajl ];
};
write_kafka = {
buildInputs = [ yajl rdkafka ];
};
write_log = {
buildInputs = [ yajl ];
};
write_mongodb = {
buildInputs = [ mongoc ];
};
write_prometheus = {
buildInputs = [ protobufc libmicrohttpd ];
};
write_redis = {
buildInputs = [ hiredis ];
};
write_riemann = {
buildInputs = [ protobufc riemann_c_client ];
};
write_sensu = {};
write_tsdb = {};
xencpu = {};
xmms = {};
zfs_arc = {};
zone = {};
zookeeper = {};
};
configureFlags =
if enabledPlugins == null
then []
else (map (plugin: "--enable-${plugin}") enabledPlugins) ++
(map (plugin: "--disable-${plugin}")
(builtins.filter (plugin: ! builtins.elem plugin enabledPlugins)
(builtins.attrNames plugins))
);
pluginBuildInputs = plugin:
if ! builtins.hasAttr plugin plugins
then throw "Unknown collectd plugin: ${plugin}"
else
let
pluginAttrs = builtins.getAttr plugin plugins;
in
if pluginAttrs ? "buildInputs"
then pluginAttrs.buildInputs
else [];
buildInputs =
if enabledPlugins == null
then builtins.concatMap pluginBuildInputs
(builtins.attrNames plugins)
else builtins.concatMap pluginBuildInputs enabledPlugins;
in {
inherit configureFlags buildInputs;
}