add counter support, add lightning time
This commit is contained in:
@ -20,6 +20,7 @@ type MetricRecorder struct {
|
||||
type RecordOpts struct {
|
||||
Float64Gauge metric.Float64Gauge
|
||||
Int64Gauge metric.Int64Gauge
|
||||
Int64Counter metric.Int64Counter
|
||||
IntVal *int
|
||||
FloatVal *float64
|
||||
Attributes []attribute.KeyValue
|
||||
@ -59,6 +60,16 @@ func (r *MetricRecorder) Record(opts *RecordOpts) {
|
||||
return
|
||||
}
|
||||
r.recordFloat(opts.Float64Gauge, *opts.FloatVal, opts.Attributes...)
|
||||
} else if opts.Int64Counter != nil {
|
||||
if opts.IntVal == nil {
|
||||
log := r.l.Trace().Str("field", string(opts.Field))
|
||||
if opts.Station != nil {
|
||||
log = log.Str("station", opts.Station.Name)
|
||||
}
|
||||
log.Msg("Dropping nil float metric")
|
||||
return
|
||||
}
|
||||
r.recordCounter(opts.Int64Counter, *opts.IntVal, opts.Attributes...)
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,6 +82,19 @@ func (o *RecordOpts) keep() bool {
|
||||
return !slices.Contains(o.Station.DropMetrics, o.Field)
|
||||
}
|
||||
|
||||
func (r *MetricRecorder) recordCounter(
|
||||
m metric.Int64Counter, value int, attributes ...attribute.KeyValue,
|
||||
) {
|
||||
// Prepare metric attributes
|
||||
options := make([]metric.AddOption, 0, len(attributes))
|
||||
if len(attributes) > 0 {
|
||||
options = append(options, metric.WithAttributes(attributes...))
|
||||
}
|
||||
|
||||
val := int64(value)
|
||||
m.Add(r.ctx, val, options...)
|
||||
}
|
||||
|
||||
func (r *MetricRecorder) recordInt(
|
||||
m metric.Int64Gauge, value int, attributes ...attribute.KeyValue,
|
||||
) {
|
||||
|
Reference in New Issue
Block a user