1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python{2_7,3_5,3_6,3_7} )
7 JAVA_PKG_OPT_USE="collectd_plugins_java"
9 inherit autotools fcaps flag-o-matic java-pkg-opt-2 linux-info multilib perl-functions python-single-r1 systemd tmpfiles user
11 DESCRIPTION="Collects system statistics and provides mechanisms to store the values"
13 HOMEPAGE="https://collectd.org/"
14 SRC_URI="https://github.com/${PN}/${PN}/archive/${PN}-${PV}.tar.gz"
16 LICENSE="MIT GPL-2 GPL-2+ GPL-3 GPL-3+"
18 KEYWORDS="~alpha ~amd64 ~arm ~x86"
19 IUSE="contrib debug java kernel_Darwin kernel_FreeBSD kernel_linux perl selinux static-libs udev xfs"
21 # The plugin lists have to follow here since they extend IUSE
23 # Plugins that don't build (e.g. dependencies not in Gentoo)
24 # apple_sensors: Requires libIOKit
25 # amqp1: Requires libqpid-proton
26 # aquaero: Requires aerotools-ng/libaquaero5
27 # barometer: Requires libi2c (i2c_smbus_read_i2c_block_data)
28 # dpdkevents: Requires dpdk
29 # dpdkstat: Requires dpdk
30 # grpc: Requires libgrpc
31 # intel_pmu: Requires libjevents (pmu-tools)
32 # intel_rdt: Requires libpqos from intel-cmt-cat project
33 # lpar: Requires libperfstat (AIX only)
34 # mic: Requires Intel Many Integrated Core Architecture API
35 # (part of Intel's Xeon Phi software)
36 # netapp: Requires libnetapp (http://communities.netapp.com/docs/DOC-1110)
37 # pf: Requires BSD packet filter
38 # pinba: Requires MySQL Pinba engine (http://pinba.org/)
39 # tape: Requires libkstat (Solaris only)
40 # write_riemann: Requires riemann-c-client
41 # xmms: Requires libxmms (v1)
42 # zone: Solaris only...
43 COLLECTD_IMPOSSIBLE_PLUGINS="apple_sensors amqp1 aquaero barometer dpdkstat
44 grpc intel_pmu intel_rdt lpar mic netapp pf pinba tape write_riemann
47 # Plugins that have been (compile) tested and can be enabled via COLLECTD_PLUGINS
48 COLLECTD_TESTED_PLUGINS="aggregation amqp apache apcups ascent battery bind
49 ceph cgroups chrony conntrack contextswitch cpu cpufreq cpusleep
50 csv curl curl_json curl_xml dbi df disk dns drbd email
51 entropy ethstat exec fhcount filecount fscache gmond gps hddtemp
52 hugepages interface ipc ipmi iptables ipvs irq java lua
53 load logfile log_logstash lvm madwifi match_empty_counter
54 match_hashed match_regex match_timediff match_value mbmon mcelog md
55 memcachec memcached memory modbus mqtt multimeter mysql netlink
56 network network nfs nginx notify_desktop notify_email notify_nagios
57 ntpd numa nut olsrd onewire openldap openvpn oracle ovs_events
58 ovs_stats perl ping postgresql powerdns processes protocols python
59 python redis routeros rrdcached rrdtool sensors serial sigrok smart
60 snmp snmp_agent statsd swap syslog table tail tail_csv
61 target_notification target_replace target_scale target_set tcpconns
62 teamspeak2 ted thermal threshold tokyotyrant turbostat unixsock
63 uptime users uuid varnish virt vmem vserver wireless write_graphite
64 write_http write_kafka write_log write_mongodb write_prometheus
65 write_redis write_sensu write_tsdb xencpu zfs_arc zookeeper"
67 COLLECTD_DISABLED_PLUGINS="${COLLECTD_IMPOSSIBLE_PLUGINS}"
69 COLLECTD_ALL_PLUGINS=${COLLECTD_TESTED_PLUGINS}
71 for plugin in ${COLLECTD_ALL_PLUGINS}; do
72 IUSE="${IUSE} collectd_plugins_${plugin}"
76 # Now come the dependencies.
81 perl? ( dev-lang/perl:=[ithreads] )
82 udev? ( virtual/udev )
83 xfs? ( sys-fs/xfsprogs )
84 collectd_plugins_amqp? ( net-libs/rabbitmq-c )
85 collectd_plugins_apache? ( net-misc/curl:0= )
86 collectd_plugins_ascent? ( net-misc/curl:0= dev-libs/libxml2:2= )
87 collectd_plugins_bind? ( net-misc/curl:0= dev-libs/libxml2:2= )
88 collectd_plugins_ceph? ( dev-libs/yajl:= )
89 collectd_plugins_curl? ( net-misc/curl:0= )
90 collectd_plugins_curl_json? ( net-misc/curl:0= dev-libs/yajl:= )
91 collectd_plugins_curl_xml? ( net-misc/curl:0= dev-libs/libxml2:2= )
92 collectd_plugins_dbi? ( dev-db/libdbi )
93 collectd_plugins_dns? ( net-libs/libpcap )
94 collectd_plugins_gmond? ( sys-cluster/ganglia )
95 collectd_plugins_gps? ( sci-geosciences/gpsd:= )
96 collectd_plugins_ipmi? ( >=sys-libs/openipmi-2.0.16-r1 )
97 collectd_plugins_iptables? ( >=net-firewall/iptables-1.4.13:0= )
98 collectd_plugins_log_logstash? ( dev-libs/yajl:= )
99 collectd_plugins_lua? ( dev-lang/lua:0= )
100 collectd_plugins_lvm? ( sys-fs/lvm2 )
101 collectd_plugins_memcachec? ( dev-libs/libmemcached )
102 collectd_plugins_modbus? ( dev-libs/libmodbus )
103 collectd_plugins_mqtt? ( app-misc/mosquitto )
104 collectd_plugins_mysql? ( dev-db/mysql-connector-c:= )
105 collectd_plugins_netlink? ( net-libs/libmnl )
106 collectd_plugins_nginx? ( net-misc/curl:0= )
107 collectd_plugins_notify_desktop? ( x11-libs/libnotify )
108 collectd_plugins_notify_email? ( net-libs/libesmtp )
109 collectd_plugins_nut? ( >=sys-power/nut-2.7.2-r2 )
110 collectd_plugins_openldap? ( net-nds/openldap )
111 collectd_plugins_onewire? ( >=sys-fs/owfs-3.1:= )
112 collectd_plugins_oracle? ( dev-db/oracle-instantclient-basic )
113 collectd_plugins_ovs_events? ( dev-libs/yajl:= )
114 collectd_plugins_ovs_stats? ( dev-libs/yajl:= )
115 collectd_plugins_perl? ( dev-lang/perl:=[ithreads] )
116 collectd_plugins_ping? ( net-libs/liboping )
117 collectd_plugins_postgresql? ( dev-db/postgresql:= )
118 collectd_plugins_python? ( ${PYTHON_DEPS} )
119 collectd_plugins_redis? ( dev-libs/hiredis:= )
120 collectd_plugins_routeros? ( net-libs/librouteros )
121 collectd_plugins_rrdcached? ( net-analyzer/rrdtool:= )
122 collectd_plugins_rrdtool? ( net-analyzer/rrdtool:= )
123 collectd_plugins_sensors? ( sys-apps/lm-sensors:= )
124 collectd_plugins_sigrok? ( <sci-libs/libsigrok-0.4:= dev-libs/glib:2 )
125 collectd_plugins_smart? ( dev-libs/libatasmart )
126 collectd_plugins_snmp? ( net-analyzer/net-snmp )
127 collectd_plugins_snmp_agent? ( net-analyzer/net-snmp )
128 collectd_plugins_tokyotyrant? ( net-misc/tokyotyrant )
129 collectd_plugins_varnish? ( www-servers/varnish:= )
130 collectd_plugins_virt? ( app-emulation/libvirt:= dev-libs/libxml2:2= )
131 collectd_plugins_write_http? ( net-misc/curl:0= dev-libs/yajl:= )
132 collectd_plugins_write_kafka? ( >=dev-libs/librdkafka-0.9.0.99:= dev-libs/yajl:= )
133 collectd_plugins_write_mongodb? ( >=dev-libs/mongo-c-driver-1.8.2:= )
134 collectd_plugins_write_prometheus? ( >=dev-libs/protobuf-c-1.2.1-r1:= net-libs/libmicrohttpd:= )
135 collectd_plugins_write_redis? ( dev-libs/hiredis:= )
136 collectd_plugins_xencpu? ( app-emulation/xen-tools:= )
139 collectd_plugins_disk? ( sys-libs/libstatgrab:= )
140 collectd_plugins_interface? ( sys-libs/libstatgrab:= )
141 collectd_plugins_load? ( sys-libs/libstatgrab:= )
142 collectd_plugins_memory? ( sys-libs/libstatgrab:= )
143 collectd_plugins_swap? ( sys-libs/libstatgrab:= )
144 collectd_plugins_users? ( sys-libs/libstatgrab:= )
147 # Enforcing !=sys-kernel/linux-headers-4.5 > due to #577846
148 DEPEND="${COMMON_DEPEND}
149 collectd_plugins_iptables? ( || ( <=sys-kernel/linux-headers-4.4 >=sys-kernel/linux-headers-4.6 ) )
150 collectd_plugins_java? ( >=virtual/jdk-1.6 )
153 RDEPEND="${COMMON_DEPEND}
154 collectd_plugins_java? ( >=virtual/jre-1.6 )
155 collectd_plugins_syslog? ( virtual/logger )
156 selinux? ( sec-policy/selinux-collectd )
157 !<sys-apps/openrc-0.18.2"
160 collectd_plugins_python? ( ${PYTHON_REQUIRED_USE} )
161 collectd_plugins_smart? ( udev )"
163 S="${WORKDIR}/${PN}-${PN}-${PV}"
165 # @FUNCTION: collectd_plugin_kernel_linux
167 # USAGE: <plugin name> <kernel_options> <severity>
168 # kernel_options is a list of kernel configurations options; the check tests whether at least
169 # one of them is enabled. If no, depending on the third argument an elog, ewarn, or eerror message
171 collectd_plugin_kernel_linux() {
173 if has ${1} ${COLLECTD_ALL_PLUGINS}; then
174 if use collectd_plugins_${1}; then
176 if linux_chkconfig_present ${opt}; then
180 multi_opt=${2//\ /\ or\ }
183 elog "The ${1} plugin can use kernel features that are disabled now; enable ${multi_opt} in your kernel"
186 ewarn "The ${1} plugin uses kernel features that are disabled now; enable ${multi_opt} in your kernel"
189 eerror "The ${1} plugin needs kernel features that are disabled now; enable ${multi_opt} in your kernel"
192 die "function collectd_plugin_kernel_linux called with invalid third argument"
199 collectd_linux_kernel_checks() {
200 if ! linux_chkconfig_present PROC_FS; then
201 ewarn "/proc file system support is disabled, many plugins will not be able to read any statistics from your system unless you enable PROC_FS in your kernel"
204 if ! linux_chkconfig_present SYSFS; then
205 ewarn "/sys file system support is disabled, many plugins will not be able to read any statistics from your system unless you enable SYSFS in your kernel"
208 # battery.c: /proc/pmu/battery_%i
209 # battery.c: /proc/acpi/battery
210 collectd_plugin_kernel_linux battery ACPI_BATTERY warn
212 # cgroups.c: /sys/fs/cgroup/
213 collectd_plugin_kernel_linux cgroups CGROUPS warn
215 # cpufreq.c: /sys/devices/system/cpu/cpu%d/cpufreq/
216 collectd_plugin_kernel_linux cpufreq SYSFS warn
217 collectd_plugin_kernel_linux cpufreq CPU_FREQ_STAT warn
220 collectd_plugin_kernel_linux drbd BLK_DEV_DRBD warn
222 # conntrack.c: /proc/sys/net/netfilter/*
223 collectd_plugin_kernel_linux conntrack NETFILTER warn
225 # fscache.c: /proc/fs/fscache/stats
226 collectd_plugin_kernel_linux fscache FSCACHE warn
228 # nfs.c: /proc/net/rpc/nfs
229 # nfs.c: /proc/net/rpc/nfsd
230 collectd_plugin_kernel_linux nfs NFS_COMMON warn
232 # serial.c: /proc/tty/driver/serial
233 # serial.c: /proc/tty/driver/ttyS
234 collectd_plugin_kernel_linux serial SERIAL_CORE warn
236 # swap.c: /proc/meminfo
237 collectd_plugin_kernel_linux swap SWAP warn
239 # thermal.c: /proc/acpi/thermal_zone
240 # thermal.c: /sys/class/thermal
241 collectd_plugin_kernel_linux thermal ACPI_THERMAL warn
243 # turbostat.c: /dev/cpu/%d/msr
244 collectd_plugin_kernel_linux turbostat X86_MSR warn
246 # vmem.c: /proc/vmstat
247 collectd_plugin_kernel_linux vmem VM_EVENT_COUNTERS warn
249 # vserver.c: /proc/virtual
250 collectd_plugin_kernel_linux vserver VSERVER warn
252 # uuid.c: /sys/hypervisor/uuid
253 collectd_plugin_kernel_linux uuid SYSFS info
255 # wireless.c: /proc/net/wireless
256 collectd_plugin_kernel_linux wireless "WIRELESS MAC80211 IEEE80211" warn
258 # zfs_arc.c: /proc/spl/kstat/zfs/arcstats
259 collectd_plugin_kernel_linux zfs_arc "SPL ZFS" warn
263 if use kernel_linux; then
266 if linux_config_exists; then
267 einfo "Checking your linux kernel configuration:"
268 collectd_linux_kernel_checks
270 elog "Cannot find a linux kernel configuration. Continuing anyway."
274 if use collectd_plugins_java; then
275 java-pkg-opt-2_pkg_setup
278 use collectd_plugins_python && python-single-r1_pkg_setup
281 enewuser collectd -1 -1 /var/lib/collectd collectd
287 # There's some strange prefix handling in the default config file, resulting in
288 # paths like "/usr/var/..."
289 sed -i -e "s:@prefix@/var:/var:g" src/collectd.conf.in || die
291 # Adjust upstream's systemd unit
292 # - Get rid of EnvironmentFile directive; These files don't exist on Gentoo!
293 # - Add User=collectd to run collectd as user "collectd" per default
295 -e '/^EnvironmentFile=.*/d' \
296 -e '/^\[Service\]/aUser=collectd' \
297 contrib/systemd.${PN}.service || die
303 # Now come the lists of os-dependent plugins. Any plugin that is not listed anywhere here
304 # should work independent of the operating system.
306 local linux_plugins="barometer battery cpu cpufreq disk
307 drbd entropy ethstat hugepages interface iptables
308 ipvs irq ipc load memory md netlink nfs numa processes
309 serial swap tcpconns thermal turbostat users vmem wireless
312 local need_libstatgrab=0
313 local libstatgrab_plugins="cpu disk interface load memory swap users"
314 local bsd_plugins="cpu tcpconns ${libstatgrab_plugins} zfc_arc"
316 local darwin_plugins="apple_sensors battery cpu disk interface memory processes tcpconns"
318 local osdependent_plugins="${linux_plugins} ${bsd_plugins} ${darwin_plugins}"
319 local myos_plugins=""
320 if use kernel_linux; then
321 einfo "Enabling Linux plugins."
322 myos_plugins=${linux_plugins}
323 elif use kernel_FreeBSD; then
324 einfo "Enabling FreeBSD plugins."
325 myos_plugins=${bsd_plugins}
326 elif use kernel_Darwin; then
327 einfo "Enabling Darwin plugins."
328 myos_plugins=${darwin_plugins}
331 local myconf="--disable-werror"
334 myconf+=" $(use_enable debug)"
337 # Required for smart plugin via REQUIRED_USE; Optional for disk plugin
339 myconf+=" --with-libudev"
341 myconf+=" --without-libudev"
346 # Disable what needs to be disabled.
347 for plugin in ${COLLECTD_DISABLED_PLUGINS}; do
348 if [[ "${plugin}" == 'dpdkstat' ]]; then
349 myconf+=" --without-libdpdk"
351 myconf+=" --disable-${plugin}"
355 # Set enable/disable for each single plugin.
356 for plugin in ${COLLECTD_ALL_PLUGINS}; do
357 if has ${plugin} ${osdependent_plugins}; then
358 # plugin is os-dependent ...
359 if has ${plugin} ${myos_plugins}; then
360 # ... and available in this os
361 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
362 # ... must we link against libstatgrab? Bug #541518
363 if use kernel_FreeBSD && has ${plugin} ${libstatgrab_plugins}; then
364 einfo "We must link against libstatgrab due to plugin \"${plugin}\" ..."
368 # ... and NOT available in this os
369 if use collectd_plugins_${plugin}; then
370 ewarn "You try to enable the ${plugin} plugin, but it is not available for this"
371 ewarn "kernel. Disabling it automatically."
373 myconf+=" --disable-${plugin}"
375 elif [[ "${plugin}" = "collectd_plugins_perl" ]]; then
376 if use collectd_plugins_perl && ! use perl; then
377 ewarn "Perl plugin disabled as perl bindings disabled by -perl use flag"
378 myconf+= --disable-perl
380 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
383 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
387 if [ "${need_libstatgrab}" -eq 1 ]; then
388 myconf+=" --with-libstatgrab"
390 myconf+=" --without-libstatgrab"
393 # JAVA_HOME is set by eclasses.
394 if use collectd_plugins_java; then
395 myconf+=" --with-java"
398 # Need libiptc ONLY for iptables. If we try to use it otherwise bug 340109 happens.
399 # lots of libs are only needed for plugins, if they are disabled, also disable the lib
400 use collectd_plugins_iptables || myconf+=" --with-libiptc=no"
401 use collectd_plugins_openldap || myconf+=" --with-libldap=no"
402 use collectd_plugins_redis || use collectd_plugins_write_redis || myconf+=" --with-libhiredis=no"
403 use collectd_plugins_smart || myconf+=" --with-libatasmart=no"
404 use collectd_plugins_gps || myconf+=" --with-libgps=no"
407 myconf+=" --with-perl-bindings=INSTALLDIRS=vendor"
409 myconf+=" --without-perl-bindings"
412 # No need for v5upgrade
413 myconf+=" --disable-target_v5upgrade"
416 if use collectd_plugins_python; then
417 myconf+=" --with-libpython=yes"
418 export PYTHON_CONFIG=$(python_get_PYTHON_CONFIG)
420 myconf+=" --with-libpython=no"
424 myconf+=" $(use_enable xfs)"
426 # Finally, run econf.
427 KERNEL_DIR="${KERNEL_DIR}" econf --config-cache \
428 $(use_enable static-libs static) \
429 --localstatedir=/var ${myconf}
433 emake DESTDIR="${D%/}" install
437 find "${ED}"usr/ -name "*.la" -delete || die
439 if use collectd_plugins_java; then
440 java-pkg_regjar "${ED}"usr/share/${PN}/java/*.jar
443 fowners root:collectd /etc/collectd.conf
444 fperms u=rw,g=r,o= /etc/collectd.conf
446 dodoc AUTHORS ChangeLog README
448 if use contrib ; then
449 insinto /usr/share/doc/${PF}
453 keepdir /var/lib/${PN}
454 fowners collectd:collectd /var/lib/${PN}
456 newinitd "${FILESDIR}/${PN}.initd-r2" ${PN}
457 newconfd "${FILESDIR}/${PN}.confd-r2" ${PN}
458 systemd_newunit "contrib/systemd.${PN}.service" ${PN}.service
460 insinto /etc/logrotate.d
461 newins "${FILESDIR}/${PN}.logrotate" ${PN}
463 newtmpfiles "${FILESDIR}"/${PN}.tmpfile ${PN}.conf
465 sed -i -e 's:^.*PIDFile "/var/run/collectd.pid":#PIDFile "/run/collectd.pid":' "${ED}"etc/collectd.conf || die
466 sed -i -e 's:^# SocketFile "/var/run/collectd-unixsock":# SocketFile "/run/collectd/collectd.socket":' "${ED}"etc/collectd.conf || die
467 sed -i -e 's:^.*LoadPlugin perl$:# The new, correct way to load the perl plugin -- \n# <LoadPlugin perl>\n# Globals true\n# </LoadPlugin>:' "${ED}"etc/collectd.conf || die
468 sed -i -e 's:^.*LoadPlugin python$:# The new, correct way to load the python plugin -- \n# <LoadPlugin python>\n# Globals true\n# </LoadPlugin>:' "${ED}"etc/collectd.conf || die
472 tmpfiles_process "${PN}.conf"
474 if use filecaps; then
476 use collectd_plugins_ceph && caps+=('CAP_DAC_OVERRIDE')
477 use collectd_plugins_exec && caps+=('CAP_SETUID' 'CAP_SETGID')
478 use collectd_plugins_iptables && caps+=('CAP_NET_ADMIN')
479 use collectd_plugins_filecount && caps+=('CAP_DAC_READ_SEARCH')
481 if use collectd_plugins_dns || use collectd_plugins_ping; then
482 caps+=('CAP_NET_RAW')
485 if use collectd_plugins_turbostat || use collectd_plugins_smart; then
486 caps+=('CAP_SYS_RAWIO')
489 if [ ${#caps[@]} -gt 0 ]; then
490 local caps_str=$(IFS=","; echo "${caps[*]}")
491 fcaps ${caps_str} usr/sbin/collectd
492 elog "Capabilities for ${EROOT}usr/sbin/collectd set to:"
493 elog " ${caps_str}+EP"
496 local systemd_unit="$(systemd_get_systemunitdir)/collectd.service"
497 if [[ -e "${systemd_unit}" ]]; then
498 caps_str="${caps[*]}"
499 sed -i -e "s:^CapabilityBoundingSet=.*:CapabilityBoundingSet=${caps_str}:" "${systemd_unit}" || \
500 die "Failed to set CapabilityBoundingSet in '${systemd_unit}'"
502 elog "CapabilityBoundingSet in '${systemd_unit}'"
503 elog "updated to match capabilities set above."
506 if has_version "sys-apps/systemd"; then
508 ewarn "Failed to update CapabilityBoundingSet in '${systemd_unit}'"
509 ewarn "because unit was not found. Please file a bug about this."
515 elog "Note: Collectd is only the collector."
516 elog " You need to install 'data' sources (applications) locally or"
517 elog " remotely on your own."
520 elog "Collectd is configured to run as unprivileged user by default."
521 elog "You may want to revisit the configuration."
524 if use collectd_plugins_email; then
525 ewarn "The email plug-in is deprecated. To submit statistics please use the unixsock plugin."
528 if use collectd_plugins_smart; then
530 elog "If you are using smart plugin and don't run collectd as root make sure"
531 elog "that the collectd user is allowed to access the disk you want to monitor"
532 elog "(can be done via udev rule for example) and that collectd has the required"
533 elog "capabilities set (which is the default when package was emerged with"
534 elog "'filecaps' USE flag set)."
538 elog "The scripts in /usr/share/doc/${PF}/collection3 for generating graphs need dev-perl/HTML-Parser,"
539 elog "dev-perl/config-general, dev-perl/regexp-common, and net-analyzer/rrdtool[perl] to be installed."