Downsample data
This commit is contained in:
@@ -53,7 +53,11 @@ type QueryModel struct {
|
||||
Options QueryOptions `json:"options"`
|
||||
|
||||
// Direct from the gRPC interfaces
|
||||
RefID string `json:"-"`
|
||||
QueryType string `json:"-"`
|
||||
TimeRange backend.TimeRange `json:"-"`
|
||||
MaxDataPoints int64 `json:"-"`
|
||||
Interval time.Duration `json:"-"`
|
||||
}
|
||||
|
||||
// QueryOptions model
|
||||
@@ -91,11 +95,16 @@ type QueryFunctionParam = interface{}
|
||||
|
||||
// ReadQuery will read and validate Settings from the DataSourceConfg
|
||||
func ReadQuery(query backend.DataQuery) (QueryModel, error) {
|
||||
model := QueryModel{}
|
||||
model := QueryModel{
|
||||
RefID: query.RefID,
|
||||
QueryType: query.QueryType,
|
||||
TimeRange: query.TimeRange,
|
||||
MaxDataPoints: query.MaxDataPoints,
|
||||
Interval: query.Interval,
|
||||
}
|
||||
if err := json.Unmarshal(query.JSON, &model); err != nil {
|
||||
return model, fmt.Errorf("could not read query: %w", err)
|
||||
}
|
||||
|
||||
model.TimeRange = query.TimeRange
|
||||
return model, nil
|
||||
}
|
||||
|
||||
@@ -94,6 +94,21 @@ func (ds *ZabbixDatasourceInstance) queryNumericDataForItems(ctx context.Context
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, s := range series {
|
||||
if int64(s.Len()) > query.MaxDataPoints && true {
|
||||
downsampleFunc := consolidateBy
|
||||
if downsampleFunc == "" {
|
||||
downsampleFunc = "avg"
|
||||
}
|
||||
downsampled, err := applyGroupBy(s.TS, query.Interval.String(), downsampleFunc)
|
||||
if err == nil {
|
||||
s.TS = downsampled
|
||||
} else {
|
||||
ds.logger.Debug("Error downsampling series", "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frames := convertTimeSeriesToDataFrames(series)
|
||||
return frames, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user