Skip to content

Commit

Permalink
docs(collectd): simplify instructions by using a community plugin for…
Browse files Browse the repository at this point in the history
… installation and configuration

Signed-off-by: Reuben Miller <[email protected]>
  • Loading branch information
reubenmiller committed Feb 4, 2024
1 parent eb93afc commit be39c2e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 53 deletions.
2 changes: 1 addition & 1 deletion docs/src/operate/troubleshooting/device-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sudo systemctl start collectd
tedge mqtt sub 'collectd/#'
```

If no metrics are collected, please check the [MQTT configuration](../../start/device-monitoring.md#collectdconf)
If no metrics are collected, please check the [MQTT configuration](../../start/device-monitoring.md#collectd-configuration)

:::note
The `collectd.conf` file included with %%te%% is configured for conservative interval times, e.g. 10 mins to 1 hour depending on the metric. This is done so that the metrics don't consume unnecessary IoT resources both on the device and in the cloud. If you want to push the metrics more frequently then you will have to adjust the `Interval` settings either globally or on the individual plugins. Make sure you restart the collectd service after making any changes to the configuration.
Expand Down
76 changes: 24 additions & 52 deletions docs/src/start/device-monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,48 @@ Using these metrics, you can monitor the health of devices
and can proactively initiate actions in case the device seems to malfunction.
Additionally, the metrics can be used to help the customer troubleshoot when problems with the device are reported.

%%te%% uses the open source component [`collectd`](https://collectd.org/) to collect the metrics from the device.
%%te%% translates the collected metrics from their native format to the [%%te%% JSON](../understand/thin-edge-json.md) format
%%te%% uses the open source component [collectd](https://collectd.org/) to collect the metrics from the device.
%%te%% translates the collectd metrics from their native format to the [%%te%% JSON](../understand/thin-edge-json.md) format
and then into the [cloud-vendor specific format](../understand/tedge-mapper.md).

Enabling monitoring on your device is a 3-steps process:
1. [Install `collectd`](#install-collectd),
2. [Configure `collectd`](#configure-collectd),
3. [Enable %%te%% monitoring](#enable-thin-edge-monitoring).
![device monitoring with collectd](images/collectd-metrics.png)

## Install collectd
## Install

Device monitoring is not enabled by default when you install %%te%%.
You will have to install and configure [`collectd`](https://collectd.org/) first.
Device monitoring is not enabled by default, however it can be enabled using a community package, [tedge-collectd-setup](https://cloudsmith.io/~thinedge/repos/community/packages/?q=name%3A%27%5Etedge-collectd-setup%24%27), which will install [collectd](https://collectd.org/) and configure some sensible defaults including monitoring of cpu, memory and disk metrics.

To install collectd, follow the [collectd installation process](https://collectd.org/download.shtml)
that is specific to your device. On a Debian or Ubuntu linux:
```sh tab={"label":"Debian/Ubuntu"}
sudo apt-get install tedge-collectd-setup
```

```sh title="Option 1: (Recommended)"
sudo apt-get install --no-install-recommends collectd-core mosquitto-clients
```sh tab={"label":"RHEL/Fedora/RockyLinux"}
sudo dnf install tedge-collectd-setup
```

```sh title="Option 2"
sudo apt-get install --no-install-recommends collectd-core libmosquitto1
```sh tab={"label":"Alpine"}
sudo apk add tedge-collectd-setup
```

:::note
Either `mosquitto-clients` or `libmosquitto1` package is required as %%te%% makes use of the MQTT plugin of `collectd` which enables collectd to publish its metrics via the local MQTT broker where %%te%% is able to process the messages.
The default collectd settings, `/etc/collectd/collectd.conf`, use conservative interval times, e.g. 10 mins to 1 hour depending on the metric. This is done so that the metrics don't consume unnecessary IoT resources both on the device and in the cloud. If you want to push the metrics more frequently then you will have to adjust the `Interval` settings either globally or on the individual plugins. Make sure you restart the collectd service after making any changes to the configuration.
:::

## Configure collectd
## Background

### TLDR; Just want it running
The following sections provide information about further customizing the collectd settings and give some background about how the collectd messages are processed by the **tedge-mapper-collectd** service.

%%te%% provides a [basic `collectd` configuration](https://github.com/thin-edge/thin-edge.io/blob/main/configuration/contrib/collectd/collectd.conf)
that can be used to collect cpu, memory and disk metrics.
### collectd configuration {#collectd-configuration}

Simply copy that file to the main collectd configuration file and restart the daemon
(it might be good to keep a copy of the original configuration).
You can further customize the default collectd configuration by editing the following file:

```sh
sudo cp /etc/collectd/collectd.conf /etc/collectd/collectd.conf.backup
sudo cp /etc/tedge/contrib/collectd/collectd.conf /etc/collectd/collectd.conf
sudo systemctl restart collectd
/etc/collectd/collectd.conf
```

:::note
The `collectd.conf` file included with %%te%% is configured for conservative interval times, e.g. 10 mins to 1 hour depending on the metric. This is done so that the metrics don't consume unnecessary IoT resources both on the device and in the cloud. If you want to push the metrics more frequently then you will have to adjust the `Interval` settings either globally or on the individual plugins. Make sure you restart the collectd service after making any changes to the configuration.
:::
Details about collectd plugins and their configuration can be viewed directly from the [collectd documentation](https://collectd.org/documentation/manpages/collectd.conf.5.shtml).

### Collectd.conf
However keep in mind the following points when editing the file:

Unless you opted for the [minimal test configuration provided with %%te%%](#tldr-just-want-it-running),
you will have to update the
[`collectd.conf` configuration file](https://collectd.org/documentation/manpages/collectd.conf.5.shtml)
(usually located at `/etc/collectd/collectd.conf`)

__Important notes__ You can enable or disable the collectd plugins of your choice, but with some notable exceptions:
1. __MQTT must be enabled__.
* %%te%% expects the collectd metrics to be published on the local MQTT bus.
Hence, you must enable the [MQTT write plugin of collectd](https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_mqtt).
Expand Down Expand Up @@ -123,20 +108,12 @@ __Important notes__ You can enable or disable the collectd plugins of your choic
</Chain>
```

## Enable %%te%% monitoring {#enable}

To enable monitoring on your device, you have to launch the `tedge-mapper-collectd` daemon process.
### tedge-mapper-collectd

```sh
sudo systemctl enable tedge-mapper-collectd
sudo systemctl start tedge-mapper-collectd
```

This process subscribes to the `collectd/#` topics to read the monitoring metrics published by collectd
The `tedge-mapper-collectd` service subscribes to the `collectd/#` topics to read the monitoring metrics published by collectd
and emits the translated measurements in %%te%% JSON format to the **measurements** topic.
You can inspect the collected and translated metrics, by subscribing to these topics:

The metrics collected by `collectd` are emitted to subtopics named after the collectd plugin and the metric name:
The metrics collected by `collectd` are emitted to subtopics named after the collectd plugin and the metric name. You can inspect the collectd messages using the following commands:

```sh te2mqtt formats=v1
tedge mqtt sub 'collectd/#'
Expand Down Expand Up @@ -174,11 +151,6 @@ tedge mqtt sub 'c8y/#'
[c8y/measurement/measurements/create] {"type": "ThinEdgeMeasurement","time":"2021-06-07T15:40:31.154898577+01:00","cpu":{"percent-active": {"value": 0.5}},"memory":{"percent-used": {"value": 1.16608109197519}}}
```

If your device is not connected yet one of the following guides:
* [Connect my device to Cumulocity IoT](./connect-c8y.md)
* [Connect my device to Azure IoT](./connect-azure.md)
* [Connect my device to AWS IoT](./connect-aws.md)

## Troubleshooting

See here for [how to troubleshoot device monitoring?](../operate/troubleshooting/device-monitoring.md)
For troubleshooting tips, check out the [device monitoring](../operate/troubleshooting/device-monitoring.md) section.
Binary file added docs/src/start/images/collectd-metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit be39c2e

Please sign in to comment.