In this demo we will build a custom OpenTelemetry collector and collect logs and metrics from the operating system.
Prerequisites:
- You need Go in v1.17 or above locally installed.
socat
netstat
jq
(optional, for nicer JSON output rendering)
First make sure you have the OTel collector builder
tool installed:
GO111MODULE=on go install go.opentelemetry.io/collector/cmd/builder@latest
Now build the collector using the supplied otelcol-builder.yaml builder config file:
builder --config=otelcol-builder.yaml --output-path=./myotelcol
Next, download the generator files and make them executable (chmod +x ...
):
For logs we use the generate-logs.sh
script, so download generate-logs.sh.
The script tails a local log file and sends a line to the collector's syslog
receiver, using socat
.
For metrics, we use the generate-metrics.sh
script, so download generate-metrics.sh.
The script reads network stats via netstat
and sends a random connection's receive data to the collector's
statsd
receiver, using socat
.
Next, run the two scripts to generate signals.
Now it's time to collect & ingest signals so start the OTel collector as follows with the supplied otel-config.yaml collector config file:
./myotelcol --config otel-config.yaml
The collected metrics and logs are written to a local file using the File
exporter, so create a sub-dir called data
and then you can follow the resulting signals using:
tail -f -n 1 data/out.json | jq