MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Add

Method Add

internal/metrics/task_base.go:21–67  ·  view source on GitHub ↗

Add 添加数据

(obj MetricInterface)

Source from the content-addressed store, hash-verified

19
20// Add 添加数据
21func (this *BaseTask) Add(obj MetricInterface) {
22 if this.isStopped || !this.isLoaded {
23 return
24 }
25
26 var keys = []string{}
27 for _, key := range this.itemConfig.Keys {
28 var k = obj.MetricKey(key)
29
30 // 忽略499状态
31 if key == "${status}" && k == "499" {
32 return
33 }
34
35 keys = append(keys, k)
36 }
37
38 v, ok := obj.MetricValue(this.itemConfig.Value)
39 if !ok {
40 return
41 }
42
43 var hash = UniqueKey(obj.MetricServerId(), keys, this.itemConfig.CurrentTime(), this.itemConfig.Version, this.itemConfig.Id)
44 var countItems int
45 this.statsLocker.RLock()
46 oldStat, ok := this.statsMap[hash]
47 if !ok {
48 countItems = len(this.statsMap)
49 }
50 this.statsLocker.RUnlock()
51 if ok {
52 atomic.AddInt64(&oldStat.Value, 1)
53 } else {
54 // 防止过载
55 if countItems < MaxQueueSize {
56 this.statsLocker.Lock()
57 this.statsMap[hash] = &Stat{
58 ServerId: obj.MetricServerId(),
59 Keys: keys,
60 Value: v,
61 Time: this.itemConfig.CurrentTime(),
62 Hash: hash,
63 }
64 this.statsLocker.Unlock()
65 }
66 }
67}
68
69func (this *BaseTask) Item() *serverconfigs.MetricItemConfig {
70 return this.itemConfig

Callers

nothing calls this directly

Calls 8

UniqueKeyFunction · 0.85
RLockMethod · 0.80
RUnlockMethod · 0.80
MetricKeyMethod · 0.65
MetricValueMethod · 0.65
MetricServerIdMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected