diff --git a/agent.go b/agent.go index 93c53f13..9c9052ac 100644 --- a/agent.go +++ b/agent.go @@ -294,8 +294,9 @@ func (a *Agent) initStatus() { a.recoverStatus() // here we add the metrics for recover application := a.agentURL.GetParam(motan.ApplicationKey, metrics.DefaultStatApplication) - key := metrics.DefaultStatRole + metrics.KeyDelimiter + application + metrics.KeyDelimiter + "abnormal_exit.total_count" - metrics.AddCounter(metrics.DefaultStatGroup, metrics.DefaultStatService, key, 1) + keys := []string{metrics.DefaultStatRole, application, "abnormal_exit"} + metrics.AddCounterWithKeys(metrics.DefaultStatGroup, "", metrics.DefaultStatService, + keys, ".total_count", 1) } else { atomic.StoreInt64(&a.status, http.StatusServiceUnavailable) } diff --git a/metrics/metrics.go b/metrics/metrics.go index 614e9dc1..1739f600 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -200,6 +200,10 @@ func AddGauge(group string, service string, key string, value int64) { sendEvent(eventGauge, group, service, key, value) } +func AddGaugeWithKeys(group, groupSuffix string, service string, keys []string, keySuffix string, value int64) { + sendEventWithKeys(eventGauge, group, groupSuffix, service, keys, keySuffix, value) +} + // AddCounterWithKeys arguments: group & groupSuffix & service & keys elements & keySuffix is text without escaped func AddCounterWithKeys(group, groupSuffix string, service string, keys []string, keySuffix string, value int64) { sendEventWithKeys(eventCounter, group, groupSuffix, service, keys, keySuffix, value) @@ -252,7 +256,8 @@ func RegisterStatusSampleFunc(key string, sf func() int64) { func sampleStatus(application string) { defer motan.HandlePanic(nil) sampler.RangeDo(func(key string, value sampler.StatusSampler) bool { - AddGauge(DefaultStatGroup, DefaultStatService, DefaultStatRole+KeyDelimiter+application+KeyDelimiter+key, value.Sample()) + AddGaugeWithKeys(DefaultStatGroup, "", DefaultStatService, + []string{DefaultStatRole, application, key}, "", value.Sample()) return true }) } @@ -801,8 +806,9 @@ func StartReporter(ctx *motan.Context) { if ctx.AgentURL != nil { application := ctx.AgentURL.GetParam(motan.ApplicationKey, DefaultStatApplication) motan.PanicStatFunc = func() { - key := DefaultStatRole + KeyDelimiter + application + KeyDelimiter + "panic.total_count" - AddCounter(DefaultStatGroup, DefaultStatService, key, 1) + keys := []string{DefaultStatRole, application, "panic"} + AddCounterWithKeys(DefaultStatGroup, "", DefaultStatService, + keys, ".total_count", 1) } startSampleStatus(application) }