(stable Statsdtable)
| 66 | } |
| 67 | |
| 68 | func (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 |
no test coverage detected