github.com/influxdata/telegraf@v1.30.3/accumulator.go (about) 1 package telegraf 2 3 import ( 4 "time" 5 ) 6 7 // Accumulator allows adding metrics to the processing flow. 8 type Accumulator interface { 9 // AddFields adds a metric to the accumulator with the given measurement 10 // name, fields, and tags (and timestamp). If a timestamp is not provided, 11 // then the accumulator sets it to "now". 12 AddFields(measurement string, 13 fields map[string]interface{}, 14 tags map[string]string, 15 t ...time.Time) 16 17 // AddGauge is the same as AddFields, but will add the metric as a "Gauge" type 18 AddGauge(measurement string, 19 fields map[string]interface{}, 20 tags map[string]string, 21 t ...time.Time) 22 23 // AddCounter is the same as AddFields, but will add the metric as a "Counter" type 24 AddCounter(measurement string, 25 fields map[string]interface{}, 26 tags map[string]string, 27 t ...time.Time) 28 29 // AddSummary is the same as AddFields, but will add the metric as a "Summary" type 30 AddSummary(measurement string, 31 fields map[string]interface{}, 32 tags map[string]string, 33 t ...time.Time) 34 35 // AddHistogram is the same as AddFields, but will add the metric as a "Histogram" type 36 AddHistogram(measurement string, 37 fields map[string]interface{}, 38 tags map[string]string, 39 t ...time.Time) 40 41 // AddMetric adds a metric to the accumulator. 42 AddMetric(Metric) 43 44 // SetPrecision sets the timestamp rounding precision. All metrics 45 // added to the accumulator will have their timestamp rounded to the 46 // nearest multiple of precision. 47 SetPrecision(precision time.Duration) 48 49 // Report an error. 50 AddError(err error) 51 52 // Upgrade to a TrackingAccumulator with space for maxTracked 53 // metrics/batches. 54 WithTracking(maxTracked int) TrackingAccumulator 55 } 56 57 // TrackingID uniquely identifies a tracked metric group 58 type TrackingID uint64 59 60 // DeliveryInfo provides the results of a delivered metric group. 61 type DeliveryInfo interface { 62 // ID is the TrackingID 63 ID() TrackingID 64 65 // Delivered returns true if the metric was processed successfully. 66 Delivered() bool 67 } 68 69 // TrackingAccumulator is an Accumulator that provides a signal when the 70 // metric has been fully processed. Sending more metrics than the accumulator 71 // has been allocated for without reading status from the Accepted or Rejected 72 // channels is an error. 73 type TrackingAccumulator interface { 74 Accumulator 75 76 // Add the Metric and arrange for tracking feedback after processing. 77 AddTrackingMetric(m Metric) TrackingID 78 79 // Add a group of Metrics and arrange for a signal when the group has been 80 // processed. 81 AddTrackingMetricGroup(group []Metric) TrackingID 82 83 // Delivered returns a channel that will contain the tracking results. 84 Delivered() <-chan DeliveryInfo 85 }