Skip to content

Commit

Permalink
Feature - OpenTelemetry support (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorvasc authored Aug 22, 2024
1 parent 7a11054 commit 2896e1b
Show file tree
Hide file tree
Showing 19 changed files with 1,318 additions and 1,657 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Subcommands:
Subcommands for monitoring:
export-for-prometheus Registers an HTTP metrics endpoints for Prometheus export
gather-for-telegraf Periodically gathers to status of one or more Minecraft servers and sends metrics to telegraf over TCP using Influx line protocol
collect-otel Periodically collects to status of one or more Minecraft servers and sends metrics to an OpenTelemetry Collector using the gRPC protocol
Subcommands for status:
status Retrieves and displays the status of the given Minecraft server
Expand Down Expand Up @@ -124,3 +125,43 @@ An example Docker composition is provided in [examples/mc-monitor-prom](examples

![Prometheus Chart](docs/prometheus_online_count_chart.png)



### Monitoring a server with Open Telemetry

Open Telemetry is a vendor-agnostic way to receive, process and export telemetry data. In this context, monitoring a Minecraft Server with Open Telemetry requires a running [Open Telemetry Collector](https://opentelemetry.io/docs/collector/) to receive the exported data. An example on how to initialize it can be found in [examples/mc-monitor-otel](examples/mc-monitor-otel).

Once you run the mc-monitor application using the `collect-otel` subcommand, mc-monitor will create the necessary [instrumentation]
(https://opentelemetry.io/docs/languages/go/instrumentation/#metrics) to export the metrics to the collector through the gRPC protocol.

The Collector will receive and process the data, sending the metrics to any of the supported [backends](https://opentelemetry.io/docs/collector/configuration/#exporters). In our example, you will find the necessary configurations to export metrics through Prometheus.

The `collect-otel` sub-command accepts the following arguments, which can also be viewed using `--help`:

```
-servers host:port
one or more host:port addresses of Java servers to monitor, when port is omitted 25565 is used (env EXPORT_SERVERS)
-bedrock-servers host:port
one or more host:port addresses of Bedrock servers to monitor, when port is omitted 19132 is used (env EXPORT_BED_ROCK_SERVERS)
-interval duration
Collect and sends OpenTelemetry data at this interval (env EXPORT_INTERVAL) (default 10s)
-otel-collector-endpoint string
OpenTelemetry gRPC endpoint to export data (env EXPORT_OTEL_COLLECTOR_ENDPOINT) (default "localhost:4317")
-otel-collector-timeout duration
Timeout for collecting OpenTelemetry data (env EXPORT_OTEL_COLLECTOR_TIMEOUT) (default 35s)
```

The following metrics are exported
- `minecraft_status_healthy`
- `minecraft_status_response_time_seconds`
- `minecraft_status_players_online_count`
- `minecraft_status_players_max_count`

with the labels
- `server_host`
- `server_port`
- `server_edition` : `java` or `bedrock`
- `server_version`

An example Docker composition is provided in [examples/mc-monitor-otel](examples/mc-monitor-otel).
18 changes: 18 additions & 0 deletions examples/mc-monitor-otel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Setup

Either git clone [the repo](https://github.com/itzg/mc-monitor) or [download a zip of the latest files](https://github.com/itzg/mc-monitor/archive/refs/heads/master.zip).

Go into the `examples/mc-monitor-otel` directory and start the composition using:

```shell
docker-compose up -d
```

Use `docker-compose logs -f` to watch the logs of the containers. When the Minecraft server with service name `mc` is up and running, then move onto the next step.

## Accessing Grafana

Open a browser to <http://localhost:3000> and log in initially with the username "admin" and password "admin". You will then be prompted to create a new password for the admin user.

[A dashboard called "MC Monitor"](http://localhost:3000/d/PpzSgJAnk/mc-monitor?orgId=1) is provisioned and can be accessed [in the dashboards section](http://localhost:3000/dashboards). That dashboard uses the Prometheus [datasource](http://localhost:3000/datasources) that was provisioned by the collector.

Loading

0 comments on commit 2896e1b

Please sign in to comment.