-
Notifications
You must be signed in to change notification settings - Fork 1
import "github.com/AarC10/GSW-V2/lib/db"- func CreateQuery(measurements MeasurementGroup) string
- type BatchHandler
- type Handler
- type InfluxDBV1Config
-
type InfluxDBV1Handler
- func (h *InfluxDBV1Handler) Close() error
- func (h *InfluxDBV1Handler) CreateQuery(measurements MeasurementGroup) string
- func (h *InfluxDBV1Handler) Initialize(host string, port int) error
- func (h *InfluxDBV1Handler) InitializeWithConfig(cfg InfluxDBV1Config) error
- func (h *InfluxDBV1Handler) Insert(measurements MeasurementGroup) error
- type InfluxDBV2Config
-
type InfluxDBV2Handler
- func (handler *InfluxDBV2Handler) BlockingInsert(ctx context.Context, measurements MeasurementGroup) error
- func (handler *InfluxDBV2Handler) Close() error
- func (handler *InfluxDBV2Handler) CreateQuery(_ MeasurementGroup) string
- func (handler *InfluxDBV2Handler) Flush() error
- func (handler *InfluxDBV2Handler) Initialize(host string, port int) error
- func (handler *InfluxDBV2Handler) InitializeWithConfig(cfg InfluxDBV2Config) error
- func (handler *InfluxDBV2Handler) Insert(measurements MeasurementGroup) error
- func (handler *InfluxDBV2Handler) InsertBatch(batch []MeasurementGroup) error
- type Measurement
- type MeasurementGroup
- type Precision
func CreateQuery(measurements MeasurementGroup) stringCreateQuery generates InfluxDB query for measurement group
BatchHandler extends Handler with batch write support
type BatchHandler interface {
Handler
Flush() error
}Handler is an interface for database access implementations
type Handler interface {
// Insert sends the measurement data to the database.
Insert(measurements MeasurementGroup) error
// CreateQuery generates the database query for measurementGroup.
CreateQuery(measurements MeasurementGroup) string
// Close closes the database client when done.
Close() error
}InfluxDBV1Config holds the fields needed for UDP writes.
type InfluxDBV1Config struct {
Host string
Port int
}InfluxDBV1Handler is a DB Handler implementation for InfluxDB v1
type InfluxDBV1Handler struct {
// contains filtered or unexported fields
}func (h *InfluxDBV1Handler) Close() errorClose closes the InfluxDB UDP client when done
func (h *InfluxDBV1Handler) CreateQuery(measurements MeasurementGroup) stringCreateQuery generates InfluxDB query for measurement group
func (h *InfluxDBV1Handler) Initialize(host string, port int) errorInitialize sets up the InfluxDB UDP connection
func (h *InfluxDBV1Handler) InitializeWithConfig(cfg InfluxDBV1Config) errorInitializeWithConfig sets up the InfluxDB UDP connection.
func (h *InfluxDBV1Handler) Insert(measurements MeasurementGroup) errorInsert sends the measurement group data to InfluxDB using UDP
InfluxDBV2Config holds the fields needed by the InfluxDB v2 client.
type InfluxDBV2Config struct {
URL string
Token string
Org string
Bucket string
BatchSize uint
FlushInterval uint
Precision Precision
}InfluxDBV2Handler is a BatchHandler implementation for InfluxDB v1
type InfluxDBV2Handler struct {
// contains filtered or unexported fields
}func (handler *InfluxDBV2Handler) BlockingInsert(ctx context.Context, measurements MeasurementGroup) errorBlockingInsert writes a point using the blocking write API.
func (handler *InfluxDBV2Handler) Close() errorClose flushes pending writes and closes the client.
func (handler *InfluxDBV2Handler) CreateQuery(_ MeasurementGroup) stringCreateQuery generates InfluxDB line protocol for a MeasurementGroup. This is literally useless so just return nothing.
func (handler *InfluxDBV2Handler) Flush() errorFlush forces all buffered points to be sent immediately.
func (handler *InfluxDBV2Handler) Initialize(host string, port int) errorInitialize satisfies the Handler interface using host/port only. This is a wrapper around InitializeWithConfig that fills in the URL and leaves.
func (handler *InfluxDBV2Handler) InitializeWithConfig(cfg InfluxDBV2Config) errorInitializeWithConfig sets up the InfluxDB v2 client with full config.
func (handler *InfluxDBV2Handler) Insert(measurements MeasurementGroup) errorInsert writes a MeasurementGroup to InfluxDB v2 as a single point. The write is buffered and flushed based on batch size and flush interval.
func (handler *InfluxDBV2Handler) InsertBatch(batch []MeasurementGroup) errorInsertBatch writes multiple MeasurementGroups in one shot and flushes.
Measurement is a single measurement to be sent to the database
type Measurement struct {
Name string // Name of the measurement
Value string // Value of the measurement
}MeasurementGroup is a group of measurements to be sent to the database
type MeasurementGroup struct {
DatabaseName string // Name of the database
Timestamp int64 // Unix timestamp in nanoseconds
Measurements []Measurement // List of measurements to be sent
}Precision constrains write precision to values supported by InfluxDB.
type Precision stringconst (
PrecisionNS Precision = "ns"
PrecisionUS Precision = "us"
PrecisionMS Precision = "ms"
PrecisionS Precision = "s"
)func ParsePrecision(raw string) (Precision, error)ParsePrecision normalizes and validates config precision values.
func (p Precision) Duration() (time.Duration, error)Duration maps precision values to the influx client write precision option.
Generated by gomarkdoc