Browse Source

collectd: add uci config support

Add uci config support.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
lilik-openwrt-22.03
Florian Eckert 5 years ago
parent
commit
3d15ebca31
33 changed files with 563 additions and 45 deletions
  1. +13
    -4
      utils/collectd/Makefile
  2. +0
    -39
      utils/collectd/files/collectd.conf
  3. +200
    -2
      utils/collectd/files/collectd.init
  4. +160
    -0
      utils/collectd/files/collectd.uci
  5. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/conntrack.json
  6. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/contextswitch.json
  7. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/cpu.json
  8. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/cpufreq.json
  9. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/csv.json
  10. +10
    -0
      utils/collectd/files/usr/share/collectd/plugin/df.json
  11. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/disk.json
  12. +6
    -0
      utils/collectd/files/usr/share/collectd/plugin/dns.json
  13. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/email.json
  14. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/entropy.json
  15. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/exec.json
  16. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/interface.json
  17. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/irq.json
  18. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/iwinfo.json
  19. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/load.json
  20. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/lua.json
  21. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/memory.json
  22. +12
    -0
      utils/collectd/files/usr/share/collectd/plugin/netlink.json
  23. +5
    -0
      utils/collectd/files/usr/share/collectd/plugin/nut.json
  24. +9
    -0
      utils/collectd/files/usr/share/collectd/plugin/olsrd.json
  25. +11
    -0
      utils/collectd/files/usr/share/collectd/plugin/openvpn.json
  26. +9
    -0
      utils/collectd/files/usr/share/collectd/plugin/ping.json
  27. +5
    -0
      utils/collectd/files/usr/share/collectd/plugin/processes.json
  28. +17
    -0
      utils/collectd/files/usr/share/collectd/plugin/rrdtool.json
  29. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/sensors.json
  30. +9
    -0
      utils/collectd/files/usr/share/collectd/plugin/tcpconns.json
  31. +8
    -0
      utils/collectd/files/usr/share/collectd/plugin/thermal.json
  32. +7
    -0
      utils/collectd/files/usr/share/collectd/plugin/unixsock.json
  33. +2
    -0
      utils/collectd/files/usr/share/collectd/plugin/uptime.json

+ 13
- 4
utils/collectd/Makefile View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=collectd
PKG_VERSION:=5.8.1
PKG_RELEASE:=5
PKG_RELEASE:=6
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=https://collectd.org/files/ \
@ -200,6 +200,7 @@ $(call Package/collectd/Default)
+zlib \
+libltdl \
+libip4tc \
+jshn \
+PACKAGE_collectd-mod-lua:liblua
MENU:=1
endef
@ -298,18 +299,21 @@ endif
define Package/collectd/conffiles
/etc/collectd.conf
/etc/config/collectd
endef
define Package/collectd/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/collectd $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/usr/share/collectd
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/collectd/types.db $(1)/usr/share/collectd/
$(INSTALL_DIR) $(1)/etc
$(INSTALL_CONF) ./files/collectd.conf $(1)/etc/
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/collectd.init $(1)/etc/init.d/collectd
$(INSTALL_DIR) $(1)/etc/collectd/conf.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) files/collectd.uci $(1)/etc/config/collectd
endef
# 1: plugin name
@ -333,6 +337,11 @@ define BuildPlugin
$(PKG_INSTALL_DIR)/usr/lib/collectd/$$$$$$$${m}.so \
$$(1)/usr/lib/collectd/ ; \
done
if [ -f ./files/usr/share/collectd/plugin/$(1).json ]; then \
$(INSTALL_DIR) $$(1)/usr/share/collectd/plugin ; \
$(INSTALL_DATA) ./files/usr/share/collectd/plugin/$(1).json \
$$(1)/usr/share/collectd/plugin/$(1).json ; \
fi
endef
$$(eval $$(call BuildPackage,collectd-mod-$(1)))


+ 0
- 39
utils/collectd/files/collectd.conf View File

@ -1,39 +0,0 @@
# Config file for collectd. More info: https://collectd.org/
# Note: Luci statistics will generate a new config and overwrite this file.
#Hostname "localhost"
#FQDNLookup true
BaseDir "/var/run/collectd"
Include "/etc/collectd/conf.d"
PIDFile "/var/run/collectd.pid"
PluginDir "/usr/lib/collectd"
TypesDB "/usr/share/collectd/types.db"
Interval 30
ReadThreads 2
LoadPlugin interface
LoadPlugin load
#LoadPlugin ping
LoadPlugin rrdtool
<Plugin rrdtool>
DataDir "/tmp/rrd"
RRARows 100
RRASingle true
RRATimespan 3600
RRATimespan 86400
RRATimespan 604800
RRATimespan 2678400
RRATimespan 31622400
</Plugin>
<Plugin interface>
IgnoreSelected false
Interface "br-lan"
</Plugin>
#<Plugin ping>
# Host "host.foo.bar"
# Interval 30
# TTL 127
#</Plugin>

+ 200
- 2
utils/collectd/files/collectd.init View File

@ -1,17 +1,215 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2016 OpenWrt.org
. "/usr/share/libubox/jshn.sh"
START=80
STOP=10
USE_PROCD=1
COLLECTD_CONF="/tmp/collectd.conf"
LOG="logger -t collectd[$$] -p"
NICEPRIO=5
CONFIG_STRING=""
process_exec() {
printf "<Plugin exec>\n" >> "$COLLECTD_CONF"
config_foreach process_exec_sections exec_input "Exec"
config_foreach process_exec_sections exec_notify "NotificationExec"
printf "</Plugin>\n\n" >> "$COLLECTD_CONF"
}
process_exec_sections() {
local cfg="$1"
local section="$2"
local cmdline cmduser cmdgroup
config_get cmdline "$cfg" cmdline
[ -z "$cmdline" ] && {
$LOG notice "No cmdline option in config $cfg defined"
return 0
}
config_get cmduser "$cfg" cmduser
[ -z "$cmduser" ] && {
$LOG notice "No cmduser option in config $cfg defined"
return 0
}
config_get cmdgroup "$cfg" cmdgroup
if [ -z "$cmdgroup" ]; then
printf "\\t%s \"%s\" \"%s\"\n" "${section}" "${cmduser}" "${cmdline}" >> "$COLLECTD_CONF"
else
printf "\\t%s \"%s:%s\" \"%s\"\n" "${section}" "${cmduser}" "${cmdgroup}" "${cmdline}" >> "$COLLECTD_CONF"
fi
}
CONFIG_LIST=""
add_list_option() {
local value="$1"
local option="$2"
local indent="$3"
CONFIG_LIST="${CONFIG_LIST}${indent}${option} \"$value\"\n"
}
process_generic() {
local cfg="$1"
local indent="$2"
local json="$3"
local config=""
json_init
json_load_file "$json"
json_select string 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
json_get_keys keys
for key in ${keys}; do
json_get_var option "$key"
config_get value "$cfg" "$option" ""
[ -z "$value" ] || {
config="${config}${indent}${option} \"${value}\"\n"
}
done
json_select ..
fi
json_select bool 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
json_get_keys keys
for key in ${keys}; do
json_get_var option "$key"
config_get_bool value "$cfg" "$option"
if [ "$value" = "0" ]; then
config="${config}${indent}${option} false\n"
fi
if [ "$value" = "1" ]; then
config="${config}${indent}${option} true\n"
fi
done
json_select ..
fi
json_select list 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
json_get_keys keys
for key in ${keys}; do
json_get_var option "$key"
CONFIG_LIST=""
config_list_foreach "$cfg" "$option" add_list_option "$option" "$indent"
config="${config}${CONFIG_LIST}"
done
json_select ..
fi
[ -z "$config" ] || {
printf "%s<Plugin %s>\n" "${CONFIG_STRING}" "$cfg" >> "$COLLECTD_CONF"
echo -e "${config}" >> "$COLLECTD_CONF"
printf "%s</Plugin>\n" "${CONFIG_STRING}" >> "$COLLECTD_CONF"
}
printf "\n" >> "$COLLECTD_CONF"
}
process_plugins() {
local cfg="$1"
local enable keys key option value
config_get enable "$cfg" enable 0
[ "$enable" = "1" ] || return 0
[ -f "/usr/lib/collectd/$cfg.so" ] || {
$LOG notice "Plugin collectd-mod-$cfg not installed"
return 0
}
[ -f "/usr/share/collectd/plugin/$cfg.json" ] || {
$LOG notice "Configuration definition file for $cfg not found"
return 0
}
printf "LoadPlugin %s\n" "$cfg" >> "$COLLECTD_CONF"
case "$cfg" in
exec)
CONFIG_STRING=""
process_exec
;;
*)
CONFIG_STRING=""
process_generic "$cfg" "\\t" "/usr/share/collectd/plugin/$cfg.json"
;;
esac
}
process_config() {
local alt_config_file BaseDir Include PIDFile PluginDir TypesDB
local Interval ReadThreads Hostname
rm -f "$COLLECTD_CONF"
[ -f /etc/config/collectd ] || {
$LOG notice "UCI config not found"
return 0
}
config_load collectd
config_get alt_config_file globals alt_config_file
# If "alt_config_file" specified, use that instead
[ -n "$alt_config_file" ] && [ -f "$alt_config_file" ] && {
rm -f "$COLLECTD_CONF"
ln -s "$alt_config_file" "$COLLECTD_CONF"
return 0
}
# GOBAL CONFIG
config_get BaseDir globals BaseDir "/var/run/collectd"
printf "BaseDir \"%s\"\n" "$BaseDir" >> "$COLLECTD_CONF"
config_get Include globals Include "/tmp/collectd.d"
printf "Include \"%s\"\n" "$Include" >> "$COLLECTD_CONF"
mkdir -p "$Include"
config_get PIDFile globals PIDFile "/var/run/collectd.pid"
printf "PIDFile \"%s\"\n" "$PIDFile" >> "$COLLECTD_CONF"
config_get PluginDir globals PluginDir "/usr/lib/collectd"
printf "PluginDir \"%s\"\n" "$PluginDir" >> "$COLLECTD_CONF"
config_get TypesDB globals TypesDB "/usr/share/collectd/types.db"
printf "TypesDB \"%s\"\n" "$TypesDB" >> "$COLLECTD_CONF"
config_get Interval globals Interval 30
printf "Interval \"%s\"\n" "$Interval" >> "$COLLECTD_CONF"
config_get ReadThreads globals ReadThreads 2
printf "ReadThreads \"%s\"\n" "$ReadThreads" >> "$COLLECTD_CONF"
config_get Hostname globals Hostname "$(hostname)"
printf "Hostname \"%s\"\n" "$Hostname" >> "$COLLECTD_CONF"
printf "\n" >> "$COLLECTD_CONF"
# PLUGIN CONFIG
config_foreach process_plugins plugin
}
start_service() {
mkdir -m 0755 -p /var/lib/collectd
procd_open_instance
procd_set_param command /usr/sbin/collectd -f
procd_set_param command /usr/sbin/collectd
procd_append_param command -C "$COLLECTD_CONF"
procd_append_param command -f # don't daemonize, procd will handle that for us
procd_set_param nice "$NICEPRIO"
process_config
# set auto respawn behavior
procd_set_param respawn
procd_close_instance
}

+ 160
- 0
utils/collectd/files/collectd.uci View File

@ -0,0 +1,160 @@
config globals 'globals'
option alt_config_file "/etc/collectd.conf"
# option BaseDir '/var/run/collectd'
# option Include '/tmp/collectd.d'
# option PIDFile '/var/run/collectd.pid'
# option PluginDir '/usr/lib/collectd'
# option TypesDB '/usr/share/collectd/types.db'
# option Interval '30'
# option ReadThreads '2'
#config plugin 'conntrack'
# option enable '0'
#config plugin 'contextswitch'
# option enable '0'
#config plugin 'cpu'
# option enable '0'
#config plugin 'cpufreq'
# option enable '0'
#config plugin 'csv'
# option enable '0'
# option StoreRates '0'
# option DataDir '/tmp'
#config plugin 'df'
# option enable '0'
# list Device '/dev/mtdblock/4'
# list MountPoint '/jffs'
# list FSType 'tmpfs'
# option IgnoreSelected '0'
#config plugin 'disk'
# option enable '0'
# list Disk 'hda1'
# list Disk 'hdb'
# option IgnoreSelected '0'
#config plugin 'dns'
# option enable '0'
# list Interface 'br-lan'
# list IgnoreSource '127.0.0.1'
#config plugin 'email'
# option enable '0'
# option SocketFile '/var/run/collectd/email.sock'
# option SocketGroup 'nogroup'
#config plugin 'entropy'
# option enable '0'
#config plugin 'exec'
# option enable '0'
#config exec_input
# option cmdline '/usr/bin/stat-dhcpusers'
# option cmduser 'nobody'
# option cmdgroup 'nogroup'
#config exec_notify
# option cmdline '/usr/bin/stat-dhcpusers'
# option cmduser 'nobody'
# option cmdgroup 'nogroup'
#config plugin 'interface'
# option enable '1'
# list Interface 'br-lan'
# option IgnoreSelected '0'
#config plugin 'irq'
# option enable '0'
# list Irq '2'
# list Irq '3'
# list Irq '4'
# list Irq '7'
#config plugin 'iwinfo'
# option enable '0'
#config plugin 'load'
# option enable '0'
#config plugin 'lua'
# option BasePath '/usr/share/collectd-mod-lua'
# list Script 'script1.lua'
# list Script 'script2.lua
#config plugin 'memory'
# option enable '0'
#config plugin 'netlink'
# option enable '0'
# option IgnoreSelected '0'
# list VerboseInterface 'br-lan'
# list QDisc 'br-lan'
#config plugin 'nut'
# option enable '0'
# option UPS 'myupsname'
#config plugin 'olsrd'
# option enable '0'
# option Port '2006'
# option Host '127.0.0.1'
#config plugin 'openvpn'
# option enable '0'
# option StatusFile '/var/run/openvpn/openvpn.status'
# option CollectIndividualUsers '1'
# optoin CollectUserCount '1'
# optoin CollectCompression '1'
# option ImprovedNamingSchema '0'
#config plugin 'ping'
# option enable '0'
# option TTL '127'
# option Interval '30'
# list Host '127.0.0.1'
#config plugin 'processes'
# option enable '0'
# list Process 'uhttpd'
# list Process 'dnsmasq'
# list Process 'dropbear'
#config plugin 'rrdtool'
# option enable '0'
# option DataDir '/tmp/rrd'
# option RRARows '100'
# option RRASingle '1'
# list RRATimespan '3600'
# list RRATimespan '86400'
# list RRATimespan '604800'
# list RRATimespan '2678400'
# list RRATimespan '31622400'
#config plugin 'sensors'
# option enable '0'
#config plugin 'tcpconns'
# option enable '0'
# list ListeningPort '0'
# list LocalPort '22'
# list LocalPort '80'
#config plugin 'thermal'
# option enable '0'
# option IgnoreSelected '0'
# list Device ''
#config plugin 'unixsock'
# option enable '0'
# option SocketFile '/var/run/collectd/query.sock'
# option SocketGroup 'nogroup'
#config plugin 'uptime'
# option enable '0'

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/conntrack.json View File

@ -0,0 +1,2 @@
{
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/contextswitch.json View File

@ -0,0 +1,2 @@
{
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/cpu.json View File

@ -0,0 +1,2 @@
{
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/cpufreq.json View File

@ -0,0 +1,2 @@
{
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/csv.json View File

@ -0,0 +1,8 @@
{
"string": [
"DataDir"
],
"bool": [
"StoreRates"
]
}

+ 10
- 0
utils/collectd/files/usr/share/collectd/plugin/df.json View File

@ -0,0 +1,10 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Device",
"MountPoint",
"FSType"
]
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/disk.json View File

@ -0,0 +1,8 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Disk"
]
}

+ 6
- 0
utils/collectd/files/usr/share/collectd/plugin/dns.json View File

@ -0,0 +1,6 @@
{
"list": [
"Interface",
"IgnoreSource"
]
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/email.json View File

@ -0,0 +1,8 @@
{
"string": [
"SocketFile",
"SocketGroup",
"SocketPerms",
"MaxConns"
]
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/entropy.json View File

@ -0,0 +1,2 @@
{
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/exec.json View File

@ -0,0 +1,2 @@
{
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/interface.json View File

@ -0,0 +1,8 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Interface"
]
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/irq.json View File

@ -0,0 +1,8 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Irq"
]
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/iwinfo.json View File

@ -0,0 +1,8 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Interface"
]
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/load.json View File

@ -0,0 +1,2 @@
{
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/lua.json View File

@ -0,0 +1,8 @@
{
"string": [
"BasePath"
],
"list": [
"Script"
]
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/memory.json View File

@ -0,0 +1,2 @@
{
}

+ 12
- 0
utils/collectd/files/usr/share/collectd/plugin/netlink.json View File

@ -0,0 +1,12 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Interface",
"VerboseInterface",
"QDisc",
"Classe",
"Filter"
]
}

+ 5
- 0
utils/collectd/files/usr/share/collectd/plugin/nut.json View File

@ -0,0 +1,5 @@
{
"string": [
"UPS"
]
}

+ 9
- 0
utils/collectd/files/usr/share/collectd/plugin/olsrd.json View File

@ -0,0 +1,9 @@
{
"string": [
"Host",
"Port",
"CollectLinks",
"CollectRoutes",
"CollectTopology"
]
}

+ 11
- 0
utils/collectd/files/usr/share/collectd/plugin/openvpn.json View File

@ -0,0 +1,11 @@
{
"string": [
"StatusFile"
],
"bool": [
"CollectIndividualUsers",
"CollectUserCount",
"CollectCompression",
"ImprovedNamingSchema"
]
}

+ 9
- 0
utils/collectd/files/usr/share/collectd/plugin/ping.json View File

@ -0,0 +1,9 @@
{
"string": [
"TTL",
"Interval"
],
"list": [
"Host"
]
}

+ 5
- 0
utils/collectd/files/usr/share/collectd/plugin/processes.json View File

@ -0,0 +1,5 @@
{
"list": [
"Process"
]
}

+ 17
- 0
utils/collectd/files/usr/share/collectd/plugin/rrdtool.json View File

@ -0,0 +1,17 @@
{
"string": [
"DataDir",
"StepSize",
"HeartBeat",
"RRARows",
"XFF",
"CacheFlush",
"CacheTimeout"
],
"bool": [
"RRASingle"
],
"list": [
"RRATimespan"
]
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/sensors.json View File

@ -0,0 +1,8 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Sensor"
]
}

+ 9
- 0
utils/collectd/files/usr/share/collectd/plugin/tcpconns.json View File

@ -0,0 +1,9 @@
{
"bool": [
"ListeningPorts"
],
"list": [
"LocalPort",
"RemotePort"
]
}

+ 8
- 0
utils/collectd/files/usr/share/collectd/plugin/thermal.json View File

@ -0,0 +1,8 @@
{
"bool": [
"IgnoreSelected"
],
"list": [
"Device"
]
}

+ 7
- 0
utils/collectd/files/usr/share/collectd/plugin/unixsock.json View File

@ -0,0 +1,7 @@
{
"string": [
"SocketFile",
"SocketGroup",
"SocketPerms"
]
}

+ 2
- 0
utils/collectd/files/usr/share/collectd/plugin/uptime.json View File

@ -0,0 +1,2 @@
{
}

Loading…
Cancel
Save