Skip to content

Commit

Permalink
Fix report (#378)
Browse files Browse the repository at this point in the history
* fix report cpu etc.
  • Loading branch information
snail007 authored Jan 11, 2024
1 parent 35e2bd1 commit c671e0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,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)
}
Expand Down
12 changes: 9 additions & 3 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit c671e0d

Please sign in to comment.