github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/cluster/calcium/metrics.go (about) 1 package calcium 2 3 import ( 4 "context" 5 6 "github.com/sanity-io/litter" 7 8 "github.com/projecteru2/core/log" 9 "github.com/projecteru2/core/metrics" 10 "github.com/projecteru2/core/types" 11 ) 12 13 // InitMetrics . 14 func (c *Calcium) InitMetrics(ctx context.Context) { 15 logger := log.WithFunc("calcium.InitMetrics") 16 metricsDescriptions, err := c.rmgr.GetMetricsDescription(ctx) 17 if err != nil { 18 logger.Error(ctx, err, "failed to get metrics description") 19 return 20 } 21 if err = metrics.InitMetrics(ctx, c.config, metricsDescriptions); err != nil { 22 logger.Error(ctx, err, "failed to init metrics") 23 return 24 } 25 logger.Infof(ctx, "init metrics success \n%+v", litter.Sdump(metricsDescriptions)) 26 } 27 28 func (c *Calcium) doSendNodeMetrics(ctx context.Context, node *types.Node) { 29 nodeMetrics, err := c.rmgr.GetNodeMetrics(ctx, node) 30 if err != nil { 31 log.WithFunc("calcium.doSendNodeMetrics").Errorf(ctx, err, "convert node %s resource info to metrics failed", node.Name) 32 return 33 } 34 metrics.Client.SendMetrics(ctx, nodeMetrics...) 35 }