1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{6,7,8} )
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}/releases/download/${PV}/${P}.tar.bz2"
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 # tokyotyrant: Requires tokyotyrant
41 # write_riemann: Requires riemann-c-client
42 # xmms: Requires libxmms (v1)
43 # zone: Solaris only...
44 COLLECTD_IMPOSSIBLE_PLUGINS="apple_sensors amqp1 aquaero barometer dpdkstat
45 grpc intel_pmu intel_rdt lpar mic netapp pf pinba tape tokyotyrant
46 write_riemann xmms zone"
48 # Plugins that have been (compile) tested and can be enabled via COLLECTD_PLUGINS
49 COLLECTD_TESTED_PLUGINS="aggregation amqp apache apcups ascent battery bind
50 ceph cgroups chrony conntrack contextswitch cpu cpufreq cpusleep
51 csv curl curl_json curl_xml dbi df disk dns drbd email
52 entropy ethstat exec fhcount filecount fscache gmond gps hddtemp
53 hugepages interface ipc ipmi iptables ipvs irq java lua
54 load logfile log_logstash lvm madwifi match_empty_counter
55 match_hashed match_regex match_timediff match_value mbmon mcelog md
56 memcachec memcached memory modbus mqtt multimeter mysql netlink
57 network network nfs nginx notify_desktop notify_email notify_nagios
58 ntpd numa nut olsrd onewire openldap openvpn oracle ovs_events
59 ovs_stats perl ping postgresql powerdns processes protocols python
60 python redis routeros rrdcached rrdtool sensors serial sigrok smart
61 snmp snmp_agent statsd swap sysevent syslog table tail tail_csv
62 target_notification target_replace target_scale target_set tcpconns
63 teamspeak2 ted thermal threshold turbostat unixsock
64 uptime users uuid varnish virt vmem vserver wireless write_graphite
65 write_http write_kafka write_log write_mongodb write_prometheus
66 write_redis write_sensu write_tsdb xencpu zfs_arc zookeeper"
68 COLLECTD_DISABLED_PLUGINS="${COLLECTD_IMPOSSIBLE_PLUGINS}"
70 COLLECTD_ALL_PLUGINS=${COLLECTD_TESTED_PLUGINS}
72 for plugin in ${COLLECTD_ALL_PLUGINS}; do
73 IUSE="${IUSE} collectd_plugins_${plugin}"
77 # Now come the dependencies.
82 perl? ( dev-lang/perl:=[ithreads] )
83 udev? ( virtual/udev )
84 xfs? ( sys-fs/xfsprogs )
85 collectd_plugins_amqp? ( net-libs/rabbitmq-c )
86 collectd_plugins_apache? ( net-misc/curl:0= )
87 collectd_plugins_ascent? ( net-misc/curl:0= dev-libs/libxml2:2= )
88 collectd_plugins_bind? ( net-misc/curl:0= dev-libs/libxml2:2= )
89 collectd_plugins_ceph? ( dev-libs/yajl:= )
90 collectd_plugins_curl? ( net-misc/curl:0= )
91 collectd_plugins_curl_json? ( net-misc/curl:0= dev-libs/yajl:= )
92 collectd_plugins_curl_xml? ( net-misc/curl:0= dev-libs/libxml2:2= )
93 collectd_plugins_dbi? ( dev-db/libdbi )
94 collectd_plugins_dns? ( net-libs/libpcap )
95 collectd_plugins_gmond? ( sys-cluster/ganglia )
96 collectd_plugins_gps? ( sci-geosciences/gpsd:= )
97 collectd_plugins_ipmi? ( >=sys-libs/openipmi-2.0.16-r1 )
98 collectd_plugins_iptables? ( >=net-firewall/iptables-1.4.13:0= )
99 collectd_plugins_log_logstash? ( dev-libs/yajl:= )
100 collectd_plugins_lua? ( dev-lang/lua:0= )
101 collectd_plugins_lvm? ( sys-fs/lvm2 )
102 collectd_plugins_memcachec? ( dev-libs/libmemcached )
103 collectd_plugins_modbus? ( dev-libs/libmodbus )
104 collectd_plugins_mqtt? ( app-misc/mosquitto )
105 collectd_plugins_mysql? ( dev-db/mysql-connector-c:= )
106 collectd_plugins_netlink? ( net-libs/libmnl )
107 collectd_plugins_nginx? ( net-misc/curl:0= )
108 collectd_plugins_notify_desktop? ( x11-libs/libnotify )
109 collectd_plugins_notify_email? ( net-libs/libesmtp )
110 collectd_plugins_nut? ( >=sys-power/nut-2.7.2-r2 )
111 collectd_plugins_openldap? ( net-nds/openldap )
112 collectd_plugins_onewire? ( >=sys-fs/owfs-3.1:= )
113 collectd_plugins_oracle? ( dev-db/oracle-instantclient-basic )
114 collectd_plugins_ovs_events? ( dev-libs/yajl:= )
115 collectd_plugins_ovs_stats? ( dev-libs/yajl:= )
116 collectd_plugins_perl? ( dev-lang/perl:=[ithreads] )
117 collectd_plugins_ping? ( net-libs/liboping )
118 collectd_plugins_postgresql? ( dev-db/postgresql:= )
119 collectd_plugins_python? ( ${PYTHON_DEPS} )
120 collectd_plugins_redis? ( dev-libs/hiredis:= )
121 collectd_plugins_routeros? ( net-libs/librouteros )
122 collectd_plugins_rrdcached? ( net-analyzer/rrdtool:= )
123 collectd_plugins_rrdtool? ( net-analyzer/rrdtool:= )
124 collectd_plugins_sensors? ( sys-apps/lm-sensors:= )
125 collectd_plugins_sigrok? ( <sci-libs/libsigrok-0.4:= dev-libs/glib:2 )
126 collectd_plugins_smart? ( dev-libs/libatasmart )
127 collectd_plugins_snmp? ( net-analyzer/net-snmp )
128 collectd_plugins_snmp_agent? ( net-analyzer/net-snmp )
129 collectd_plugins_sysevent? ( dev-libs/yajl:= )
130 collectd_plugins_varnish? ( www-servers/varnish:= )
131 collectd_plugins_virt? ( app-emulation/libvirt:= dev-libs/libxml2:2= )
132 collectd_plugins_write_http? ( net-misc/curl:0= dev-libs/yajl:= )
133 collectd_plugins_write_kafka? ( >=dev-libs/librdkafka-0.9.0.99:= dev-libs/yajl:= )
134 collectd_plugins_write_mongodb? ( >=dev-libs/mongo-c-driver-1.8.2:= )
135 collectd_plugins_write_prometheus? ( >=dev-libs/protobuf-c-1.2.1-r1:= net-libs/libmicrohttpd:= )
136 collectd_plugins_write_redis? ( dev-libs/hiredis:= )
137 collectd_plugins_xencpu? ( app-emulation/xen-tools:= )
140 collectd_plugins_disk? ( sys-libs/libstatgrab:= )
141 collectd_plugins_interface? ( sys-libs/libstatgrab:= )
142 collectd_plugins_load? ( sys-libs/libstatgrab:= )
143 collectd_plugins_memory? ( sys-libs/libstatgrab:= )
144 collectd_plugins_swap? ( sys-libs/libstatgrab:= )
145 collectd_plugins_users? ( sys-libs/libstatgrab:= )
148 # Enforcing !=sys-kernel/linux-headers-4.5 > due to #577846
149 DEPEND="${COMMON_DEPEND}
150 collectd_plugins_iptables? ( || ( <=sys-kernel/linux-headers-4.4 >=sys-kernel/linux-headers-4.6 ) )
151 collectd_plugins_java? ( >=virtual/jdk-1.6 )
154 RDEPEND="${COMMON_DEPEND}
155 collectd_plugins_java? ( >=virtual/jre-1.6 )
156 collectd_plugins_syslog? ( virtual/logger )
157 selinux? ( sec-policy/selinux-collectd )"
160 collectd_plugins_python? ( ${PYTHON_REQUIRED_USE} )
161 collectd_plugins_smart? ( udev )"
163 # @FUNCTION: collectd_plugin_kernel_linux
165 # USAGE: <plugin name> <kernel_options> <severity>
166 # kernel_options is a list of kernel configurations options; the check tests whether at least
167 # one of them is enabled. If no, depending on the third argument an elog, ewarn, or eerror message
169 collectd_plugin_kernel_linux() {
171 if has ${1} ${COLLECTD_ALL_PLUGINS}; then
172 if use collectd_plugins_${1}; then
174 if linux_chkconfig_present ${opt}; then
178 multi_opt=${2//\ /\ or\ }
181 elog "The ${1} plugin can use kernel features that are disabled now; enable ${multi_opt} in your kernel"
184 ewarn "The ${1} plugin uses kernel features that are disabled now; enable ${multi_opt} in your kernel"
187 eerror "The ${1} plugin needs kernel features that are disabled now; enable ${multi_opt} in your kernel"
190 die "function collectd_plugin_kernel_linux called with invalid third argument"
197 collectd_linux_kernel_checks() {
198 if ! linux_chkconfig_present PROC_FS; then
199 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"
202 if ! linux_chkconfig_present SYSFS; then
203 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"
206 # battery.c: /proc/pmu/battery_%i
207 # battery.c: /proc/acpi/battery
208 collectd_plugin_kernel_linux battery ACPI_BATTERY warn
210 # cgroups.c: /sys/fs/cgroup/
211 collectd_plugin_kernel_linux cgroups CGROUPS warn
213 # cpufreq.c: /sys/devices/system/cpu/cpu%d/cpufreq/
214 collectd_plugin_kernel_linux cpufreq SYSFS warn
215 collectd_plugin_kernel_linux cpufreq CPU_FREQ_STAT warn
218 collectd_plugin_kernel_linux drbd BLK_DEV_DRBD warn
220 # conntrack.c: /proc/sys/net/netfilter/*
221 collectd_plugin_kernel_linux conntrack NETFILTER warn
223 # fscache.c: /proc/fs/fscache/stats
224 collectd_plugin_kernel_linux fscache FSCACHE warn
226 # nfs.c: /proc/net/rpc/nfs
227 # nfs.c: /proc/net/rpc/nfsd
228 collectd_plugin_kernel_linux nfs NFS_COMMON warn
230 # serial.c: /proc/tty/driver/serial
231 # serial.c: /proc/tty/driver/ttyS
232 collectd_plugin_kernel_linux serial SERIAL_CORE warn
234 # swap.c: /proc/meminfo
235 collectd_plugin_kernel_linux swap SWAP warn
237 # thermal.c: /proc/acpi/thermal_zone
238 # thermal.c: /sys/class/thermal
239 collectd_plugin_kernel_linux thermal ACPI_THERMAL warn
241 # turbostat.c: /dev/cpu/%d/msr
242 collectd_plugin_kernel_linux turbostat X86_MSR warn
244 # vmem.c: /proc/vmstat
245 collectd_plugin_kernel_linux vmem VM_EVENT_COUNTERS warn
247 # vserver.c: /proc/virtual
248 collectd_plugin_kernel_linux vserver VSERVER warn
250 # uuid.c: /sys/hypervisor/uuid
251 collectd_plugin_kernel_linux uuid SYSFS info
253 # wireless.c: /proc/net/wireless
254 collectd_plugin_kernel_linux wireless "WIRELESS MAC80211 IEEE80211" warn
256 # zfs_arc.c: /proc/spl/kstat/zfs/arcstats
257 collectd_plugin_kernel_linux zfs_arc "SPL ZFS" warn
261 if use kernel_linux; then
264 if linux_config_exists; then
265 einfo "Checking your linux kernel configuration:"
266 collectd_linux_kernel_checks
268 elog "Cannot find a linux kernel configuration. Continuing anyway."
272 if use collectd_plugins_java; then
273 java-pkg-opt-2_pkg_setup
276 use collectd_plugins_python && python-single-r1_pkg_setup
279 enewuser collectd -1 -1 /var/lib/collectd collectd
285 # There's some strange prefix handling in the default config file, resulting in
286 # paths like "/usr/var/..."
287 sed -i -e "s:@prefix@/var:/var:g" src/collectd.conf.in || die
289 # Adjust upstream's systemd unit
290 # - Get rid of EnvironmentFile directive; These files don't exist on Gentoo!
291 # - Add User=collectd to run collectd as user "collectd" per default
293 -e '/^EnvironmentFile=.*/d' \
294 -e '/^\[Service\]/aUser=collectd' \
295 contrib/systemd.${PN}.service || die
301 # Now come the lists of os-dependent plugins. Any plugin that is not listed anywhere here
302 # should work independent of the operating system.
304 local linux_plugins="barometer battery cpu cpufreq disk
305 drbd entropy ethstat hugepages interface iptables
306 ipvs irq ipc load memory md netlink nfs numa processes
307 serial swap tcpconns thermal turbostat users vmem wireless
310 local need_libstatgrab=0
311 local libstatgrab_plugins="cpu disk interface load memory swap users"
312 local bsd_plugins="cpu tcpconns ${libstatgrab_plugins} zfc_arc"
314 local darwin_plugins="apple_sensors battery cpu disk interface memory processes tcpconns"
316 local osdependent_plugins="${linux_plugins} ${bsd_plugins} ${darwin_plugins}"
317 local myos_plugins=""
318 if use kernel_linux; then
319 einfo "Enabling Linux plugins."
320 myos_plugins=${linux_plugins}
321 elif use kernel_FreeBSD; then
322 einfo "Enabling FreeBSD plugins."
323 myos_plugins=${bsd_plugins}
324 elif use kernel_Darwin; then
325 einfo "Enabling Darwin plugins."
326 myos_plugins=${darwin_plugins}
329 local myconf="--disable-werror"
332 myconf+=" $(use_enable debug)"
335 # Required for smart plugin via REQUIRED_USE; Optional for disk plugin
337 myconf+=" --with-libudev"
339 myconf+=" --without-libudev"
344 # Disable what needs to be disabled.
345 for plugin in ${COLLECTD_DISABLED_PLUGINS}; do
346 if [[ "${plugin}" == 'dpdkstat' ]]; then
347 myconf+=" --without-libdpdk"
349 myconf+=" --disable-${plugin}"
353 # Set enable/disable for each single plugin.
354 for plugin in ${COLLECTD_ALL_PLUGINS}; do
355 if has ${plugin} ${osdependent_plugins}; then
356 # plugin is os-dependent ...
357 if has ${plugin} ${myos_plugins}; then
358 # ... and available in this os
359 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
360 # ... must we link against libstatgrab? Bug #541518
361 if use kernel_FreeBSD && has ${plugin} ${libstatgrab_plugins}; then
362 einfo "We must link against libstatgrab due to plugin \"${plugin}\" ..."
366 # ... and NOT available in this os
367 if use collectd_plugins_${plugin}; then
368 ewarn "You try to enable the ${plugin} plugin, but it is not available for this"
369 ewarn "kernel. Disabling it automatically."
371 myconf+=" --disable-${plugin}"
373 elif [[ "${plugin}" = "collectd_plugins_perl" ]]; then
374 if use collectd_plugins_perl && ! use perl; then
375 ewarn "Perl plugin disabled as perl bindings disabled by -perl use flag"
376 myconf+= --disable-perl
378 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
381 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
385 if [ "${need_libstatgrab}" -eq 1 ]; then
386 myconf+=" --with-libstatgrab"
388 myconf+=" --without-libstatgrab"
391 # JAVA_HOME is set by eclasses.
392 if use collectd_plugins_java; then
393 myconf+=" --with-java"
396 # Need libiptc ONLY for iptables. If we try to use it otherwise bug 340109 happens.
397 # lots of libs are only needed for plugins, if they are disabled, also disable the lib
398 use collectd_plugins_iptables || myconf+=" --with-libiptc=no"
399 use collectd_plugins_openldap || myconf+=" --with-libldap=no"
400 use collectd_plugins_redis || use collectd_plugins_write_redis || myconf+=" --with-libhiredis=no"
401 use collectd_plugins_smart || myconf+=" --with-libatasmart=no"
402 use collectd_plugins_gps || myconf+=" --with-libgps=no"
405 myconf+=" --with-perl-bindings=INSTALLDIRS=vendor"
407 myconf+=" --without-perl-bindings"
410 # No need for v5upgrade
411 myconf+=" --disable-target_v5upgrade"
414 if use collectd_plugins_python; then
415 myconf+=" --with-libpython=yes"
416 export PYTHON_CONFIG=$(python_get_PYTHON_CONFIG)
418 myconf+=" --with-libpython=no"
422 myconf+=" $(use_enable xfs)"
424 # Finally, run econf.
425 KERNEL_DIR="${KERNEL_DIR}" econf --config-cache \
426 $(use_enable static-libs static) \
427 --localstatedir=/var ${myconf}
431 emake DESTDIR="${D%/}" install
435 find "${ED}"usr/ -name "*.la" -delete || die
437 if use collectd_plugins_java; then
438 java-pkg_regjar "${ED}"usr/share/${PN}/java/*.jar
441 fowners root:collectd /etc/collectd.conf
442 fperms u=rw,g=r,o= /etc/collectd.conf
444 dodoc AUTHORS ChangeLog README
446 if use contrib ; then
447 insinto /usr/share/${PN}
451 keepdir /var/lib/${PN}
452 fowners collectd:collectd /var/lib/${PN}
454 newinitd "${FILESDIR}/${PN}.initd-r2" ${PN}
455 newconfd "${FILESDIR}/${PN}.confd-r2" ${PN}
456 systemd_newunit "contrib/systemd.${PN}.service" ${PN}.service
458 insinto /etc/logrotate.d
459 newins "${FILESDIR}/${PN}.logrotate" ${PN}
461 newtmpfiles "${FILESDIR}"/${PN}.tmpfile ${PN}.conf
463 sed -i -e 's:^.*PIDFile "/var/run/collectd.pid":#PIDFile "/run/collectd.pid":' "${ED}"etc/collectd.conf || die
464 sed -i -e 's:^# SocketFile "/var/run/collectd-unixsock":# SocketFile "/run/collectd/collectd.socket":' "${ED}"etc/collectd.conf || die
465 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
466 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
470 tmpfiles_process "${PN}.conf"
472 if use filecaps; then
474 use collectd_plugins_ceph && caps+=('CAP_DAC_OVERRIDE')
475 use collectd_plugins_exec && caps+=('CAP_SETUID' 'CAP_SETGID')
476 use collectd_plugins_iptables && caps+=('CAP_NET_ADMIN')
477 use collectd_plugins_filecount && caps+=('CAP_DAC_READ_SEARCH')
479 if use collectd_plugins_dns || use collectd_plugins_ping; then
480 caps+=('CAP_NET_RAW')
483 if use collectd_plugins_turbostat || use collectd_plugins_smart; then
484 caps+=('CAP_SYS_RAWIO')
487 if [ ${#caps[@]} -gt 0 ]; then
488 local caps_str=$(IFS=","; echo "${caps[*]}")
489 fcaps ${caps_str} usr/sbin/collectd
490 elog "Capabilities for ${EROOT}usr/sbin/collectd set to:"
491 elog " ${caps_str}+EP"
494 local systemd_unit="$(systemd_get_systemunitdir)/collectd.service"
495 if [[ -e "${systemd_unit}" ]]; then
496 caps_str="${caps[*]}"
497 sed -i -e "s:^CapabilityBoundingSet=.*:CapabilityBoundingSet=${caps_str}:" "${systemd_unit}" || \
498 die "Failed to set CapabilityBoundingSet in '${systemd_unit}'"
500 elog "CapabilityBoundingSet in '${systemd_unit}'"
501 elog "updated to match capabilities set above."
504 if has_version "sys-apps/systemd"; then
506 ewarn "Failed to update CapabilityBoundingSet in '${systemd_unit}'"
507 ewarn "because unit was not found. Please file a bug about this."
513 elog "Note: Collectd is only the collector."
514 elog " You need to install 'data' sources (applications) locally or"
515 elog " remotely on your own."
518 elog "Collectd is configured to run as unprivileged user by default."
519 elog "You may want to revisit the configuration."
522 if use collectd_plugins_email; then
523 ewarn "The email plug-in is deprecated. To submit statistics please use the unixsock plugin."
526 if use collectd_plugins_smart; then
528 elog "If you are using smart plugin and don't run collectd as root make sure"
529 elog "that the collectd user is allowed to access the disk you want to monitor"
530 elog "(can be done via udev rule for example) and that collectd has the required"
531 elog "capabilities set (which is the default when package was emerged with"
532 elog "'filecaps' USE flag set)."
536 elog "The scripts in /usr/share/doc/${PF}/collection3 for generating graphs need dev-perl/HTML-Parser,"
537 elog "dev-perl/config-general, dev-perl/regexp-common, and net-analyzer/rrdtool[perl] to be installed."