我从来没有合作过。但我会尽力回答。
您应该将go-metrics
注册表注册到配置中。
这是如何创建和使用注册表的示例(https://pkg.go.dev/gopkg.in/Shopify/sarama.v2#example-Config-Metrics):
// Our application registry
appMetricRegistry := metrics.NewRegistry()
appGauge := metrics.GetOrRegisterGauge("m1", appMetricRegistry)
appGauge.Update(1)
config := NewConfig()
// Use a prefix registry instead of the default local one
config.MetricRegistry = metrics.NewPrefixedChildRegistry(appMetricRegistry, "sarama.")
// Simulate a metric created by sarama without starting a broker
saramaGauge := metrics.GetOrRegisterGauge("m2", config.MetricRegistry)
saramaGauge.Update(2)
metrics.WriteOnce(appMetricRegistry, os.Stdout)
所以你应该创建注册表并将其设置为配置
appMetricRegistry := metrics.NewRegistry()
appGauge := metrics.GetOrRegisterGauge("m1", appMetricRegistry)
appGauge.Update(1)
saramaConfig := sarama.NewConfig()
saramaConfig.Version = <BrokerVersion>
// set it here
saramaConfig.MetricRegistry = metrics.NewPrefixedChildRegistry(appMetricRegistry, "sarama.")
client, err := sarama.NewClient(<brokerAddresses>, saramaConfig)
if err != nil {
log.Println("Unable to create sarama client")
panic(err)
}
config := client.Config()
MeanIncomingByteRate := metrics.GetOrRegisterMeter(getMetricNameForTopic("incoming-byte-rate", topic), config.MetricRegistry).RateMean(),