Skip to content

Commit dc9df51

Browse files
authored
Merge pull request #465 from ukkopahis/telegraf-auto-includes
telegraf: add automatic docker and temp monitoring
2 parents 85ad198 + 975df90 commit dc9df51

File tree

6 files changed

+51
-12
lines changed

6 files changed

+51
-12
lines changed

.templates/telegraf/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ COPY ${IOTSTACK_DEFAULTS_DIR} /${IOTSTACK_DEFAULTS_DIR}
1919
ENV BASELINE_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf-reference.conf
2020
ENV IOTSTACK_CONFIG=/${IOTSTACK_DEFAULTS_DIR}/telegraf.conf
2121
RUN cp /etc/telegraf/telegraf.conf ${BASELINE_CONFIG} && \
22+
cat /${IOTSTACK_DEFAULTS_DIR}/auto_include/*.conf >> ${BASELINE_CONFIG} && \
23+
rm -r /${IOTSTACK_DEFAULTS_DIR}/auto_include && \
2224
chmod 444 ${BASELINE_CONFIG} && \
2325
grep -v -e "^[ ]*#" -e "^[ ]*$" ${BASELINE_CONFIG} >${IOTSTACK_CONFIG} && \
2426
sed -i '/^\[\[outputs.influxdb\]\]/a\ \ urls = ["http://influxdb:8086"]' ${IOTSTACK_CONFIG}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[[inputs.file]]
2+
files = ["/sys/class/thermal/thermal_zone0/temp"]
3+
name_override = "cpu_temperature"
4+
data_format = "value"
5+
data_type = "integer"

docs/Containers/Telegraf.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ The purpose of the Dockerfile is to:
2222
│      ├── Dockerfile ❶
2323
│      ├── entrypoint.sh ❷
2424
│ ├── iotstack_defaults
25-
│   │ └── additions ❸
26-
│      └── service.yml ❹
25+
│   │ ├── additions ❸
26+
│   │ └── auto_include ❹
27+
│      └── service.yml ❺
2728
├── services
2829
│ └── telegraf
29-
│ └── service.yml
30-
├── docker-compose.yml
30+
│ └── service.yml
31+
├── docker-compose.yml
3132
└── volumes
3233
└── telegraf ❼
3334
├── additions ❽
@@ -38,9 +39,10 @@ The purpose of the Dockerfile is to:
3839
1. The *Dockerfile* used to customise Telegraf for IOTstack.
3940
2. A replacement for the `telegraf` container script of the same name, extended to handle container self-repair.
4041
3. The *additions folder*. See [Applying optional additions](#optionalAdditions).
41-
4. The *template service definition*.
42-
5. The *working service definition* (only relevant to old-menu, copied from ❹).
43-
6. The *Compose* file (includes ❹).
42+
4. The *auto_include folder*. Additions automatically applied to
43+
`telegraf.conf`. See [Automatic includes to telegraf.conf](#autoInclude).
44+
5. The *template service definition*.
45+
6. The *working service definition* (only relevant to old-menu, copied from ❹).
4446
7. The *persistent storage area* for the `telegraf` container.
4547
8. A working copy of the *additions folder* (copied from ❸). See [Applying optional additions](#optionalAdditions).
4648
9. The *reference configuration file*. See [Changing Telegraf's configuration](#editConfiguration).
@@ -214,21 +216,31 @@ When you make a change to `telegraf.conf`, you activate it by restarting the con
214216
$ cd ~/IOTstack
215217
$ docker-compose restart telegraf
216218
```
219+
220+
### <a name="autoInclude"> Automatic includes to telegraf.conf </a>
221+
222+
* `inputs.docker.conf` instructs Telegraf to collect metrics from Docker. Requires kernel control
223+
groups to be enabled to collect memory usage data. If not done during initial installation,
224+
enable by running (reboot required):
225+
```
226+
echo $(cat /boot/cmdline.txt) cgroup_memory=1 cgroup_enable=memory | sudo tee /boot/cmdline.txt
227+
```
228+
* `inputs.cpu_temp.conf' collects cpu temperature.
217229

218230
### <a name="optionalAdditions"> Applying optional additions </a>
219231

220232
The *additions folder* (see [Significant directories and files](#significantFiles)) is a mechanism for additional *IOTstack-ready* configuration options to be provided for Telegraf.
221233

222-
At the time of writing (October 2021), two additions are provided:
234+
Currently there is one addition:
223235

224-
1. `inputs.docker.conf` provided by @tablatronix, which instructs Telegraf to collect metrics from Docker.
225-
2. `inputs.mqtt_consumer.conf` which formed part of the [gcgarner/IOTstack telegraf configuration](https://github.com/gcgarner/IOTstack/blob/master/.templates/telegraf/telegraf.conf) and instructs Telegraf to subscribe to a metric feed from the Mosquitto broker. This assumes, of course, that something is publishing those metrics.
236+
1. `inputs.mqtt_consumer.conf` which formed part of the [gcgarner/IOTstack telegraf configuration](https://github.com/gcgarner/IOTstack/blob/master/.templates/telegraf/telegraf.conf) and instructs Telegraf to subscribe to a metric feed from the Mosquitto broker. This assumes, of course, that something is publishing those metrics.
226237

227-
Using `inputs.docker.conf` as the example, applying that addition to your Telegraf configuration file involves:
238+
Using `inputs.mqtt_consumer.conf` as the example, applying that addition to
239+
your Telegraf configuration file involves:
228240

229241
```
230242
$ cd ~/IOTstack/volumes/telegraf
231-
$ grep -v "^#" additions/inputs.docker.conf | sudo tee -a telegraf.conf >/dev/null
243+
$ grep -v "^#" additions/inputs.mqtt_consumer.conf | sudo tee -a telegraf.conf >/dev/null
232244
$ cd ~/IOTstack
233245
$ docker-compose restart telegraf
234246
```

docs/Getting-Started.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ $ sudo apt update
178178
$ sudo apt install libseccomp2 -t buster-backports
179179
```
180180

181+
### patch 3 - kernel control groups
182+
183+
Kernel control groups need to be enabled in order to monitor container specific
184+
usage. This makes commands like `docker stats` fully work. Also needed for full
185+
monitoring of docker resource usage by the telegraf container.
186+
187+
Enable by running (takes effect after reboot):
188+
```
189+
echo $(cat /boot/cmdline.txt) cgroup_memory=1 cgroup_enable=memory | sudo tee /boot/cmdline.txt
190+
```
191+
181192
## <a name="aboutSudo"> a word about the `sudo` command </a>
182193

183194
Many first-time users of IOTstack get into difficulty by misusing the `sudo` command. The problem is best understood by example. In the following, you would expect `~` (tilde) to expand to `/home/pi`. It does:

install.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ function do_env_checks() {
275275
fi
276276
}
277277

278+
function do_kernel_checks() {
279+
if ! grep -q "cgroup_memory=1 cgroup_enable=memory" /boot/cmdline.txt; then
280+
echo "Kernel cgroups not enabled. Adding kernel parameters." >&2
281+
echo "You will need to restart your system before the changes take effect."
282+
echo $(cat /boot/cmdline.txt) cgroup_memory=1 cgroup_enable=memory | sudo tee /boot/cmdline.txt
283+
fi
284+
}
285+
278286
touch .new_install
279287
echo "Enter in the sudo password when prompted, to install dependencies"
280288

@@ -306,3 +314,4 @@ if [ ! "$(user_in_group docker)" == "true" ]; then
306314
sudo usermod -G "docker" -a $USER
307315
fi
308316
do_env_checks
317+
do_kernel_checks

0 commit comments

Comments
 (0)