func (m *MinMax) Add(in telegraf.Metric) { id := in.HashID() if _, ok := m.cache[id]; !ok { // hit an uncached metric, create caches for first time: a := aggregate{ name: in.Name(), tags: in.Tags(), fields: make(map[string]minmax), } for k, v := range in.Fields() { if fv, ok := convert(v); ok { a.fields[k] = minmax{ min: fv, max: fv, } } } m.cache[id] = a } else { for k, v := range in.Fields() { if fv, ok := convert(v); ok { if _, ok := m.cache[id].fields[k]; !ok { // hit an uncached field of a cached metric m.cache[id].fields[k] = minmax{ min: fv, max: fv, } continue } if fv < m.cache[id].fields[k].min { tmp := m.cache[id].fields[k] tmp.min = fv m.cache[id].fields[k] = tmp } else if fv > m.cache[id].fields[k].max { tmp := m.cache[id].fields[k] tmp.max = fv m.cache[id].fields[k] = tmp } } } } }