From 06adb2d9ce4fa1f3021d52f2a53f8402ff72f7b2 Mon Sep 17 00:00:00 2001 From: tanlang Date: Wed, 27 Sep 2023 11:15:12 +0800 Subject: [PATCH 1/5] feat: update metrics --- marketevent/market_event.go | 4 +- metrics/exporter.go | 33 +-------------- metrics/metrics.go | 76 +++++++++++++--------------------- metrics/record_metrics_loop.go | 10 +++-- proofevent/proof_event.go | 6 +-- 5 files changed, 41 insertions(+), 88 deletions(-) diff --git a/marketevent/market_event.go b/marketevent/market_event.go index 44cddc6..fc8b8a1 100644 --- a/marketevent/market_event.go +++ b/marketevent/market_event.go @@ -87,8 +87,8 @@ func (m *MarketEventStream) ListenMarketEvent(ctx context.Context, policy *gtype ctx, _ = tag.New(ctx, tag.Upsert(metrics.IPKey, ip), tag.Upsert(metrics.MinerAddressKey, mAddr.String()), tag.Upsert(metrics.MinerTypeKey, "market")) - stats.Record(ctx, metrics.MinerRegister.M(1)) - stats.Record(ctx, metrics.MinerSource.M(1)) + metrics.MarketRegister.Tick(ctx) + metrics.MarketSource.Tick(ctx) out <- >ypes.RequestEvent{ ID: sharedTypes.NewUUID(), diff --git a/metrics/exporter.go b/metrics/exporter.go index 32c6007..c6cd05e 100644 --- a/metrics/exporter.go +++ b/metrics/exporter.go @@ -2,11 +2,9 @@ package metrics import ( "context" - "fmt" "github.com/ipfs-force-community/metrics" logging "github.com/ipfs/go-log/v2" - "go.opencensus.io/stats/view" v2API "github.com/filecoin-project/venus/venus-shared/api/gateway/v2" ) @@ -14,36 +12,7 @@ import ( var log = logging.Logger("metrics") func SetupMetrics(ctx context.Context, metricsConfig *metrics.MetricsConfig, api v2API.IGateway) error { - log.Infof("metrics config: enabled: %v, exporter type: %s, prometheus: %+v, graphite: %+v", - metricsConfig.Enabled, metricsConfig.Exporter.Type, metricsConfig.Exporter.Prometheus, - metricsConfig.Exporter.Graphite) - - if !metricsConfig.Enabled { - return nil - } - - if err := view.Register(views...); err != nil { - return fmt.Errorf("cannot register the view: %w", err) - } - - switch metricsConfig.Exporter.Type { - case metrics.ETPrometheus: - go func() { - if err := metrics.RegisterPrometheusExporter(ctx, metricsConfig.Exporter.Prometheus); err != nil { - log.Errorf("failed to register prometheus exporter err: %v", err) - } - log.Infof("prometheus exporter server graceful shutdown successful") - }() - - case metrics.ETGraphite: - if err := metrics.RegisterGraphiteExporter(ctx, metricsConfig.Exporter.Graphite); err != nil { - log.Errorf("failed to register graphite exporter: %v", err) - } - default: - log.Warnf("invalid exporter type: %s", metricsConfig.Exporter.Type) - } - + metrics.SetupMetrics(ctx, metricsConfig) go recordMetricsLoop(ctx, api) - return nil } diff --git a/metrics/metrics.go b/metrics/metrics.go index db02e12..c739c29 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -3,7 +3,8 @@ package metrics import ( "time" - "github.com/filecoin-project/go-jsonrpc/metrics" + rpcMetrics "github.com/filecoin-project/go-jsonrpc/metrics" + "github.com/ipfs-force-community/metrics" "go.opencensus.io/stats" "go.opencensus.io/stats/view" "go.opencensus.io/tag" @@ -26,20 +27,20 @@ var defaultMillisecondsDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0. var ( // wallet - WalletRegister = stats.Int64("wallet_register", "Wallet register", stats.UnitDimensionless) - WalletUnregister = stats.Int64("wallet_unregister", "Wallet unregister", stats.UnitDimensionless) - WalletNum = stats.Int64("wallet_num", "Wallet count", stats.UnitDimensionless) - WalletAddressNum = stats.Int64("wallet_address_num", "Address owned by wallet", stats.UnitDimensionless) - WalletAddAddr = stats.Int64("wallet_add_addr", "Wallet add a new address", stats.UnitDimensionless) - WalletRemoveAddr = stats.Int64("wallet_remove_addr", "Wallet remove a new address", stats.UnitDimensionless) - WalletConnNum = stats.Int64("wallet_conn_num", "Wallet connection count", stats.UnitDimensionless) + WalletRegister = stats.Int64("wallet/register", "Wallet register", stats.UnitDimensionless) + WalletUnregister = stats.Int64("wallet/unregister", "Wallet unregister", stats.UnitDimensionless) + WalletNum = stats.Int64("wallet/num", "Wallet count", stats.UnitDimensionless) + WalletAddressNum = stats.Int64("wallet/address_num", "Address owned by wallet", stats.UnitDimensionless) + WalletAddAddr = stats.Int64("wallet/add_addr", "Wallet add a new address", stats.UnitDimensionless) + WalletRemoveAddr = stats.Int64("wallet/remove_addr", "Wallet remove a new address", stats.UnitDimensionless) + WalletConnNum = stats.Int64("wallet/conn_num", "Wallet connection count", stats.UnitDimensionless) // miner - MinerRegister = stats.Int64("miner_register", "Miner register", stats.UnitDimensionless) - MinerUnregister = stats.Int64("miner_unregister", "Miner unregister", stats.UnitDimensionless) - MinerNum = stats.Int64("miner_num", "Wallet count", stats.UnitDimensionless) - MinerSource = stats.Int64("wallet_source", "Miner IP", stats.UnitDimensionless) - MinerConnNum = stats.Int64("miner_conn_num", "Miner connection count", stats.UnitDimensionless) + MinerRegister = metrics.NewCounter("proof/register", "Miner register", MinerAddressKey, IPKey, MinerTypeKey) + MinerUnregister = metrics.NewCounter("proof/unregister", "Miner unregister", MinerAddressKey, IPKey, MinerTypeKey) + MinerNum = metrics.NewCounter("proof/miner_num", "Wallet count", MinerAddressKey, MinerTypeKey) + MinerSource = metrics.NewCounter("proof/source", "Miner IP", MinerAddressKey, MinerTypeKey) + MinerConnNum = metrics.NewCounter("proof/conn_num", "Miner connection count", MinerAddressKey, IPKey, MinerTypeKey) // method call WalletSign = stats.Float64("wallet_sign", "Call WalletSign spent time", stats.UnitMilliseconds) @@ -48,6 +49,15 @@ var ( SectorsUnsealPiece = stats.Float64("sectors_unseal_piece", "Call SectorsUnsealPiece spent time", stats.UnitMilliseconds) ) +var ( + // market event + MarketRegister = metrics.NewCounter("market/register", "Market register", MinerAddressKey, IPKey, MinerTypeKey) + MarketUnregister = metrics.NewCounter("market/unregister", "Market unregister", MinerAddressKey, IPKey, MinerTypeKey) + MarketNum = metrics.NewCounter("market/num", "Market count", MinerAddressKey, MinerTypeKey) + MarketSource = metrics.NewCounter("market/source", "Market IP", MinerAddressKey, MinerTypeKey) + MarketConnNum = metrics.NewCounter("market/conn_num", "Market connection count", MinerAddressKey, IPKey, MinerTypeKey) +) + var ( // wallet walletRegisterView = &view.View{ @@ -86,33 +96,6 @@ var ( TagKeys: []tag.Key{WalletAccountKey, IPKey}, } - // miner - minerRegisterView = &view.View{ - Measure: MinerRegister, - Aggregation: view.Count(), - TagKeys: []tag.Key{MinerAddressKey, MinerTypeKey, IPKey}, - } - minerUnregisterView = &view.View{ - Measure: MinerUnregister, - Aggregation: view.Count(), - TagKeys: []tag.Key{MinerAddressKey, MinerTypeKey, IPKey}, - } - minerNumView = &view.View{ - Measure: MinerNum, - Aggregation: view.Count(), - TagKeys: []tag.Key{MinerAddressKey, MinerTypeKey}, - } - minerSourceView = &view.View{ - Measure: MinerSource, - Aggregation: view.Count(), - TagKeys: []tag.Key{MinerAddressKey, MinerTypeKey}, - } - minerConnNumView = &view.View{ - Measure: WalletConnNum, - Aggregation: view.Count(), - TagKeys: []tag.Key{MinerAddressKey, IPKey, MinerTypeKey}, - } - // method call walletSignView = &view.View{ Measure: WalletSign, @@ -145,19 +128,18 @@ var views = append([]*view.View{ walletRemoveAddrView, walletConnNumView, - minerRegisterView, - minerUnregisterView, - minerNumView, - minerSourceView, - minerConnNumView, - walletSignView, walletListView, computeProofView, sectorsUnsealPieceView, -}, metrics.DefaultViews...) +}, rpcMetrics.DefaultViews...) // SinceInMilliseconds returns the duration of time since the provide time as a float64. func SinceInMilliseconds(startTime time.Time) float64 { return float64(time.Since(startTime).Nanoseconds()) / 1e6 } + +func init() { + // register metrics + _ = view.Register(views...) +} diff --git a/metrics/record_metrics_loop.go b/metrics/record_metrics_loop.go index 36f9d76..7fc6e3b 100644 --- a/metrics/record_metrics_loop.go +++ b/metrics/record_metrics_loop.go @@ -65,9 +65,10 @@ func recordMarketConnectionInfo(ctx context.Context, api v2API.IGateway) { for _, state := range connsState { ctx, _ = tag.New(ctx, tag.Upsert(MinerAddressKey, state.Addr.String()), tag.Upsert(MinerTypeKey, "market")) for _, conn := range state.Conn.Connections { - _ = stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(IPKey, conn.IP)}, MinerConnNum.M(1)) + ctx, _ := tag.New(ctx, tag.Upsert(IPKey, conn.IP)) + MarketConnNum.Tick(ctx) } - stats.Record(ctx, MinerNum.M(1)) + MarketNum.Tick(ctx) } } @@ -87,8 +88,9 @@ func recordMinerConnectionInfo(ctx context.Context, api v2API.IGateway) { ctx, _ = tag.New(ctx, tag.Upsert(MinerTypeKey, "pprof"), tag.Upsert(MinerAddressKey, miner.String())) for _, conn := range state.Connections { - _ = stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(IPKey, conn.IP)}, MinerConnNum.M(1)) + ctx, _ := tag.New(ctx, tag.Upsert(IPKey, conn.IP)) + MinerNum.Tick(ctx) } - stats.Record(ctx, MinerNum.M(1)) + MinerNum.Tick(ctx) } } diff --git a/proofevent/proof_event.go b/proofevent/proof_event.go index 90abdd5..192ab02 100644 --- a/proofevent/proof_event.go +++ b/proofevent/proof_event.go @@ -103,8 +103,8 @@ func (e *ProofEventStream) ListenProofEvent(ctx context.Context, policy *sharedG ctx, _ = tag.New(ctx, tag.Upsert(metrics.IPKey, ip), tag.Upsert(metrics.MinerAddressKey, mAddr.String()), tag.Upsert(metrics.MinerTypeKey, "pprof")) - stats.Record(ctx, metrics.MinerRegister.M(1)) - stats.Record(ctx, metrics.MinerSource.M(1)) + metrics.MinerRegister.Tick(ctx) + metrics.MinerSource.Tick(ctx) reqEventChan <- &sharedGatewayTypes.RequestEvent{ ID: sharedTypes.NewUUID(), @@ -120,7 +120,7 @@ func (e *ProofEventStream) ListenProofEvent(ctx context.Context, policy *sharedG case <-ctx.Done(): removeChannel() close(out) - stats.Record(ctx, metrics.MinerUnregister.M(1)) + metrics.MinerUnregister.Tick(ctx) return case c := <-reqEventChan: out <- c From b01b987678a0b7faebf6d14c08ab5ca6f413cfe5 Mon Sep 17 00:00:00 2001 From: tanlang Date: Wed, 27 Sep 2023 11:21:44 +0800 Subject: [PATCH 2/5] chore: disable lint rule unused-parameter --- .golangci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 5120d24..0bdbab4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,3 +26,7 @@ issues: linters-settings: goconst: min-occurrences: 6 + revive: + rules: + - name: unused-parameter + disabled: true From 120c410d23251a63cdc10855f87d7785ef490403 Mon Sep 17 00:00:00 2001 From: tanlang Date: Wed, 27 Sep 2023 13:59:45 +0800 Subject: [PATCH 3/5] feat: correct for num count in metrics --- marketevent/market_event.go | 4 ++-- metrics/exporter.go | 5 ++++- metrics/metrics.go | 38 +++++++--------------------------- metrics/record_metrics_loop.go | 37 +++++++++++++++++---------------- walletevent/wallet_event.go | 2 -- 5 files changed, 33 insertions(+), 53 deletions(-) diff --git a/marketevent/market_event.go b/marketevent/market_event.go index fc8b8a1..06189aa 100644 --- a/marketevent/market_event.go +++ b/marketevent/market_event.go @@ -87,8 +87,8 @@ func (m *MarketEventStream) ListenMarketEvent(ctx context.Context, policy *gtype ctx, _ = tag.New(ctx, tag.Upsert(metrics.IPKey, ip), tag.Upsert(metrics.MinerAddressKey, mAddr.String()), tag.Upsert(metrics.MinerTypeKey, "market")) - metrics.MarketRegister.Tick(ctx) - metrics.MarketSource.Tick(ctx) + metrics.MinerRegister.Tick(ctx) + metrics.MinerSource.Tick(ctx) out <- >ypes.RequestEvent{ ID: sharedTypes.NewUUID(), diff --git a/metrics/exporter.go b/metrics/exporter.go index c6cd05e..3184b88 100644 --- a/metrics/exporter.go +++ b/metrics/exporter.go @@ -12,7 +12,10 @@ import ( var log = logging.Logger("metrics") func SetupMetrics(ctx context.Context, metricsConfig *metrics.MetricsConfig, api v2API.IGateway) error { - metrics.SetupMetrics(ctx, metricsConfig) + err := metrics.SetupMetrics(ctx, metricsConfig) + if err != nil { + return err + } go recordMetricsLoop(ctx, api) return nil } diff --git a/metrics/metrics.go b/metrics/metrics.go index c739c29..7e70fe7 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -29,18 +29,15 @@ var ( // wallet WalletRegister = stats.Int64("wallet/register", "Wallet register", stats.UnitDimensionless) WalletUnregister = stats.Int64("wallet/unregister", "Wallet unregister", stats.UnitDimensionless) - WalletNum = stats.Int64("wallet/num", "Wallet count", stats.UnitDimensionless) - WalletAddressNum = stats.Int64("wallet/address_num", "Address owned by wallet", stats.UnitDimensionless) WalletAddAddr = stats.Int64("wallet/add_addr", "Wallet add a new address", stats.UnitDimensionless) WalletRemoveAddr = stats.Int64("wallet/remove_addr", "Wallet remove a new address", stats.UnitDimensionless) - WalletConnNum = stats.Int64("wallet/conn_num", "Wallet connection count", stats.UnitDimensionless) // miner MinerRegister = metrics.NewCounter("proof/register", "Miner register", MinerAddressKey, IPKey, MinerTypeKey) MinerUnregister = metrics.NewCounter("proof/unregister", "Miner unregister", MinerAddressKey, IPKey, MinerTypeKey) - MinerNum = metrics.NewCounter("proof/miner_num", "Wallet count", MinerAddressKey, MinerTypeKey) MinerSource = metrics.NewCounter("proof/source", "Miner IP", MinerAddressKey, MinerTypeKey) - MinerConnNum = metrics.NewCounter("proof/conn_num", "Miner connection count", MinerAddressKey, IPKey, MinerTypeKey) + MinerNum = metrics.NewInt64("proof/miner_num", "Wallet count", "", MinerTypeKey) + MinerConnNum = metrics.NewInt64("proof/conn_num", "Miner connection count", "", MinerTypeKey) // method call WalletSign = stats.Float64("wallet_sign", "Call WalletSign spent time", stats.UnitMilliseconds) @@ -50,12 +47,11 @@ var ( ) var ( - // market event - MarketRegister = metrics.NewCounter("market/register", "Market register", MinerAddressKey, IPKey, MinerTypeKey) - MarketUnregister = metrics.NewCounter("market/unregister", "Market unregister", MinerAddressKey, IPKey, MinerTypeKey) - MarketNum = metrics.NewCounter("market/num", "Market count", MinerAddressKey, MinerTypeKey) - MarketSource = metrics.NewCounter("market/source", "Market IP", MinerAddressKey, MinerTypeKey) - MarketConnNum = metrics.NewCounter("market/conn_num", "Market connection count", MinerAddressKey, IPKey, MinerTypeKey) + + // wallet event + WalletNum = metrics.NewInt64("wallet/num", "Wallet count", stats.UnitDimensionless) + WalletAddressNum = metrics.NewInt64("wallet/address_num", "Address owned by wallet", stats.UnitDimensionless) + WalletConnNum = metrics.NewInt64("wallet/conn_num", "Wallet connection count", stats.UnitDimensionless) ) var ( @@ -70,16 +66,7 @@ var ( Aggregation: view.Count(), TagKeys: []tag.Key{WalletAccountKey, IPKey}, } - walletNumView = &view.View{ - Measure: WalletNum, - Aggregation: view.Count(), - TagKeys: []tag.Key{WalletAccountKey}, - } - walletAddressNumView = &view.View{ - Measure: WalletAddressNum, - Aggregation: view.Count(), - TagKeys: []tag.Key{WalletAccountKey, WalletAddressKey}, - } + walletAddAddrView = &view.View{ Measure: WalletAddAddr, Aggregation: view.Count(), @@ -90,11 +77,6 @@ var ( Aggregation: view.Count(), TagKeys: []tag.Key{WalletAccountKey, WalletAddressKey}, } - walletConnNumView = &view.View{ - Measure: WalletConnNum, - Aggregation: view.Count(), - TagKeys: []tag.Key{WalletAccountKey, IPKey}, - } // method call walletSignView = &view.View{ @@ -122,12 +104,8 @@ var ( var views = append([]*view.View{ walletRegisterView, walletUnregisterView, - walletNumView, - walletAddressNumView, walletAddAddrView, walletRemoveAddrView, - walletConnNumView, - walletSignView, walletListView, computeProofView, diff --git a/metrics/record_metrics_loop.go b/metrics/record_metrics_loop.go index 7fc6e3b..453d9df 100644 --- a/metrics/record_metrics_loop.go +++ b/metrics/record_metrics_loop.go @@ -5,7 +5,6 @@ import ( "time" "github.com/filecoin-project/go-address" - "go.opencensus.io/stats" "go.opencensus.io/tag" v2API "github.com/filecoin-project/venus/venus-shared/api/gateway/v2" @@ -35,50 +34,55 @@ func recordWalletConnectionInfo(ctx context.Context, api v2API.IGateway) { return } + var walletNum, connNum int64 addrs := make(map[address.Address]struct{}) for _, detail := range walletDetails { ctx, _ = tag.New(ctx, tag.Upsert(WalletAccountKey, detail.Account)) - stats.Record(ctx, WalletNum.M(1)) + walletNum++ for _, conn := range detail.ConnectStates { - _ = stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(IPKey, conn.IP)}, WalletConnNum.M(1)) + connNum++ for _, addr := range conn.Addrs { if _, ok := addrs[addr]; ok { continue } addrs[addr] = struct{}{} - _ = stats.RecordWithTags(ctx, - []tag.Mutator{tag.Upsert(WalletAddressKey, addr.String())}, WalletAddressNum.M(1)) } } - addrs = make(map[address.Address]struct{}) } + + WalletNum.Set(ctx, walletNum) + WalletConnNum.Set(ctx, connNum) + WalletAddressNum.Set(ctx, int64(len(addrs))) } func recordMarketConnectionInfo(ctx context.Context, api v2API.IGateway) { + ctx, _ = tag.New(ctx, tag.Upsert(MinerTypeKey, "market")) connsState, err := api.ListMarketConnectionsState(ctx) if err != nil { log.Warnf("failed to get market connections state %v", err) return } + var connNum int64 for _, state := range connsState { - ctx, _ = tag.New(ctx, tag.Upsert(MinerAddressKey, state.Addr.String()), tag.Upsert(MinerTypeKey, "market")) - for _, conn := range state.Conn.Connections { - ctx, _ := tag.New(ctx, tag.Upsert(IPKey, conn.IP)) - MarketConnNum.Tick(ctx) - } - MarketNum.Tick(ctx) + + connNum += int64(len(state.Conn.Connections)) } + MinerConnNum.Set(ctx, connNum) + MinerNum.Set(ctx, int64(len(connsState))) } func recordMinerConnectionInfo(ctx context.Context, api v2API.IGateway) { + ctx, _ = tag.New(ctx, tag.Upsert(MinerTypeKey, "pprof")) + miners, err := api.ListConnectedMiners(ctx) if err != nil { log.Warnf("faield to list connected miners %v", err) return } + var connNum int64 for _, miner := range miners { state, err := api.ListMinerConnection(ctx, miner) if err != nil { @@ -86,11 +90,8 @@ func recordMinerConnectionInfo(ctx context.Context, api v2API.IGateway) { return } - ctx, _ = tag.New(ctx, tag.Upsert(MinerTypeKey, "pprof"), tag.Upsert(MinerAddressKey, miner.String())) - for _, conn := range state.Connections { - ctx, _ := tag.New(ctx, tag.Upsert(IPKey, conn.IP)) - MinerNum.Tick(ctx) - } - MinerNum.Tick(ctx) + connNum += int64(len(state.Connections)) } + MinerConnNum.Set(ctx, connNum) + MinerNum.Set(ctx, int64(len(miners))) } diff --git a/walletevent/wallet_event.go b/walletevent/wallet_event.go index b403635..8d155a3 100644 --- a/walletevent/wallet_event.go +++ b/walletevent/wallet_event.go @@ -335,8 +335,6 @@ func (w *WalletEventStream) getValidatedAddress(ctx context.Context, channel *ty return nil, err } validAddrs = append(validAddrs, addr) - _ = stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(metrics.WalletAddressKey, addr.String())}, - metrics.WalletAddressNum.M(1)) } return validAddrs, nil From cae36c99c193cfdd5e5a03db9e40023fd21c4203 Mon Sep 17 00:00:00 2001 From: tanlang Date: Mon, 4 Dec 2023 14:36:37 +0800 Subject: [PATCH 4/5] feat: add metrics api state --- main.go | 4 ++++ metrics/metrics.go | 21 +++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index a0e2ddd..188461b 100644 --- a/main.go +++ b/main.go @@ -321,6 +321,10 @@ func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error { return err } + metrics2.ApiState.Set(ctx, 1) + defer func() { + metrics2.ApiState.Set(ctx, 0) + }() if err = srv.Serve(manet.NetListener(nl)); err != nil && err != http.ErrServerClosed { return err } diff --git a/metrics/metrics.go b/metrics/metrics.go index 7e70fe7..7cf12ab 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -27,31 +27,28 @@ var defaultMillisecondsDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0. var ( // wallet + WalletNum = metrics.NewInt64("wallet/num", "Wallet count", stats.UnitDimensionless) + WalletAddressNum = metrics.NewInt64("wallet/address_num", "Address owned by wallet", stats.UnitDimensionless) + WalletConnNum = metrics.NewInt64("wallet/conn_num", "Wallet connection count", stats.UnitDimensionless) WalletRegister = stats.Int64("wallet/register", "Wallet register", stats.UnitDimensionless) WalletUnregister = stats.Int64("wallet/unregister", "Wallet unregister", stats.UnitDimensionless) WalletAddAddr = stats.Int64("wallet/add_addr", "Wallet add a new address", stats.UnitDimensionless) WalletRemoveAddr = stats.Int64("wallet/remove_addr", "Wallet remove a new address", stats.UnitDimensionless) // miner - MinerRegister = metrics.NewCounter("proof/register", "Miner register", MinerAddressKey, IPKey, MinerTypeKey) - MinerUnregister = metrics.NewCounter("proof/unregister", "Miner unregister", MinerAddressKey, IPKey, MinerTypeKey) - MinerSource = metrics.NewCounter("proof/source", "Miner IP", MinerAddressKey, MinerTypeKey) - MinerNum = metrics.NewInt64("proof/miner_num", "Wallet count", "", MinerTypeKey) - MinerConnNum = metrics.NewInt64("proof/conn_num", "Miner connection count", "", MinerTypeKey) + MinerRegister = metrics.NewCounter("miner/register", "Miner register", MinerAddressKey, IPKey, MinerTypeKey) + MinerUnregister = metrics.NewCounter("miner/unregister", "Miner unregister", MinerAddressKey, IPKey, MinerTypeKey) + MinerSource = metrics.NewCounter("miner/source", "Miner IP", MinerAddressKey, MinerTypeKey) + MinerNum = metrics.NewInt64("miner/num", "Wallet count", "", MinerTypeKey) + MinerConnNum = metrics.NewInt64("miner/conn_num", "Miner connection count", "", MinerTypeKey) // method call WalletSign = stats.Float64("wallet_sign", "Call WalletSign spent time", stats.UnitMilliseconds) WalletList = stats.Float64("wallet_list", "Call WalletList spent time", stats.UnitMilliseconds) ComputeProof = stats.Float64("compute_proof", "Call ComputeProof spent time", stats.UnitMilliseconds) SectorsUnsealPiece = stats.Float64("sectors_unseal_piece", "Call SectorsUnsealPiece spent time", stats.UnitMilliseconds) -) -var ( - - // wallet event - WalletNum = metrics.NewInt64("wallet/num", "Wallet count", stats.UnitDimensionless) - WalletAddressNum = metrics.NewInt64("wallet/address_num", "Address owned by wallet", stats.UnitDimensionless) - WalletConnNum = metrics.NewInt64("wallet/conn_num", "Wallet connection count", stats.UnitDimensionless) + ApiState = metrics.NewInt64("api/state", "api service state. 0: down, 1: up", "") ) var ( From c970795c799ac14d0b6c1e4af8fce8f97ddd3f1c Mon Sep 17 00:00:00 2001 From: tanlang Date: Thu, 7 Dec 2023 16:17:32 +0800 Subject: [PATCH 5/5] chore: update metrics --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a6998a9..9f5dcff 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/filecoin-project/venus v1.14.0 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 - github.com/ipfs-force-community/metrics v1.0.1-0.20231011024528-8c881d456601 + github.com/ipfs-force-community/metrics v1.0.1-0.20231207081445-30178e706d09 github.com/ipfs-force-community/sophon-auth v1.14.0 github.com/ipfs-force-community/sophon-miner v1.14.0 github.com/ipfs/go-cid v0.4.1 diff --git a/go.sum b/go.sum index 71fd82d..87b8d5b 100644 --- a/go.sum +++ b/go.sum @@ -476,8 +476,8 @@ github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 h1:W9WBk7 github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= github.com/ipfs-force-community/go-jsonrpc v0.1.9 h1:5QavBltfvV6fz/+EbYsCkVxJ1MSJncZm6YuPs1SLdZU= github.com/ipfs-force-community/go-jsonrpc v0.1.9/go.mod h1:jBSvPTl8V1N7gSTuCR4bis8wnQnIjHbRPpROol6iQKM= -github.com/ipfs-force-community/metrics v1.0.1-0.20231011024528-8c881d456601 h1:zxKQ30KAD6KfvSFAx9tuqQXLDsEHyF+eVaUBXXYC2bU= -github.com/ipfs-force-community/metrics v1.0.1-0.20231011024528-8c881d456601/go.mod h1:wM6EmkEcnJgWOFcVytgvK0u15awEmt8He0f2kAdsFDA= +github.com/ipfs-force-community/metrics v1.0.1-0.20231207081445-30178e706d09 h1:qEI6ItxKtgOupMMuGJwqK5zEzztKKPUP1QKq9g+X5bM= +github.com/ipfs-force-community/metrics v1.0.1-0.20231207081445-30178e706d09/go.mod h1:wM6EmkEcnJgWOFcVytgvK0u15awEmt8He0f2kAdsFDA= github.com/ipfs-force-community/sophon-auth v1.14.0 h1:ctBJ6UHkcytEzfVPgiiHo0cW4FGQrE7r1H3Um0FcHbo= github.com/ipfs-force-community/sophon-auth v1.14.0/go.mod h1:d6J6u3zyIwcEajRho5BhVBcoIChEf0K76wP4yJEfEhc= github.com/ipfs-force-community/sophon-miner v1.14.0 h1:3c+EoHBM4Ir0EnbPQCJpkNmgAoBR8chDZO0MPRYpYT4=