diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d70cc92 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +cmd +internal +pkg +.* +go.* +Makefile \ No newline at end of file diff --git a/.gitignore b/.gitignore index a725465..06a99b2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor/ \ No newline at end of file +vendor/ +node-status \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f1ac7d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM iron/go +WORKDIR /dist + +COPY . . + +EXPOSE 80 +ENTRYPOINT ["/dist/node-status"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4aa2d4a --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +GIN := jsoniter +BIN := node-status + +.PHONY: build +build: + CGO_ENABLED=0 go build -tags=${GIN} -o ${BIN} cmd/node-status/*.go diff --git a/README.md b/README.md index c4a2d52..80fa523 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,63 @@ ### openethereum-node-status -> ⚠️ WIP - A tiny stateless service to return health status and useful metrics from OpenEthereum/Parity nodes. Requires the [following API's](https://openethereum.github.io/JSONRPC) to be enabled: - eth - parity +#### Usage + +Default config: + +```bash +RPC_ENDPOINT=https://core.bloxberg.org +SERVER_POINT=80 +DEBUG_ENABLED=false +``` + +Build and run: + +```bash +make build +docker build -t node-status:latest . +docker run --rm -p 5555:80 node-status:latest +``` + +Pre-build Docker image is available at `docker.grassecon.net/devops/node-status:latest` + +Use with any uptime tracker and/or metrics scrapper. + #### Endpoints -- `/health` (Expect 200 for health with an additional JSON object with more info) -- `/metrics` (Expect 200 with an additional JSON object with more info) +- `/health`: + +```json +{ + "chainName": "bloxberg", + "syncComplete": true +} +``` + +- `/metrics`: + +```json +{ + "blockNumber": 13421262, + "enode": "enode://0fb17be7e259fee00d0c123c82dfd9cde74763683b7773a1d764a472436362c3031eac591721c02f754ba22140bb654f69261a7dc79143419a3ff8aff1298cce@130.183.206.234:30303", + "gasPrice": 0, + "peerCount": 5, + "pendingTransactions": [ + { + "hash": "0x04b39537eaed56bdab1309d6f2dd6a2618f1725db3709d345a15cc967bb4481f", + "from": "0xfc6771c7bd523403327d8fe84b63c3262c2007d6", + "to": "0x105e668e389620d5588847c35fb91ea096f465ca" + } + ], + "pendingTransactionsCount": 1 +} +``` + +In-case of any issues, the endpoints return a `503` error #### Development diff --git a/cmd/node-status/main.go b/cmd/node-status/main.go index 2225b10..e5b0490 100644 --- a/cmd/node-status/main.go +++ b/cmd/node-status/main.go @@ -56,6 +56,9 @@ func main() { } server.RpcClient = rpc.NewRpcClient(conf.String("rpc.endpoint")) + log.Info(). + Str("module", "main"). + Msg("starting server") if err := server.Start(fmt.Sprintf(":%s", conf.String("server.port")), ginMode); err != nil { log.Fatal(). diff --git a/config/config.toml b/config/config.toml index 396d04d..4ef511b 100644 --- a/config/config.toml +++ b/config/config.toml @@ -2,7 +2,7 @@ endpoint = "https://core.bloxberg.org" [server] -port = "5555" +port = "80" [debug] enabled = false