Align time series data if possible
This commit is contained in:
@@ -16,6 +16,7 @@ type ZabbixDatasourceSettingsDTO struct {
|
||||
CacheTTL string `json:"cacheTTL"`
|
||||
Timeout string `json:"timeout"`
|
||||
|
||||
DisableDataAlignment bool `json:"disableDataAlignment"`
|
||||
DisableReadOnlyUsersAck bool `json:"disableReadOnlyUsersAck"`
|
||||
}
|
||||
|
||||
@@ -27,6 +28,7 @@ type ZabbixDatasourceSettings struct {
|
||||
CacheTTL time.Duration
|
||||
Timeout time.Duration
|
||||
|
||||
DisableDataAlignment bool `json:"disableDataAlignment"`
|
||||
DisableReadOnlyUsersAck bool `json:"disableReadOnlyUsersAck"`
|
||||
}
|
||||
|
||||
@@ -61,7 +63,8 @@ type QueryFilter struct {
|
||||
|
||||
// QueryOptions model
|
||||
type QueryOptions struct {
|
||||
ShowDisabledItems bool `json:"showDisabledItems"`
|
||||
ShowDisabledItems bool `json:"showDisabledItems"`
|
||||
DisableDataAlignment bool `json:"disableDataAlignment"`
|
||||
}
|
||||
|
||||
// QueryOptions model
|
||||
|
||||
@@ -2,9 +2,11 @@ package datasource
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/gtime"
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/timeseries"
|
||||
"github.com/alexanderzobnin/grafana-zabbix/pkg/zabbix"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
@@ -33,6 +35,7 @@ func convertHistoryToTimeSeries(history zabbix.History, items []*zabbix.Item) []
|
||||
if len(pointItem.Hosts) > 0 {
|
||||
pointSeries.Meta.Name = fmt.Sprintf("%s: %s", pointItem.Hosts[0].Name, itemName)
|
||||
}
|
||||
pointSeries.Meta.Interval = parseItemUpdateInterval(pointItem.Delay)
|
||||
}
|
||||
|
||||
value := point.Value
|
||||
@@ -209,3 +212,18 @@ func getTrendPointValue(point zabbix.TrendPoint, valueType string) (float64, err
|
||||
|
||||
return 0, fmt.Errorf("failed to get trend value, unknown value type: %s", valueType)
|
||||
}
|
||||
|
||||
var fixedUpdateIntervalPattern = regexp.MustCompile(`^(\d+)([shd]?)$`)
|
||||
|
||||
func parseItemUpdateInterval(delay string) *time.Duration {
|
||||
if valid := fixedUpdateIntervalPattern.MatchString(delay); !valid {
|
||||
return nil
|
||||
}
|
||||
|
||||
interval, err := gtime.ParseInterval(delay)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &interval
|
||||
}
|
||||
|
||||
@@ -79,6 +79,16 @@ func (ds *ZabbixDatasourceInstance) queryNumericDataForItems(ctx context.Context
|
||||
}
|
||||
|
||||
series := convertHistoryToTimeSeries(history, items)
|
||||
|
||||
// Align time series data if possible
|
||||
if query.Options.DisableDataAlignment == false && ds.Settings.DisableDataAlignment == false {
|
||||
for _, s := range series {
|
||||
if s.Meta.Interval != nil {
|
||||
s.TS = s.TS.Align(*s.Meta.Interval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
series, err = applyFunctions(series, query.Functions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user