Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
silentnoname committed Sep 3, 2024
0 parents commit 2356a65
Show file tree
Hide file tree
Showing 13 changed files with 1,861 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# discord webhook url, you can create one here: https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks
discord_webhook=
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# IDEs
.idea/
.vscode/
*.swp
*~

# OS generated files
.DS_Store
Thumbs.db

.env

*.log
*_test.go
config.toml
celestia-node-monitor
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 silentnoname

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
98 changes: 98 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# celestia-node-monitor

A simple monitor for the Celestia DA node, it support full, bridge, and light node.
# Features
* It will send alert in discord channel when your celestia DA node is down, not synced, or lack of balance.
* It will check the status every 5 minutes.


# Pre-requisites

1. You have go 1.22+ installed.
2. You have set a discord webhook. You can follow this guide: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks

# How to use

## Get your auth token
```
# mocha bridge node for example
AUTH_TOKEN=$(celestia bridge auth admin --p2p.network mocha)
echo $AUTH_TOKEN
```

## Input your webhook url in .env file
`cp .env.example .env`
then edit .env file

## Edit config.toml
`cp config.toml.example config.toml`
then edit config.toml file
Configure the following parameters in the `config.toml` file:

* `[node]` section:
- `standardConsensusRPC`: Celestia Network Public Consensus RPC address
- `minimumBalance`: Minimum balance of your node (in utia). You'll receive an alert if the balance falls below this value.

* `[[node.APIs]]` section:
- `URL`: Celestia DA Node API address, default is http://localhost:26658
- `Token`: Your da node authentication token

* `[discord]` section:
- `alertuserid`: Discord user ID. Set this if you want to be @ mentioned when receiving alerts.
- `alertroleid`: Discord role ID. Set this if you want members with a specific role to be @ mentioned when receiving alerts.

You can add multiple `[[node.APIs]]` blocks to monitor multiple nodes.

For instructions on how to find Discord user ID and role ID:
- User ID: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-
- Role ID: https://www.itgeared.com/how-to-get-role-id-on-discord/

## Build
```shell
go build -o celestia-node-monitor ./cmd
```





## Run
```shell
./celestia-node-monitor
```

You can check the log in `celestia-node-monitor.log`


## Run as a service
```
sudo tee /etc/systemd/system/clelestia-node-monitor.service > /dev/null << EOF
[Unit]
Description=celestia-node-monitor
After=network-online.target
[Service]
User=$USER
WorkingDirectory=$HOME/celestia-node-monitor
ExecStart=$HOME/celestia-node-monitor/celestia-node-monitor
Restart=always
RestartSec=3
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
```
start

```
sudo systemctl enable celestia-node-monitor
sudo systemctl daemon-reload
sudo systemctl start celestia-node-monitor
```
check logs
```
sudo journalctl -fu celestia-node-monitor -o cat
```

41 changes: 41 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"celestia-node-monitor/pkg/alert"
"celestia-node-monitor/pkg/config"
"celestia-node-monitor/pkg/log"
"celestia-node-monitor/pkg/check"
"strconv"
"strings"
"time"
"go.uber.org/zap"
)

func main() {
log.InitLog()
log.Log.Info("Start celestia-node-monitor")
log.Log.Info("Loading config")
cfg, err := config.LoadConfig("config.toml", ".env")
if err != nil {
panic(err)
}
log.Log.Info("Standard consensus rpc is " + cfg.Node.StandardConsensusRPC)
nodeURLs := make([]string, len(cfg.Node.APIs))
for i, api := range cfg.Node.APIs {
nodeURLs[i] = api.URL
}
log.Log.Info("Nodes to check: " + strings.Join(nodeURLs, ", "))
log.Log.Info("Will alert when node balance is less than " + strconv.Itoa(cfg.Node.MinimumBalance) + " utia")
log.Log.Info("Will check node performance every 5 minutes")
ticker := time.NewTicker(1 * time.Minute)
for range ticker.C {
log.Log.Info("Start to check node performance")
nodePerformances:= monitor.CheckNodes(*cfg)
log.Log.Info("Start to check and send alert")
alerterr := alert.SendAlertViaDiscord(*cfg, nodePerformances)
if alerterr != nil {
log.Log.Error("Failed to send alert", zap.Error(err))
}
}

}
28 changes: 28 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[node]

standardConsensusRPC="https://rpc-mocha.pops.one/"

# Minimum balance of the da node , the denom is utia
minimumBalance=1000000


# The default api is http://localhost:26658
[[node.APIs]]
URL = "http://localhost:26658"
Token = "your_auth_token_here"

#if you have more than one node, you can add more like this
#[[node.APIs]]
#URL = "http://localhost:26658"
#Token = "your_auth_token_here"

# Minimum balance of the da node , the denom is utia
minimumBalance=1000000

[discord]

# discord userid, can be empty https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID-
alertuserid=[""]

# discord role id, can be empty https://www.itgeared.com/how-to-get-role-id-on-discord/
alertroleid=[""]
102 changes: 102 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
module celestia-node-monitor

go 1.22.2

toolchain go1.22.6

require (
github.com/avast/retry-go v3.0.0+incompatible
github.com/celestiaorg/celestia-openrpc v0.4.0
github.com/spf13/viper v1.15.0
go.uber.org/zap v1.25.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

require (
cosmossdk.io/math v1.1.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/celestiaorg/go-fraud v0.2.0 // indirect
github.com/celestiaorg/go-header v0.4.1 // indirect
github.com/celestiaorg/go-square v1.0.1 // indirect
github.com/celestiaorg/go-square/merkle v0.0.0-20240429192549-dea967e1533b // indirect
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 // indirect
github.com/celestiaorg/nmt v0.20.0 // indirect
github.com/celestiaorg/rsmt2d v0.11.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cometbft/cometbft v0.37.2 // indirect
github.com/cosmos/gogoproto v1.4.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/filecoin-project/go-jsonrpc v0.3.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/klauspost/reedsolomon v1.11.8 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.30.0 // indirect
github.com/libp2p/go-libp2p-pubsub v0.9.3 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.11.0 // indirect
github.com/multiformats/go-multibase v0.2.0 // indirect
github.com/multiformats/go-multicodec v0.9.0 // indirect
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef // indirect
google.golang.org/grpc v1.52.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.2.1 // indirect
)
Loading

0 comments on commit 2356a65

Please sign in to comment.