buildMetrics builds the metrics part of the report to be sent to the stats server
()
| 111 | |
| 112 | // buildMetrics builds the metrics part of the report to be sent to the stats server |
| 113 | func buildMetrics() map[string]interface{} { |
| 114 | result := map[string]interface{}{ |
| 115 | "memstats": memstats(), |
| 116 | "num_cpu": runtime.NumCPU(), |
| 117 | "num_goroutine": runtime.NumGoroutine(), |
| 118 | } |
| 119 | expvar.Do(func(kv expvar.KeyValue) { |
| 120 | if !strings.HasPrefix(kv.Key, statsPrefix) || kv.Key == statsPrefix+targetKey || kv.Key == statsPrefix+editionKey { |
| 121 | return |
| 122 | } |
| 123 | var value interface{} |
| 124 | switch v := kv.Value.(type) { |
| 125 | case *expvar.Int: |
| 126 | value = v.Value() |
| 127 | case *expvar.Float: |
| 128 | value = v.Value() |
| 129 | case *expvar.String: |
| 130 | value = v.Value() |
| 131 | case *Statistics: |
| 132 | value = v.Value() |
| 133 | case *Counter: |
| 134 | v.updateRate() |
| 135 | value = v.Value() |
| 136 | v.reset() |
| 137 | case *WordCounter: |
| 138 | value = v.Value() |
| 139 | default: |
| 140 | value = v.String() |
| 141 | } |
| 142 | result[strings.TrimPrefix(kv.Key, statsPrefix)] = value |
| 143 | }) |
| 144 | return result |
| 145 | } |
| 146 | |
| 147 | func memstats() interface{} { |
| 148 | stats := new(runtime.MemStats) |
no test coverage detected