Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build stage
FROM golang:1.25-alpine AS builder
FROM golang:1.26-alpine AS builder

WORKDIR /build

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Metrics will be available at `http://localhost:2112/metrics`
- `--balance.scrape-interval`: Balance check scrape interval in seconds (default: 30)
- `--verifier.workers`: Number of concurrent workers for block verification (default: 50)
- `--verbose`: Enable verbose (debug level) logging (default: false)
- `--log-format`: Log output format, `console` (human-readable) or `json` (one JSON object per line, for Loki/ELK ingestion) (default: `console`)

### Example with Custom Endpoints

Expand Down Expand Up @@ -119,6 +120,8 @@ Monitor native token balances for one or more Celestia addresses:

This will query account balances every 30 seconds with automatic failover between RPC endpoints.

`https://` consensus endpoints are dialed over TLS (port 443 if none is given); `http://` and bare `host:port` endpoints use plaintext gRPC.

## Prometheus Metrics

The following metrics are exposed:
Expand Down Expand Up @@ -276,7 +279,7 @@ When `--balance.addresses` and `--balance.consensus-rpc-urls` are provided:

There are two independent debug logging mechanisms:

- `--verbose` flag: sets the application log level to debug.
- `--verbose` flag: sets the application log level to debug. Per-block and per-poll success messages (block verification, drift polls, balance checks, JSON-RPC health checks) are logged at debug level, so use `--verbose` to see them. Warnings and errors are always logged.
- `EVMETRICS_DEBUG=true` environment variable: logs DA submission details from the metrics package.

**Use cases**: Troubleshoot submission failures, verify submission flow.
Expand Down
30 changes: 22 additions & 8 deletions cmd/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -33,6 +34,7 @@ const (
flagDataNS = "data-namespace"
flagDuration = "duration"
flagVerbose = "verbose"
flagLogFormat = "log-format"
flagPort = "port"
flagChain = "chain-id"
flagReferenceNode = "reference-node"
Expand All @@ -59,6 +61,7 @@ type flagValues struct {
dataNS string
duration int
verbose bool
logFormat string
port int
chainID string
referenceNode string
Expand Down Expand Up @@ -92,6 +95,7 @@ func NewMonitorCmd() *cobra.Command {
cmd.Flags().StringVar(&flags.dataNS, flagDataNS, "", "Data namespace (my_app_data_namespace)")
cmd.Flags().IntVar(&flags.duration, flagDuration, 0, "Duration in seconds to stream (0 = infinite)")
cmd.Flags().BoolVar(&flags.verbose, flagVerbose, false, "Enable verbose logging")
cmd.Flags().StringVar(&flags.logFormat, flagLogFormat, "console", "Log output format: console or json")
cmd.Flags().IntVar(&flags.port, flagPort, 2112, "HTTP server port for metrics")
cmd.Flags().StringVar(&flags.chainID, flagChain, "testnet", "chainID identifier for metrics labels")
cmd.Flags().StringVar(&flags.referenceNode, flagReferenceNode, "", "Reference node RPC endpoint URL (sequencer) for drift monitoring")
Expand Down Expand Up @@ -159,17 +163,27 @@ func newClients(ctx context.Context, flags flagValues, logger zerolog.Logger) (*
return evnodeClient, evmClient, celestiaClient, nil
}

func monitorAndExportMetrics(_ *cobra.Command, _ []string) error {
// Setup logger
func newLogger(format string, verbose bool, w io.Writer) (zerolog.Logger, error) {
switch format {
case "console":
w = zerolog.ConsoleWriter{Out: w, TimeFormat: time.RFC3339}
case "json":
default:
return zerolog.Logger{}, fmt.Errorf("invalid --%s %q: must be console or json", flagLogFormat, format)
}

logLevel := zerolog.InfoLevel
if flags.verbose {
if verbose {
logLevel = zerolog.DebugLevel
}
logger := zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}).
Level(logLevel).
With().
Timestamp().
Logger()
return zerolog.New(w).Level(logLevel).With().Timestamp().Logger(), nil
}

func monitorAndExportMetrics(_ *cobra.Command, _ []string) error {
logger, err := newLogger(flags.logFormat, flags.verbose, os.Stdout)
if err != nil {
return err
}

// setup context with signal handling for graceful shutdown
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
Expand Down
54 changes: 54 additions & 0 deletions cmd/monitor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package cmd

import (
"bytes"
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
)

func TestNewLogger(t *testing.T) {
t.Run("json", func(t *testing.T) {
var buf bytes.Buffer
logger, err := newLogger("json", false, &buf)
require.NoError(t, err)

logger.Info().Msg("hello")

var entry map[string]any
require.NoError(t, json.Unmarshal(buf.Bytes(), &entry))
require.Equal(t, "info", entry["level"])
require.Equal(t, "hello", entry["message"])
require.Contains(t, entry, "time")
})

t.Run("console", func(t *testing.T) {
var buf bytes.Buffer
logger, err := newLogger("console", false, &buf)
require.NoError(t, err)

logger.Info().Msg("hello")

require.Contains(t, buf.String(), "hello")
require.False(t, json.Valid(buf.Bytes()))
})

t.Run("invalid format", func(t *testing.T) {
_, err := newLogger("xml", false, &bytes.Buffer{})
require.Error(t, err)
})

t.Run("verbose enables debug", func(t *testing.T) {
var buf bytes.Buffer
logger, err := newLogger("json", false, &buf)
require.NoError(t, err)
logger.Debug().Msg("hidden")
require.Empty(t, buf.String())

logger, err = newLogger("json", true, &buf)
require.NoError(t, err)
logger.Debug().Msg("shown")
require.Contains(t, buf.String(), `"message":"shown"`)
})
}
35 changes: 20 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module github.com/evstack/ev-metrics

go 1.25.6
go 1.26.0

require (
connectrpc.com/connect v1.19.1
github.com/celestiaorg/go-square/v3 v3.0.2
github.com/cosmos/cosmos-sdk v0.50.14
github.com/ethereum/go-ethereum v1.16.5
github.com/ethereum/go-ethereum v1.17.0
github.com/evstack/ev-node v1.0.0
github.com/prometheus/client_golang v1.23.2
github.com/rs/zerolog v1.34.0
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
golang.org/x/sync v0.20.0
google.golang.org/grpc v1.79.2
golang.org/x/sync v0.23.0
google.golang.org/grpc v1.83.1
google.golang.org/protobuf v1.36.11
)

Expand All @@ -33,6 +33,7 @@ require (
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
Expand All @@ -47,7 +48,7 @@ require (
github.com/cockroachdb/pebble v1.1.5 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.19 // indirect
github.com/cometbft/cometbft v0.38.21 // indirect
github.com/cometbft/cometbft-db v0.14.1 // indirect
github.com/consensys/gnark-crypto v0.18.1 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
Expand All @@ -60,7 +61,6 @@ require (
github.com/cosmos/ics23/go v0.11.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.15.0 // indirect
github.com/crate-crypto/go-eth-kzg v1.4.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.6.0 // indirect
Expand All @@ -71,8 +71,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.7.0 // indirect
github.com/emicklei/dot v1.6.2 // indirect
github.com/ethereum/c-kzg-4844/v2 v2.1.3 // indirect
github.com/ethereum/go-verkle v0.2.2 // indirect
github.com/ethereum/c-kzg-4844/v2 v2.1.5 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/filecoin-project/go-jsonrpc v0.10.1 // indirect
Expand All @@ -81,6 +80,8 @@ require (
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
Expand Down Expand Up @@ -153,20 +154,24 @@ require (
github.com/zondax/ledger-go v1.0.0 // indirect
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel v1.44.0 // indirect
go.opentelemetry.io/otel/metric v1.44.0 // indirect
go.opentelemetry.io/otel/trace v1.44.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.1 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.48.0 // indirect
golang.org/x/crypto v0.57.0 // indirect
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/net v0.51.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/term v0.40.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/net v0.60.0 // indirect
golang.org/x/sys v0.48.0 // indirect
golang.org/x/term v0.46.0 // indirect
golang.org/x/text v0.42.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260209200024-4cfbd4190f57 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260209200024-4cfbd4190f57 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.2 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand Down
Loading
Loading