Skip to content

Commit b94f12f

Browse files
authored
Add an example showing how to use the collector with collectd (#5738)
1 parent f15767c commit b94f12f

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-0
lines changed

examples/collectd/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# CollectD example
2+
3+
This example shows how to connect a CollectD daemon running on a host to an OpenTelemetry Collector.
4+
5+
For the purpose of this example, the host is represented by a Ubuntu 24.04 docker image.
6+
7+
On this image, we install collectd as a Debian package, using stock instructions.
8+
9+
We proceed to add configuration to CollectD to instruct it to have an active behavior:
10+
* We give it directions to ingest free disk related metrics through `collectd/metrics.conf`
11+
* We instruct CollectD to send data over HTTP using `collectd/http.conf`
12+
13+
We also set up a collector to listen over HTTP for traffic from the collectD daemon.
14+
15+
To do so, we set up the [collectd receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/collectdreceiver):
16+
17+
```yaml
18+
collectd:
19+
endpoint: "0.0.0.0:8081"
20+
```
21+
22+
Note we use `0.0.0.0` to make sure we expose the 8081 port over the Docker network interface so the 2 Docker containers may interact.
23+
24+
We run the example with the instruction to start the docker-compose setup, building the collectd container:
25+
26+
```bash
27+
$> docker compose up --build
28+
```
29+
30+
We check that the collector is indeed receiving metrics and logging them to stdout via the debug exporter:
31+
32+
```bash
33+
$> docker logs otelcollector
34+
```
35+
36+
A typical example of output is:
37+
```
38+
StartTimestamp: 1970-01-01 00:00:00 +0000 UTC
39+
Timestamp: 2024-12-20 19:55:44.006000128 +0000 UTC
40+
Value: 38.976566
41+
Metric #17
42+
Descriptor:
43+
-> Name: percent_bytes.reserved
44+
-> Description:
45+
-> Unit:
46+
-> DataType: Gauge
47+
NumberDataPoints #0
48+
Data point attributes:
49+
-> plugin: Str(df)
50+
-> plugin_instance: Str(etc-hosts)
51+
-> host: Str(ea1d62c7a229)
52+
-> dsname: Str(value)
53+
StartTimestamp: 1970-01-01 00:00:00 +0000 UTC
54+
Timestamp: 2024-12-20 19:55:44.006000128 +0000 UTC
55+
Value: 5.102245
56+
{"kind": "exporter", "data_type": "metrics", "name": "debug"}
57+
```

examples/collectd/collectd/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM ubuntu:24.04
2+
3+
RUN apt-get update && apt-get install -y collectd && apt-get clean
4+
5+
CMD ["/usr/sbin/collectd", "-f"]

examples/collectd/collectd/http.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# The minimal configuration required to have collectd send data to an OpenTelemetry Collector
2+
# with a collectdreceiver deployed on port 8081.
3+
4+
LoadPlugin write_http
5+
<Plugin "write_http">
6+
<Node "collector">
7+
URL "http://otelcollector:8081"
8+
Format JSON
9+
VerifyPeer false
10+
VerifyHost false
11+
</Node>
12+
</Plugin>
13+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# An example of collectd plugin configuration reporting free disk space on the host.
2+
3+
<LoadPlugin df>
4+
Interval 3600
5+
</LoadPlugin>
6+
<Plugin df>
7+
ValuesPercentage true
8+
</Plugin>

examples/collectd/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3"
2+
services:
3+
collectd:
4+
build: collectd
5+
container_name: collectd
6+
depends_on:
7+
- otelcollector
8+
volumes:
9+
- ./collectd/http.conf:/etc/collectd/collectd.conf.d/http.conf
10+
- ./collectd/metrics.conf:/etc/collectd/collectd.conf.d/metrics.conf
11+
# OpenTelemetry Collector
12+
otelcollector:
13+
image: quay.io/signalfx/splunk-otel-collector:latest
14+
container_name: otelcollector
15+
command: ["--config=/etc/otel-collector-config.yml", "--set=service.telemetry.logs.level=debug"]
16+
volumes:
17+
- ./otel-collector-config.yml:/etc/otel-collector-config.yml
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
receivers:
2+
collectd:
3+
endpoint: "0.0.0.0:8081"
4+
5+
exporters:
6+
debug:
7+
verbosity: detailed
8+
9+
service:
10+
pipelines:
11+
metrics:
12+
receivers: [collectd]
13+
exporters: [debug]

0 commit comments

Comments
 (0)