Skip to content

Commit

Permalink
Merge pull request #12 from MOV-AI/feat/linux_cpu
Browse files Browse the repository at this point in the history
DP-1324: add test in entrypoint on enabling linux_cpu input
  • Loading branch information
AlexFernandes-MOVAI authored Nov 7, 2023
2 parents 5ae34d8 + ab505c2 commit 3cb1f58
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ LABEL movai="telegraf"
LABEL environment="develop"

COPY files/telegraf.conf /etc/telegraf/telegraf.conf
COPY files/entrypoint.sh /entrypoint.sh

RUN chmod o+w /etc/telegraf/telegraf.conf

# Rest is upstream
35 changes: 35 additions & 0 deletions files/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
set -e

# Check if linux_cpu inputs required files exist
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq/" ] && [ -d "/sys/devices/system/cpu/cpu0/thermal_throttle/" ]; then
# Enable the [[inputs.linux_cpu]] plugin
enable_plugin=true
else
# Disable the [[inputs.linux_cpu]] plugin
enable_plugin=false
fi

if [ "$enable_plugin" == "true" ] && ! grep linux_cpu /etc/telegraf/telegraf.conf -q; then
# Include the configuration for the [[inputs.linux_cpu]] plugin
cat <<EOF >> /etc/telegraf/telegraf.conf
[[inputs.linux_cpu]]
host_sys = "/hostfs/sys"
metrics = ["cpufreq", "thermal"]
EOF
fi

if [ "${1:0:1}" = '-' ]; then
set -- telegraf "$@"
fi

if [ "$(id -u)" -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"

exec su-exec telegraf "$@"
fi

14 changes: 0 additions & 14 deletions files/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5452,20 +5452,6 @@
# servers = ["127.0.0.1:4010"]


# Provides Linux CPU metrics
[[inputs.linux_cpu]]
## Path for sysfs filesystem.
## See https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt
## Defaults:
host_sys = "/hostfs/sys"

# ## CPU metrics collected by the plugin.
# ## Supported options:
# ## "cpufreq", "thermal"
# ## Defaults:
metrics = ["cpufreq", "thermal"]


# # Provides Linux sysctl fs metrics
# [[inputs.linux_sysctl_fs]]
# # no configuration
Expand Down

0 comments on commit 3cb1f58

Please sign in to comment.