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/${P}/${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 # dpdk_telemetry: Requires dpdk
31 # grpc: Requires libgrpc
32 # intel_pmu: Requires libjevents (pmu-tools)
33 # intel_rdt: Requires libpqos from intel-cmt-cat project
34 # lpar: Requires libperfstat (AIX only)
35 # mic: Requires Intel Many Integrated Core Architecture API
36 # (part of Intel's Xeon Phi software)
37 # netapp: Requires libnetapp (http://communities.netapp.com/docs/DOC-1110)
38 # pf: Requires BSD packet filter
39 # pinba: Requires MySQL Pinba engine (http://pinba.org/)
40 # redfish: Requires libredfish
41 # tape: Requires libkstat (Solaris only)
42 # tokyotyrant: Requires tokyotyrant
43 # write_riemann: Requires riemann-c-client
44 # xmms: Requires libxmms (v1)
45 # zone: Solaris only...
46 COLLECTD_IMPOSSIBLE_PLUGINS="apple_sensors amqp1 aquaero barometer
47 dpdkevents dpdkstat dpdk_telemetry grpc intel_pmu intel_rdt lpar
48 mic netapp pf pinba redfish tape tokyotyrant write_riemann xmms zone"
50 # Plugins that have been (compile) tested and can be enabled via COLLECTD_PLUGINS
51 COLLECTD_TESTED_PLUGINS="aggregation amqp apache apcups ascent battery bind
52 buddyinfo capabilities ceph cgroups check_uptime chrony conntrack
53 contextswitch cpu cpufreq cpusleep csv curl curl_json curl_xml
54 dbi df disk dns drbd email entropy ethstat exec fhcount filecount
55 fscache gmond gps hddtemp hugepages interface ipc ipmi iptables
56 ipvs irq java lua load logfile logparser log_logstash madwifi
57 match_empty_counter match_hashed match_regex match_timediff
58 match_value mbmon mcelog md memcachec memcached memory modbus mqtt
59 multimeter mysql netlink network network nfs nginx notify_desktop
60 notify_email notify_nagios ntpd numa nut olsrd onewire openldap
61 openvpn oracle ovs_events ovs_stats pcie_errors perl ping postgresql
62 powerdns procevent processes protocols python python redis routeros
63 rrdcached rrdtool sensors serial sigrok slurm smart snmp snmp_agent
64 statsd swap synproxy sysevent syslog table tail tail_csv
65 target_notification target_replace target_scale target_set tcpconns
66 teamspeak2 ted thermal threshold turbostat ubi unixsock uptime users
67 uuid varnish virt vmem vserver wireless write_graphite write_http
68 write_influxdb_udp write_kafka write_log write_mongodb write_prometheus
69 write_redis write_sensu write_stackdriver write_syslog write_tsdb
70 xencpu zfs_arc zookeeper"
72 COLLECTD_DISABLED_PLUGINS="${COLLECTD_IMPOSSIBLE_PLUGINS}"
74 COLLECTD_ALL_PLUGINS=${COLLECTD_TESTED_PLUGINS}
76 for plugin in ${COLLECTD_ALL_PLUGINS}; do
77 IUSE="${IUSE} collectd_plugins_${plugin}"
81 # Now come the dependencies.
86 perl? ( dev-lang/perl:=[ithreads] )
87 udev? ( virtual/udev )
88 xfs? ( sys-fs/xfsprogs )
89 collectd_plugins_amqp? ( net-libs/rabbitmq-c )
90 collectd_plugins_apache? ( net-misc/curl:0= )
91 collectd_plugins_ascent? ( net-misc/curl:0= dev-libs/libxml2:2= )
92 collectd_plugins_bind? ( net-misc/curl:0= dev-libs/libxml2:2= )
93 collectd_plugins_ceph? ( dev-libs/yajl:= )
94 collectd_plugins_capabilities? ( sys-libs/libcap dev-libs/jansson net-libs/libmicrohttpd:= )
95 collectd_plugins_curl? ( net-misc/curl:0= )
96 collectd_plugins_curl_json? ( net-misc/curl:0= dev-libs/yajl:= )
97 collectd_plugins_curl_xml? ( net-misc/curl:0= dev-libs/libxml2:2= )
98 collectd_plugins_dbi? ( dev-db/libdbi )
99 collectd_plugins_dns? ( net-libs/libpcap )
100 collectd_plugins_gmond? ( sys-cluster/ganglia )
101 collectd_plugins_gps? ( sci-geosciences/gpsd:= )
102 collectd_plugins_ipmi? ( >=sys-libs/openipmi-2.0.16-r1 )
103 collectd_plugins_iptables? ( >=net-firewall/iptables-1.4.13:0= )
104 collectd_plugins_log_logstash? ( dev-libs/yajl:= )
105 collectd_plugins_lua? ( dev-lang/lua:0= )
106 collectd_plugins_memcachec? ( dev-libs/libmemcached )
107 collectd_plugins_modbus? ( dev-libs/libmodbus )
108 collectd_plugins_mqtt? ( app-misc/mosquitto )
109 collectd_plugins_mysql? ( dev-db/mysql-connector-c:= )
110 collectd_plugins_netlink? ( net-libs/libmnl )
111 collectd_plugins_nginx? ( net-misc/curl:0= )
112 collectd_plugins_notify_desktop? ( x11-libs/libnotify )
113 collectd_plugins_notify_email? ( net-libs/libesmtp )
114 collectd_plugins_nut? ( >=sys-power/nut-2.7.2-r2 )
115 collectd_plugins_openldap? ( net-nds/openldap )
116 collectd_plugins_onewire? ( >=sys-fs/owfs-3.1:= )
117 collectd_plugins_oracle? ( dev-db/oracle-instantclient-basic )
118 collectd_plugins_ovs_events? ( dev-libs/yajl:= )
119 collectd_plugins_ovs_stats? ( dev-libs/yajl:= )
120 collectd_plugins_perl? ( dev-lang/perl:=[ithreads] )
121 collectd_plugins_ping? ( net-libs/liboping )
122 collectd_plugins_postgresql? ( dev-db/postgresql:= )
123 collectd_plugins_procevent? ( dev-libs/yajl:= )
124 collectd_plugins_python? ( ${PYTHON_DEPS} )
125 collectd_plugins_redis? ( dev-libs/hiredis:= )
126 collectd_plugins_routeros? ( net-libs/librouteros )
127 collectd_plugins_rrdcached? ( net-analyzer/rrdtool:= )
128 collectd_plugins_rrdtool? ( net-analyzer/rrdtool:= )
129 collectd_plugins_sensors? ( sys-apps/lm-sensors:= )
130 collectd_plugins_sigrok? ( <sci-libs/libsigrok-0.4:= dev-libs/glib:2 )
131 collectd_plugins_slurm? ( sys-cluster/slurm )
132 collectd_plugins_snmp? ( net-analyzer/net-snmp )
133 collectd_plugins_snmp_agent? ( net-analyzer/net-snmp )
134 collectd_plugins_sysevent? ( dev-libs/yajl:= )
135 collectd_plugins_varnish? ( www-servers/varnish:= )
136 collectd_plugins_virt? ( app-emulation/libvirt:= dev-libs/libxml2:2= )
137 collectd_plugins_write_http? ( net-misc/curl:0= dev-libs/yajl:= )
138 collectd_plugins_write_kafka? ( >=dev-libs/librdkafka-0.9.0.99:= dev-libs/yajl:= )
139 collectd_plugins_write_mongodb? ( >=dev-libs/mongo-c-driver-1.8.2:= )
140 collectd_plugins_write_prometheus? ( >=dev-libs/protobuf-c-1.2.1-r1:= net-libs/libmicrohttpd:= )
141 collectd_plugins_write_redis? ( dev-libs/hiredis:= )
142 collectd_plugins_write_stackdriver? ( net-misc/curl:0= dev-libs/yajl:= )
143 collectd_plugins_xencpu? ( app-emulation/xen-tools:= )
146 collectd_plugins_disk? ( sys-libs/libstatgrab:= )
147 collectd_plugins_interface? ( sys-libs/libstatgrab:= )
148 collectd_plugins_load? ( sys-libs/libstatgrab:= )
149 collectd_plugins_memory? ( sys-libs/libstatgrab:= )
150 collectd_plugins_swap? ( sys-libs/libstatgrab:= )
151 collectd_plugins_users? ( sys-libs/libstatgrab:= )
154 # Enforcing !=sys-kernel/linux-headers-4.5 > due to #577846
155 DEPEND="${COMMON_DEPEND}
156 collectd_plugins_iptables? ( || ( <=sys-kernel/linux-headers-4.4 >=sys-kernel/linux-headers-4.6 ) )
157 collectd_plugins_java? ( >=virtual/jdk-1.6 )
160 RDEPEND="${COMMON_DEPEND}
161 collectd_plugins_java? ( >=virtual/jre-1.6 )
162 collectd_plugins_syslog? ( virtual/logger )
163 selinux? ( sec-policy/selinux-collectd )"
166 collectd_plugins_python? ( ${PYTHON_REQUIRED_USE} )
167 collectd_plugins_smart? ( udev )
170 # @FUNCTION: collectd_plugin_kernel_linux
172 # USAGE: <plugin name> <kernel_options> <severity>
173 # kernel_options is a list of kernel configurations options; the check tests whether at least
174 # one of them is enabled. If no, depending on the third argument an elog, ewarn, or eerror message
176 collectd_plugin_kernel_linux() {
178 if has ${1} ${COLLECTD_ALL_PLUGINS}; then
179 if use collectd_plugins_${1}; then
181 if linux_chkconfig_present ${opt}; then
185 multi_opt=${2//\ /\ or\ }
188 elog "The ${1} plugin can use kernel features that are disabled now; enable ${multi_opt} in your kernel"
191 ewarn "The ${1} plugin uses kernel features that are disabled now; enable ${multi_opt} in your kernel"
194 eerror "The ${1} plugin needs kernel features that are disabled now; enable ${multi_opt} in your kernel"
197 die "function collectd_plugin_kernel_linux called with invalid third argument"
204 collectd_linux_kernel_checks() {
205 if ! linux_chkconfig_present PROC_FS; then
206 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"
209 if ! linux_chkconfig_present SYSFS; then
210 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"
213 # battery.c: /proc/pmu/battery_%i
214 # battery.c: /proc/acpi/battery
215 collectd_plugin_kernel_linux battery ACPI_BATTERY warn
217 # cgroups.c: /sys/fs/cgroup/
218 collectd_plugin_kernel_linux cgroups CGROUPS warn
220 # cpufreq.c: /sys/devices/system/cpu/cpu%d/cpufreq/
221 collectd_plugin_kernel_linux cpufreq SYSFS warn
222 collectd_plugin_kernel_linux cpufreq CPU_FREQ_STAT warn
225 collectd_plugin_kernel_linux drbd BLK_DEV_DRBD warn
227 # conntrack.c: /proc/sys/net/netfilter/*
228 collectd_plugin_kernel_linux conntrack NETFILTER warn
230 # fscache.c: /proc/fs/fscache/stats
231 collectd_plugin_kernel_linux fscache FSCACHE warn
233 # nfs.c: /proc/net/rpc/nfs
234 # nfs.c: /proc/net/rpc/nfsd
235 collectd_plugin_kernel_linux nfs NFS_COMMON warn
237 # serial.c: /proc/tty/driver/serial
238 # serial.c: /proc/tty/driver/ttyS
239 collectd_plugin_kernel_linux serial SERIAL_CORE warn
241 # swap.c: /proc/meminfo
242 collectd_plugin_kernel_linux swap SWAP warn
244 # thermal.c: /proc/acpi/thermal_zone
245 # thermal.c: /sys/class/thermal
246 collectd_plugin_kernel_linux thermal ACPI_THERMAL warn
248 # turbostat.c: /dev/cpu/%d/msr
249 collectd_plugin_kernel_linux turbostat X86_MSR warn
251 # vmem.c: /proc/vmstat
252 collectd_plugin_kernel_linux vmem VM_EVENT_COUNTERS warn
254 # vserver.c: /proc/virtual
255 collectd_plugin_kernel_linux vserver VSERVER warn
257 # uuid.c: /sys/hypervisor/uuid
258 collectd_plugin_kernel_linux uuid SYSFS info
260 # wireless.c: /proc/net/wireless
261 collectd_plugin_kernel_linux wireless "WIRELESS MAC80211 IEEE80211" warn
263 # zfs_arc.c: /proc/spl/kstat/zfs/arcstats
264 collectd_plugin_kernel_linux zfs_arc "SPL ZFS" warn
268 if use kernel_linux; then
271 if linux_config_exists; then
272 einfo "Checking your linux kernel configuration:"
273 collectd_linux_kernel_checks
275 elog "Cannot find a linux kernel configuration. Continuing anyway."
279 if use collectd_plugins_java; then
280 java-pkg-opt-2_pkg_setup
283 use collectd_plugins_python && python-single-r1_pkg_setup
286 enewuser collectd -1 -1 /var/lib/collectd collectd
292 # There's some strange prefix handling in the default config file, resulting in
293 # paths like "/usr/var/..."
294 sed -i -e "s:@prefix@/var:/var:g" src/collectd.conf.in || die
296 # Adjust upstream's systemd unit
297 # - Get rid of EnvironmentFile directive; These files don't exist on Gentoo!
298 # - Add User=collectd to run collectd as user "collectd" per default
300 -e '/^EnvironmentFile=.*/d' \
301 -e '/^\[Service\]/aUser=collectd' \
302 contrib/systemd.${PN}.service || die
308 # Now come the lists of os-dependent plugins. Any plugin that is not listed anywhere here
309 # should work independent of the operating system.
311 local linux_plugins="barometer battery cpu cpufreq disk
312 drbd entropy ethstat hugepages interface iptables
313 ipvs irq ipc load memory md netlink nfs numa processes
314 serial swap tcpconns thermal turbostat users vmem wireless
317 local need_libstatgrab=0
318 local libstatgrab_plugins="cpu disk interface load memory swap users"
319 local bsd_plugins="cpu tcpconns ${libstatgrab_plugins} zfc_arc"
321 local darwin_plugins="apple_sensors battery cpu disk interface memory processes tcpconns"
323 local osdependent_plugins="${linux_plugins} ${bsd_plugins} ${darwin_plugins}"
324 local myos_plugins=""
325 if use kernel_linux; then
326 einfo "Enabling Linux plugins."
327 myos_plugins=${linux_plugins}
328 elif use kernel_FreeBSD; then
329 einfo "Enabling FreeBSD plugins."
330 myos_plugins=${bsd_plugins}
331 elif use kernel_Darwin; then
332 einfo "Enabling Darwin plugins."
333 myos_plugins=${darwin_plugins}
336 local myconf="--disable-werror"
339 myconf+=" $(use_enable debug)"
342 # Required for smart plugin via REQUIRED_USE; Optional for disk plugin
344 myconf+=" --with-libudev"
346 myconf+=" --without-libudev"
351 # Disable what needs to be disabled.
352 for plugin in ${COLLECTD_DISABLED_PLUGINS}; do
353 if [[ "${plugin}" == 'dpdkstat' ]]; then
354 myconf+=" --without-libdpdk"
356 myconf+=" --disable-${plugin}"
360 # Set enable/disable for each single plugin.
361 for plugin in ${COLLECTD_ALL_PLUGINS}; do
362 if has ${plugin} ${osdependent_plugins}; then
363 # plugin is os-dependent ...
364 if has ${plugin} ${myos_plugins}; then
365 # ... and available in this os
366 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
367 # ... must we link against libstatgrab? Bug #541518
368 if use kernel_FreeBSD && has ${plugin} ${libstatgrab_plugins}; then
369 einfo "We must link against libstatgrab due to plugin \"${plugin}\" ..."
373 # ... and NOT available in this os
374 if use collectd_plugins_${plugin}; then
375 ewarn "You try to enable the ${plugin} plugin, but it is not available for this"
376 ewarn "kernel. Disabling it automatically."
378 myconf+=" --disable-${plugin}"
380 elif [[ "${plugin}" = "collectd_plugins_perl" ]]; then
381 if use collectd_plugins_perl && ! use perl; then
382 ewarn "Perl plugin disabled as perl bindings disabled by -perl use flag"
383 myconf+= --disable-perl
385 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
388 myconf+=" $(use_enable collectd_plugins_${plugin} ${plugin})"
392 if [ "${need_libstatgrab}" -eq 1 ]; then
393 myconf+=" --with-libstatgrab"
395 myconf+=" --without-libstatgrab"
398 # JAVA_HOME is set by eclasses.
399 if use collectd_plugins_java; then
400 myconf+=" --with-java"
403 # Need libiptc ONLY for iptables. If we try to use it otherwise bug 340109 happens.
404 # lots of libs are only needed for plugins, if they are disabled, also disable the lib
405 use collectd_plugins_iptables || myconf+=" --with-libiptc=no"
406 use collectd_plugins_openldap || myconf+=" --with-libldap=no"
407 use collectd_plugins_redis || use collectd_plugins_write_redis || myconf+=" --with-libhiredis=no"
408 use collectd_plugins_smart || myconf+=" --with-libatasmart=no"
409 use collectd_plugins_gps || myconf+=" --with-libgps=no"
412 myconf+=" --with-perl-bindings=INSTALLDIRS=vendor"
414 myconf+=" --without-perl-bindings"
417 # No need for v5upgrade
418 myconf+=" --disable-target_v5upgrade"
421 if use collectd_plugins_python; then
422 myconf+=" --with-libpython=yes"
423 export PYTHON_CONFIG=$(python_get_PYTHON_CONFIG)
425 myconf+=" --with-libpython=no"
429 myconf+=" $(use_enable xfs)"
431 # Finally, run econf.
432 KERNEL_DIR="${KERNEL_DIR}" econf --config-cache \
433 $(use_enable static-libs static) \
434 --localstatedir=/var ${myconf}
438 emake DESTDIR="${D%/}" install
442 find "${ED}"usr/ -name "*.la" -delete || die
444 if use collectd_plugins_java; then
445 java-pkg_regjar "${ED}"usr/share/${PN}/java/*.jar
448 fowners root:collectd /etc/collectd.conf
449 fperms u=rw,g=r,o= /etc/collectd.conf
451 dodoc AUTHORS ChangeLog README
453 if use contrib ; then
454 insinto /usr/share/${PN}
458 keepdir /var/lib/${PN}
459 fowners collectd:collectd /var/lib/${PN}
461 newinitd "${FILESDIR}/${PN}.initd-r2" ${PN}
462 newconfd "${FILESDIR}/${PN}.confd-r2" ${PN}
463 systemd_newunit "contrib/systemd.${PN}.service" ${PN}.service
465 insinto /etc/logrotate.d
466 newins "${FILESDIR}/${PN}.logrotate" ${PN}
468 newtmpfiles "${FILESDIR}"/${PN}.tmpfile ${PN}.conf
470 sed -i -e 's:^.*PIDFile "/var/run/collectd.pid":#PIDFile "/run/collectd.pid":' "${ED}"etc/collectd.conf || die
471 sed -i -e 's:^# SocketFile "/var/run/collectd-unixsock":# SocketFile "/run/collectd/collectd.socket":' "${ED}"etc/collectd.conf || die
472 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
473 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
477 tmpfiles_process "${PN}.conf"
479 if use filecaps; then
481 use collectd_plugins_ceph && caps+=('CAP_DAC_OVERRIDE')
482 use collectd_plugins_exec && caps+=('CAP_SETUID' 'CAP_SETGID')
483 use collectd_plugins_iptables && caps+=('CAP_NET_ADMIN')
484 use collectd_plugins_filecount && caps+=('CAP_DAC_READ_SEARCH')
486 if use collectd_plugins_dns || use collectd_plugins_ping; then
487 caps+=('CAP_NET_RAW')
490 if use collectd_plugins_turbostat || use collectd_plugins_smart; then
491 caps+=('CAP_SYS_RAWIO')
494 if [ ${#caps[@]} -gt 0 ]; then
495 local caps_str=$(IFS=","; echo "${caps[*]}")
496 fcaps ${caps_str} usr/sbin/collectd
497 elog "Capabilities for ${EROOT}usr/sbin/collectd set to:"
498 elog " ${caps_str}+EP"
501 local systemd_unit="$(systemd_get_systemunitdir)/collectd.service"
502 if [[ -e "${systemd_unit}" ]]; then
503 caps_str="${caps[*]}"
504 sed -i -e "s:^CapabilityBoundingSet=.*:CapabilityBoundingSet=${caps_str}:" "${systemd_unit}" || \
505 die "Failed to set CapabilityBoundingSet in '${systemd_unit}'"
507 elog "CapabilityBoundingSet in '${systemd_unit}'"
508 elog "updated to match capabilities set above."
511 if has_version "sys-apps/systemd"; then
513 ewarn "Failed to update CapabilityBoundingSet in '${systemd_unit}'"
514 ewarn "because unit was not found. Please file a bug about this."
520 elog "Note: Collectd is only the collector."
521 elog " You need to install 'data' sources (applications) locally or"
522 elog " remotely on your own."
525 elog "Collectd is configured to run as unprivileged user by default."
526 elog "You may want to revisit the configuration."
529 if use collectd_plugins_email; then
530 ewarn "The email plug-in is deprecated. To submit statistics please use the unixsock plugin."
533 if use collectd_plugins_smart; then
535 elog "If you are using smart plugin and don't run collectd as root make sure"
536 elog "that the collectd user is allowed to access the disk you want to monitor"
537 elog "(can be done via udev rule for example) and that collectd has the required"
538 elog "capabilities set (which is the default when package was emerged with"
539 elog "'filecaps' USE flag set)."
543 elog "The scripts in /usr/share/doc/${PF}/collection3 for generating graphs need dev-perl/HTML-Parser,"
544 elog "dev-perl/CGI, dev-perl/Config-General and net-analyzer/rrdtool[perl] to be installed."