Documentation
¶
Overview ¶
package influxdb2 provides API for using InfluxDB client in Go It's intended to use with InfluxDB 2 server
Index ¶
- Constants
- func DefaultDialect() *domain.Dialect
- type Error
- type FluxColumn
- func (f *FluxColumn) DataType() string
- func (f *FluxColumn) DefaultValue() string
- func (f *FluxColumn) Index() int
- func (f *FluxColumn) IsGroup() bool
- func (f *FluxColumn) Name() string
- func (f *FluxColumn) SetDataType(dataType string)
- func (f *FluxColumn) SetDefaultValue(defaultValue string)
- func (f *FluxColumn) SetGroup(group bool)
- func (f *FluxColumn) SetName(name string)
- func (f *FluxColumn) String() string
- type FluxRecord
- func (r *FluxRecord) Field() string
- func (r *FluxRecord) Measurement() string
- func (r *FluxRecord) Start() time.Time
- func (r *FluxRecord) Stop() time.Time
- func (r *FluxRecord) String() string
- func (r *FluxRecord) Table() int
- func (r *FluxRecord) Time() time.Time
- func (r *FluxRecord) Value() interface{}
- func (r *FluxRecord) ValueByKey(key string) interface{}
- func (r *FluxRecord) Values() map[string]interface{}
- type FluxTableMetadata
- type InfluxDBClient
- type Options
- func (o *Options) BatchSize() uint
- func (o *Options) FlushInterval() uint
- func (o *Options) LogLevel() uint
- func (o *Options) MaxRetries() uint
- func (o *Options) Precision() time.Duration
- func (o *Options) RetryBufferLimit() uint
- func (o *Options) RetryInterval() uint
- func (o *Options) SetBatchSize(batchSize uint) *Options
- func (o *Options) SetFlushInterval(flushIntervalMs uint) *Options
- func (o *Options) SetLogLevel(logLevel uint) *Options
- func (o *Options) SetMaxRetries(maxRetries uint) *Options
- func (o *Options) SetPrecision(precision time.Duration) *Options
- func (o *Options) SetRetryBufferLimit(retryBufferLimit uint) *Options
- func (o *Options) SetRetryInterval(retryIntervalMs uint) *Options
- func (o *Options) SetTlsConfig(tlsConfig *tls.Config) *Options
- func (o *Options) SetUseGZip(useGZip bool) *Options
- func (o *Options) TlsConfig() *tls.Config
- func (o *Options) UseGZip() bool
- type Point
- func (m *Point) AddField(k string, v interface{}) *Point
- func (m *Point) AddTag(k, v string) *Point
- func (m *Point) FieldList() []*lp.Field
- func (m *Point) Name() string
- func (m *Point) SetTime(timestamp time.Time) *Point
- func (m *Point) SortFields() *Point
- func (m *Point) SortTags() *Point
- func (m *Point) TagList() []*lp.Tag
- func (m *Point) Time() time.Time
- type QueryApi
- type QueryTableResult
- type RequestCallback
- type ResponseCallback
- type WriteApi
- type WriteApiBlocking
Constants ¶
const (
Version = "1.0.0"
)
Variables ¶
This section is empty.
Functions ¶
func DefaultDialect ¶
DefaultDialect return flux query Dialect with full annotations (datatype, group, default), header and comma char as a delimiter
Types ¶
type Error ¶
Error represent error response from InfluxDBServer or http error
type FluxColumn ¶
type FluxColumn struct {
// contains filtered or unexported fields
}
FluxColumn holds flux query table column properties
func (*FluxColumn) DataType ¶
func (f *FluxColumn) DataType() string
DataType returns data type of the column
func (*FluxColumn) DefaultValue ¶
func (f *FluxColumn) DefaultValue() string
DefaultValue returns default value of the column
func (*FluxColumn) IsGroup ¶
func (f *FluxColumn) IsGroup() bool
IsGroup return true if the column is grouping column
func (*FluxColumn) SetDataType ¶
func (f *FluxColumn) SetDataType(dataType string)
SetDataType sets data type for the column
func (*FluxColumn) SetDefaultValue ¶
func (f *FluxColumn) SetDefaultValue(defaultValue string)
SetDefaultValue sets default value for the column
func (*FluxColumn) SetGroup ¶
func (f *FluxColumn) SetGroup(group bool)
SetGroup set group flag for the column
func (*FluxColumn) SetName ¶
func (f *FluxColumn) SetName(name string)
SetName sets name of the column
func (*FluxColumn) String ¶
func (f *FluxColumn) String() string
String returns FluxColumn string dump
type FluxRecord ¶
type FluxRecord struct {
// contains filtered or unexported fields
}
FluxRecord represents row in the flux query result table
func (*FluxRecord) Measurement ¶
func (r *FluxRecord) Measurement() string
Measurement returns the measurement name of the record
func (*FluxRecord) Start ¶
func (r *FluxRecord) Start() time.Time
Start returns the inclusive lower time bound of all records in the current table
func (*FluxRecord) Stop ¶
func (r *FluxRecord) Stop() time.Time
Stop returns the exclusive upper time bound of all records in the current table
func (*FluxRecord) String ¶
func (r *FluxRecord) String() string
String returns FluxRecord string dump
func (*FluxRecord) Table ¶
func (r *FluxRecord) Table() int
Table returns index of the table record belongs to
func (*FluxRecord) Time ¶
func (r *FluxRecord) Time() time.Time
Start returns the time of the record
func (*FluxRecord) Value ¶
func (r *FluxRecord) Value() interface{}
Value returns the actual field value
func (*FluxRecord) ValueByKey ¶
func (r *FluxRecord) ValueByKey(key string) interface{}
ValueByKey returns value for given column key for the record
func (*FluxRecord) Values ¶
func (r *FluxRecord) Values() map[string]interface{}
Values returns map of the values where key is the column name
type FluxTableMetadata ¶
type FluxTableMetadata struct {
// contains filtered or unexported fields
}
FluxTableMetadata holds flux query result table information represented by collection of columns. Each new table is introduced by annotations
func (*FluxTableMetadata) AddColumn ¶
func (f *FluxTableMetadata) AddColumn(column *FluxColumn) *FluxTableMetadata
AddColumn adds column definition to table metadata
func (*FluxTableMetadata) Column ¶
func (f *FluxTableMetadata) Column(index int) *FluxColumn
Column returns flux table column by index Returns nil if index is out of the bounds
func (*FluxTableMetadata) Columns ¶
func (f *FluxTableMetadata) Columns() []*FluxColumn
Columns returns slice of flux query result table
func (*FluxTableMetadata) Position ¶
func (f *FluxTableMetadata) Position() int
Position returns position of the table in the flux query result
func (*FluxTableMetadata) String ¶
func (f *FluxTableMetadata) String() string
String returns FluxTableMetadata string dump
type InfluxDBClient ¶
type InfluxDBClient interface { // WriteApi returns the asynchronous, non-blocking, Write client. WriteApi(org, bucket string) WriteApi // WriteApi returns the synchronous, blocking, Write client. WriteApiBlocking(org, bucket string) WriteApiBlocking // QueryApi returns Query client QueryApi(org string) QueryApi // Close ensures all ongoing asynchronous write clients finish Close() // Options returns the options associated with client Options() *Options // ServerUrl returns the url of the server url client talks to ServerUrl() string // Setup sends request to initialise new InfluxDB server with user, org and bucket, and data retention period // Retention period of zero will result to infinite retention // and returns details about newly created entities along with the authorization object Setup(ctx context.Context, username, password, org, bucket string, retentionPeriodHours int) (*domain.OnboardingResponse, error) // Ready checks InfluxDB server is running Ready(ctx context.Context) (bool, error) // contains filtered or unexported methods }
InfluxDBClient provides API to communicate with InfluxDBServer There two APIs for writing, WriteApi and WriteApiBlocking. WriteApi provides asynchronous, non-blocking, methods for writing time series data. WriteApiBlocking provides blocking methods for writing time series data
func NewClient ¶
func NewClient(serverUrl string, authToken string) InfluxDBClient
NewClient creates InfluxDBClient for connecting to given serverUrl with provided authentication token, with default options Authentication token can be empty in case of connecting to newly installed InfluxDB server, which has not been set up yet. In such case Setup will set authentication token
func NewClientWithOptions ¶
func NewClientWithOptions(serverUrl string, authToken string, options *Options) InfluxDBClient
NewClientWithOptions creates InfluxDBClient for connecting to given serverUrl with provided authentication token and configured with custom Options Authentication token can be empty in case of connecting to newly installed InfluxDB server, which has not been set up yet. In such case Setup will set authentication token
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options holds configuration properties for communicating with InfluxDB server
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns Options object with default values
func (*Options) FlushInterval ¶
FlushInterval returns flush interval in ms
func (*Options) MaxRetries ¶
MaxRetries returns maximum count of retry attempts of failed writes
func (*Options) RetryBufferLimit ¶
RetryBufferLimit returns retry buffer limit
func (*Options) RetryInterval ¶
RetryInterval returns retry interval in ms
func (*Options) SetBatchSize ¶
SetBatchSize sets number of points sent in single request
func (*Options) SetFlushInterval ¶
SetFlushInterval sets flush interval in ms in which is buffer flushed if it has not been already written
func (*Options) SetLogLevel ¶
SetLogLevel set level to filter log messages. Each level mean to log all categories bellow. 0 error, 1 - warning, 2 - info, 3 - debug Debug level will print also content of writen batches
func (*Options) SetMaxRetries ¶
SetMaxRetries sets maximum count of retry attempts of failed writes
func (*Options) SetPrecision ¶
SetPrecision sets time precision to use in writes for timestamp. In unit of duration: time.Nanosecond, time.Microsecond, time.Millisecond, time.Second
func (*Options) SetRetryBufferLimit ¶
SetRetryBufferLimit sets maximum number of points to keep for retry. Should be multiple of BatchSize.
func (*Options) SetRetryInterval ¶
SetRetryInterval sets retry interval in ms, which is set if not sent by server
func (*Options) SetTlsConfig ¶
SetTlsConfig sets TLS configuration for secure connection
func (*Options) SetUseGZip ¶
SetUseGZip specifies whether to use GZip compression in write requests.
type Point ¶
type Point struct {
// contains filtered or unexported fields
}
Point is represents InfluxDB time series point, holding tags and fields
func NewPoint ¶
func NewPoint( measurement string, tags map[string]string, fields map[string]interface{}, ts time.Time, ) *Point
NewPoint creates a Point from measurement name, tags, fields and a timestamp.
func NewPointWithMeasurement ¶
NewPointWithMeasurement creates a empty Point Use AddTag and AddField to fill point with data
func (*Point) SortFields ¶
SortFields orders the fields of a point alphanumerically by key.
func (*Point) SortTags ¶
SortTags orders the tags of a point alphanumerically by key. This is just here as a helper, to make it easy to keep tags sorted if you are creating a Point manually.
type QueryApi ¶
type QueryApi interface { // QueryRaw executes flux query on the InfluxDB server and returns complete query result as a string with table annotations according to dialect QueryRaw(ctx context.Context, query string, dialect *domain.Dialect) (string, error) // Query executes flux query on the InfluxDB server and returns QueryTableResult which parses streamed response into structures representing flux table parts Query(ctx context.Context, query string) (*QueryTableResult, error) }
QueryApi provides methods for performing synchronously flux query against InfluxDB server
type QueryTableResult ¶
QueryTableResult parses streamed flux query response into structures representing flux table parts Walking though the result is done by repeatedly calling Next() until returns false. Actual flux table info (columns with names, data types, etc) is returned by TableMetadata() method. Data are acquired by Record() method. Preliminary end can be caused by an error, so when Next() return false, check Err() for an error
func (*QueryTableResult) Err ¶
func (q *QueryTableResult) Err() error
Err returns an error raised during flux query response parsing
func (*QueryTableResult) Next ¶
func (q *QueryTableResult) Next() bool
Next advances to next row in query result. During the first time it is called, Next creates also table metadata Actual parsed row is available through Record() function Returns false in case of end or an error, otherwise true
func (*QueryTableResult) Record ¶
func (q *QueryTableResult) Record() *FluxRecord
Record returns last parsed flux table data row Use Record methods to access value and row properties
func (*QueryTableResult) TableChanged ¶
func (q *QueryTableResult) TableChanged() bool
TableChanged returns true if last call of Next() found also new result table Table information is available via TableMetadata method
func (*QueryTableResult) TableMetadata ¶
func (q *QueryTableResult) TableMetadata() *FluxTableMetadata
TableMetadata returns actual flux table metadata
func (*QueryTableResult) TablePosition ¶
func (q *QueryTableResult) TablePosition() int
TablePosition returns actual flux table position in the result. Each new table is introduced by annotations
type ResponseCallback ¶
type WriteApi ¶
type WriteApi interface { // WriteRecord writes asynchronously line protocol record into bucket. // WriteRecord adds record into the buffer which is sent on the background when it reaches the batch size. // Blocking alternative is available in the WriteApiBlocking interface WriteRecord(line string) // WritePoint writes asynchronously Point into bucket. // WritePoint adds Point into the buffer which is sent on the background when it reaches the batch size. // Blocking alternative is available in the WriteApiBlocking interface WritePoint(point *Point) // Flush forces all pending writes from the buffer to be sent Flush() // Flushes all pending writes and stop async processes. After this the Write client cannot be used Close() // Errors return channel for reading errors which occurs during async writes Errors() <-chan error }
WriteApiBlocking is Write client interface with non-blocking methods for writing time series data asynchronously in batches into an InfluxDB server.
type WriteApiBlocking ¶
type WriteApiBlocking interface { // WriteRecord writes line protocol record(s) into bucket. // WriteRecord writes without implicit batching. Batch is created from given number of records // Non-blocking alternative is available in the WriteApi interface WriteRecord(ctx context.Context, line ...string) error // WritePoint data point into bucket. // WritePoint writes without implicit batching. Batch is created from given number of points // Non-blocking alternative is available in the WriteApi interface WritePoint(ctx context.Context, point ...*Point) error }
WriteApiBlocking offers blocking methods for writing time series data synchronously into an InfluxDB server.