diff --git a/README.md b/README.md index 2681799..4ecffea 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,10 @@ GLOBAL OPTIONS: --node value [ --node value ] rpc node endpoint to connect to (specify multiple for high availability) (default: "http://localhost:26657") --no-gov disable calls to gov module (useful for consumer chains) (default: false) --no-staking disable calls to staking module (useful for consumer chains) (default: false) + --denom value denom used in metrics label (eg. atom or uatom) + --denom-exponent value denom exponent (eg. 6 for atom, 1 for uatom) (default: 0) --validator value [ --validator value ] validator address(es) to track (use :my-label to add a custom label in metrics & ouput) + --x-gov value version of the gov module to use (v1|v1beta1) (default: "v1beta1") --help, -h show help --version, -v print the version ``` diff --git a/pkg/app/flags.go b/pkg/app/flags.go index e279cef..4a7369a 100644 --- a/pkg/app/flags.go +++ b/pkg/app/flags.go @@ -39,10 +39,13 @@ var Flags = []cli.Flag{ Name: "no-staking", Usage: "disable calls to staking module (useful for consumer chains)", }, + &cli.StringFlag{ + Name: "denom", + Usage: "denom used in metrics label (eg. atom or uatom)", + }, &cli.UintFlag{ - Name: "token-exponent", - Usage: "token exponent (ie. 6 for uatom)", - Value: 6, + Name: "denom-exponent", + Usage: "denom exponent (eg. 6 for atom, 1 for uatom)", }, &cli.StringSliceFlag{ Name: "validator", diff --git a/pkg/app/run.go b/pkg/app/run.go index 348fbc7..138a38c 100644 --- a/pkg/app/run.go +++ b/pkg/app/run.go @@ -37,7 +37,8 @@ func RunFunc(cCtx *cli.Context) error { nodes = cCtx.StringSlice("node") noGov = cCtx.Bool("no-gov") noStaking = cCtx.Bool("no-staking") - tokenExpon = cCtx.Uint("token-exponent") + denom = cCtx.String("denom") + denomExpon = cCtx.Uint("denom-exponent") validators = cCtx.StringSlice("validator") xGov = cCtx.String("x-gov") ) @@ -97,7 +98,8 @@ func RunFunc(cCtx *cli.Context) error { // if !noStaking { validatorsWatcher := watcher.NewValidatorsWatcher(trackedValidators, metrics, pool, watcher.ValidatorsWatcherOptions{ - TokenExponent: tokenExpon, + Denom: denom, + DenomExponent: denomExpon, }) errg.Go(func() error { return validatorsWatcher.Start(ctx) diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index ab5cd2d..929c97d 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -57,7 +57,7 @@ func New(namespace string) *Metrics { Name: "seat_price", Help: "Min seat price to be in the active set (ie. bonded tokens of the latest validator)", }, - []string{"chain_id"}, + []string{"chain_id", "denom"}, ), Rank: prometheus.NewGaugeVec( prometheus.GaugeOpts{ @@ -113,7 +113,7 @@ func New(namespace string) *Metrics { Name: "tokens", Help: "Number of staked tokens per validator", }, - []string{"chain_id", "address", "name"}, + []string{"chain_id", "address", "name", "denom"}, ), IsBonded: prometheus.NewGaugeVec( prometheus.GaugeOpts{ diff --git a/pkg/watcher/validators.go b/pkg/watcher/validators.go index 7845ca4..d6c2a5b 100644 --- a/pkg/watcher/validators.go +++ b/pkg/watcher/validators.go @@ -24,7 +24,8 @@ type ValidatorsWatcher struct { } type ValidatorsWatcherOptions struct { - TokenExponent uint + Denom string + DenomExponent uint } func NewValidatorsWatcher(validators []TrackedValidator, metrics *metrics.Metrics, pool *rpc.Pool, opts ValidatorsWatcherOptions) *ValidatorsWatcher { @@ -77,18 +78,18 @@ func (w *ValidatorsWatcher) handleValidators(chainID string, validators []stakin // Sort validators by tokens & status (bonded, unbonded, jailed) sort.Sort(RankedValidators(validators)) - tokenExponent := w.opts.TokenExponent - if tokenExponent == 0 { - tokenExponent = 1 + denomExponent := w.opts.DenomExponent + if denomExponent == 0 { + denomExponent = 1 } seatPrice := decimal.Zero for _, val := range validators { - tokens := decimal.NewFromBigInt(val.Tokens.BigInt(), -int32(tokenExponent)) + tokens := decimal.NewFromBigInt(val.Tokens.BigInt(), -int32(denomExponent)) if val.Status == staking.Bonded && (seatPrice.IsZero() || seatPrice.GreaterThan(tokens)) { seatPrice = tokens } - w.metrics.SeatPrice.WithLabelValues(chainID).Set(seatPrice.InexactFloat64()) + w.metrics.SeatPrice.WithLabelValues(chainID, w.opts.Denom).Set(seatPrice.InexactFloat64()) } for _, tracked := range w.validators { @@ -103,11 +104,11 @@ func (w *ValidatorsWatcher) handleValidators(chainID string, validators []stakin rank = i + 1 isBonded = val.Status == staking.Bonded isJailed = val.Jailed - tokens = decimal.NewFromBigInt(val.Tokens.BigInt(), -int32(tokenExponent)) + tokens = decimal.NewFromBigInt(val.Tokens.BigInt(), -int32(denomExponent)) ) w.metrics.Rank.WithLabelValues(chainID, address, name).Set(float64(rank)) - w.metrics.Tokens.WithLabelValues(chainID, address, name).Set(tokens.InexactFloat64()) + w.metrics.Tokens.WithLabelValues(chainID, address, name, w.opts.Denom).Set(tokens.InexactFloat64()) w.metrics.IsBonded.WithLabelValues(chainID, address, name).Set(metrics.BoolToFloat64(isBonded)) w.metrics.IsJailed.WithLabelValues(chainID, address, name).Set(metrics.BoolToFloat64(isJailed)) break diff --git a/pkg/watcher/validators_test.go b/pkg/watcher/validators_test.go index ef1376b..070b0f4 100644 --- a/pkg/watcher/validators_test.go +++ b/pkg/watcher/validators_test.go @@ -30,7 +30,7 @@ func TestValidatorsWatcher(t *testing.T) { metrics.New("cosmos_validator_watcher"), nil, ValidatorsWatcherOptions{ - TokenExponent: 6, + DenomExponent: 6, }, )