From efab03957535a1ed749bf286f78fad03e9b0f511 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 20 Oct 2019 00:35:55 +0200 Subject: [PATCH] collectd: parameterize with optional enabledPlugins --- pkgs/tools/system/collectd/default.nix | 63 +---- pkgs/tools/system/collectd/plugins.nix | 342 +++++++++++++++++++++++++ 2 files changed, 351 insertions(+), 54 deletions(-) create mode 100644 pkgs/tools/system/collectd/plugins.nix diff --git a/pkgs/tools/system/collectd/default.nix b/pkgs/tools/system/collectd/default.nix index 3e7e4e5969ab..517d0afb95f2 100644 --- a/pkgs/tools/system/collectd/default.nix +++ b/pkgs/tools/system/collectd/default.nix @@ -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 = '' diff --git a/pkgs/tools/system/collectd/plugins.nix b/pkgs/tools/system/collectd/plugins.nix new file mode 100644 index 000000000000..10f850419872 --- /dev/null +++ b/pkgs/tools/system/collectd/plugins.nix @@ -0,0 +1,342 @@ +{ 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 +, 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 + 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 = {}; + 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; +}