Skip to content

Commit

Permalink
status: add support for JSON formatted output (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg authored Nov 11, 2024
1 parent 3c931ec commit 8691ff9
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
uses: itzg/github-workflows/.github/workflows/go-with-releaser-image.yml@main
with:
go-version: "1.22.7"
go-version: "1.23.3"
secrets:
image-registry-username: ${{ secrets.DOCKERHUB_USERNAME }}
image-registry-password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
build:
uses: itzg/github-workflows/.github/workflows/go-test.yml@main
with:
go-version: "1.22.7"
go-version: "1.23.3"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.22 as builder
FROM golang:1.23 as builder

WORKDIR /build

Expand Down
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,91 @@ Subcommands for status:
status-bedrock Retrieves and displays the status of the given Minecraft Bedrock Dedicated server
```

Usage for any of the sub-commands can be displayed by add `--help` after each, such as:

```shell
mc-monitor status --help
```

### status

```
-host string
hostname of the Minecraft server (env MC_HOST) (default "localhost")
-json
output server status as JSON
-port int
port of the Minecraft server (env MC_PORT) (default 25565)
-retry-interval duration
if retry-limit is non-zero, status will be retried at this interval (default 10s)
-retry-limit int
if non-zero, failed status will be retried this many times before exiting
-show-player-count
show just the online player count
-skip-readiness-check
returns success when pinging a server without player info, or with a max player count of 0
-timeout duration
the timeout the ping can take as a maximum (default 15s)
-use-mc-utils
(experimental) try using mcutils to query the server
-use-proxy
supports contacting Bungeecord when proxy_protocol enabled
-use-server-list-ping
indicates the legacy, server list ping should be used for pre-1.12
```

### status-bedrock

```
-host string
(default "localhost")
-port int
(default 19132)
-retry-interval duration
if retry-limit is non-zero, status will be retried at this interval (default 10s)
-retry-limit int
if non-zero, failed status will be retried this many times before exiting
```

### export-for-prometheus

```
-bedrock-servers host:port
one or more host:port addresses of Bedrock servers to monitor, when port is omitted 19132 is used (env EXPORT_BEDROCK_SERVERS)
-port int
HTTP port where Prometheus metrics are exported (env EXPORT_PORT) (default 8080)
-servers host:port
one or more host:port addresses of Java servers to monitor, when port is omitted 25565 is used (env EXPORT_SERVERS)
-timeout duration
timeout when checking each servers (env TIMEOUT) (default 1m0s)
```

### gather-for-telegraf

```
-interval duration
gathers and sends metrics at this interval (env GATHER_INTERVAL) (default 1m0s)
-servers host:port
one or more host:port addresses of servers to monitor (env GATHER_SERVERS)
-telegraf-address host:port
host:port of telegraf accepting Influx line protocol (env GATHER_TELEGRAF_ADDRESS) (default "localhost:8094")
```

### collect-otel

```
-bedrock-servers host:port
one or more host:port addresses of Bedrock servers to monitor, when port is omitted 19132 is used (env EXPORT_BEDROCK_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)
-servers host:port
one or more host:port addresses of Java servers to monitor, when port is omitted 25565 is used (env EXPORT_SERVERS)
```

## Examples

### Checking the status of a server
Expand Down
51 changes: 26 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
module github.com/itzg/mc-monitor

go 1.21
go 1.23

toolchain go1.22.6
toolchain go1.23.3

require (
github.com/Raqbit/mc-pinger v0.2.4
github.com/avast/retry-go v3.0.0+incompatible
github.com/google/subcommands v1.2.0
github.com/itzg/go-flagsfiller v1.14.0
github.com/itzg/go-flagsfiller v1.15.0
github.com/itzg/line-protocol-sender v0.1.1
github.com/itzg/zapconfigs v0.1.0
github.com/prometheus/client_golang v1.19.1
github.com/sandertv/go-raknet v1.12.1
github.com/prometheus/client_golang v1.20.5
github.com/sandertv/go-raknet v1.14.2
github.com/stretchr/testify v1.9.0
github.com/xrjr/mcutils v1.5.1
go.opentelemetry.io/contrib/instrumentation/runtime v0.53.0
go.opentelemetry.io/otel v1.28.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0
go.opentelemetry.io/otel/metric v1.28.0
go.opentelemetry.io/otel/sdk/metric v1.28.0
go.opentelemetry.io/contrib/instrumentation/runtime v0.57.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.32.0
go.opentelemetry.io/otel/metric v1.32.0
go.opentelemetry.io/otel/sdk/metric v1.32.0
go.uber.org/zap v1.27.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/df-mc/atomic v1.10.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.23.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pires/go-proxyproto v0.7.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 8691ff9

Please sign in to comment.