MCPcopy
hub / github.com/deepflowio/deepflow / RegisterStatsdTable

Method RegisterStatsdTable

server/controller/statsd/statsd.go:68–139  ·  view source on GitHub ↗
(stable Statsdtable)

Source from the content-addressed store, hash-verified

66}
67
68func (s *StatsdMonitor) RegisterStatsdTable(stable Statsdtable) {
69 if !s.enable {
70 return
71 }
72
73 if err := s.initStatsdClient(); err != nil {
74 log.Warning(err)
75 return
76 }
77
78 encoder := new(codec.SimpleEncoder)
79
80 statter := stable.GetStatter()
81 keys := []string{}
82 for key := range statter.GlobalTags {
83 keys = append(keys, key)
84 }
85 sort.Strings(keys)
86
87 // collect
88 timeStamp := time.Now().Unix()
89 dfStats := &pb.Stats{}
90 for _, e := range statter.Element {
91 for mfName, mfValues := range e.MetricsFloatNameToValues {
92 name := e.VirtualTableName
93 hostName := os.Getenv(common.NODE_NAME_KEY)
94 tagNames := []string{e.PrivateTagKey, "host"}
95 tagValues := []string{mfName, hostName}
96
97 if e.UseGlobalTag {
98 tagNames = append(tagNames, keys...)
99 for _, k := range keys {
100 tagValues = append(tagValues, statter.GlobalTags[k])
101 }
102 }
103
104 metricsFloatNames := []string{}
105 metricsFloatValues := []float64{}
106 var vSum float64
107 for _, v := range mfValues {
108 vSum += v
109 }
110 switch e.MetricType {
111 case MetricInc:
112 metricsFloatNames = []string{"count"}
113 metricsFloatValues = []float64{vSum}
114 case MetricTiming:
115 vLen := float64(len(mfValues))
116 vAVG, _ := strconv.ParseFloat(fmt.Sprintf("%.3f", vSum/vLen), 64)
117 metricsFloatNames = []string{"avg", "len"}
118 if vLen == 1 && vAVG == 0 {
119 vLen = 0
120 }
121 metricsFloatValues = []float64{vAVG, vLen}
122 default:
123 continue
124 }
125

Callers 8

sendStatsdMethod · 0.80
GetCloudDataMethod · 0.80
GetCloudDataMethod · 0.80
GetCloudDataMethod · 0.80
GetCloudDataMethod · 0.80
GetCloudDataMethod · 0.80
GetKubernetesResponseMethod · 0.80

Calls 7

initStatsdClientMethod · 0.95
EncodeMethod · 0.95
GetStatterMethod · 0.65
ResetMethod · 0.65
WarningMethod · 0.45
WriteMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected