Documentation ¶
Overview ¶
Package influxdb2 provides API for using InfluxDB client in Go. It's intended to use with InfluxDB 2 server. WriteApi, QueryApi and Health work also with InfluxDB 1.8
Index ¶
- Constants
- func DefaultDialect() *domain.Dialect
- func NewPoint(measurement string, tags map[string]string, fields map[string]interface{}, ...) *write.Point
- func NewPointWithMeasurement(measurement string) *write.Point
- type Client
- type Options
- func (o *Options) AddDefaultTag(key, value string) *Options
- func (o *Options) BatchSize() uint
- func (o *Options) FlushInterval() uint
- func (o *Options) HttpOptions() *http.Options
- func (o *Options) HttpRequestTimeout() 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) SetHttpRequestTimeout(httpRequestTimeout 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
- func (o *Options) WriteOptions() *write.Options
Examples ¶
Constants ¶
const (
Version = "1.3.0"
)
Variables ¶
This section is empty.
Functions ¶
func DefaultDialect ¶ added in v1.0.0
DefaultDialect return flux query Dialect with full annotations (datatype, group, default), header and comma char as a delimiter
func NewPoint ¶ added in v1.0.0
func NewPoint( measurement string, tags map[string]string, fields map[string]interface{}, ts time.Time, ) *write.Point
NewPoint creates a Point from measurement name, tags, fields and a timestamp.
func NewPointWithMeasurement ¶ added in v1.0.0
NewPointWithMeasurement creates a empty Point Use AddTag and AddField to fill point with data
Types ¶
type Client ¶
type Client interface { // Setup sends request to initialise new InfluxDB server with user, org and bucket, and data retention period // and returns details about newly created entities along with the authorization object. // Retention period of zero will result to infinite retention. Setup(ctx context.Context, username, password, org, bucket string, retentionPeriodHours int) (*domain.OnboardingResponse, error) // Ready checks InfluxDB server is running. It doesn't validate authentication params. Ready(ctx context.Context) (bool, error) // Health returns an InfluxDB server health check result. Read the HealthCheck.Status field to get server status. // Health doesn't validate authentication params. Health(ctx context.Context) (*domain.HealthCheck, error) // 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 // WriteApi returns the asynchronous, non-blocking, Write client WriteApi(org, bucket string) api.WriteApi // WriteApi returns the synchronous, blocking, Write client WriteApiBlocking(org, bucket string) api.WriteApiBlocking // QueryApi returns Query client QueryApi(org string) api.QueryApi // AuthorizationsApi returns Authorizations API client AuthorizationsApi() api.AuthorizationsApi // OrganizationsApi returns Organizations API client OrganizationsApi() api.OrganizationsApi // UsersApi returns Users API client UsersApi() api.UsersApi // DeleteApi returns Delete API client DeleteApi() api.DeleteApi // BucketsApi returns Buckets API client BucketsApi() api.BucketsApi // LabelsApi returns Labels API client LabelsApi() api.LabelsApi }
Client 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.
Example (NewClient) ¶
// Create client client := influxdb2.NewClient("http://localhost:9999", "my-token") // always close client at the end defer client.Close()
Output:
Example (NewClientWithOptions) ¶
// Create client and set batch size to 20 client := influxdb2.NewClientWithOptions("http://localhost:9999", "my-token", influxdb2.DefaultOptions().SetBatchSize(20)) // always close client at the end defer client.Close()
Output:
func NewClient ¶ added in v1.0.0
NewClient creates Client for connecting to given serverUrl with provided authentication token, with the 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 ¶ added in v1.0.0
NewClientWithOptions creates Client 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 ¶ added in v1.0.0
type Options struct {
// contains filtered or unexported fields
}
Options holds configuration properties for communicating with InfluxDB server
func DefaultOptions ¶ added in v1.0.0
func DefaultOptions() *Options
DefaultOptions returns Options object with default values
func (*Options) AddDefaultTag ¶ added in v1.3.0
AddDefaultTag adds a default tag. DefaultTags are added to each written point. If a tag with the same key already exist it is overwritten. If a point already defines such a tag, it is left unchanged
func (*Options) FlushInterval ¶ added in v1.0.0
FlushInterval returns flush interval in ms
func (*Options) HttpOptions ¶ added in v1.2.0
HttpOptions returns http related options
func (*Options) HttpRequestTimeout ¶ added in v1.1.0
HttpRequestTimeout returns HTTP request timeout
func (*Options) MaxRetries ¶ added in v1.0.0
MaxRetries returns maximum count of retry attempts of failed writes
func (*Options) RetryBufferLimit ¶ added in v1.0.0
RetryBufferLimit returns retry buffer limit
func (*Options) RetryInterval ¶ added in v1.0.0
RetryInterval returns the retry interval in ms
func (*Options) SetBatchSize ¶ added in v1.0.0
SetBatchSize sets number of points sent in single request
func (*Options) SetFlushInterval ¶ added in v1.0.0
SetFlushInterval sets flush interval in ms in which is buffer flushed if it has not been already written
func (*Options) SetHttpRequestTimeout ¶ added in v1.1.0
SetHttpRequestTimeout sets HTTP request timeout in sec
func (*Options) SetLogLevel ¶ added in v1.0.0
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 ¶ added in v1.0.0
SetMaxRetries sets maximum count of retry attempts of failed writes
func (*Options) SetPrecision ¶ added in v1.0.0
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 ¶ added in v1.0.0
SetRetryBufferLimit sets maximum number of points to keep for retry. Should be multiple of BatchSize.
func (*Options) SetRetryInterval ¶ added in v1.0.0
SetRetryInterval sets retry interval in ms, which is set if not sent by server
func (*Options) SetTlsConfig ¶ added in v1.0.0
SetTlsConfig sets TLS configuration for secure connection
func (*Options) SetUseGZip ¶ added in v1.0.0
SetUseGZip specifies whether to use GZip compression in write requests.
func (*Options) WriteOptions ¶ added in v1.2.0
WriteOptions returns write related options
Directories ¶
Path | Synopsis |
---|---|
Package api provides clients for InfluxDB server APIs.
|
Package api provides clients for InfluxDB server APIs. |
Package domain provides primitives to interact the openapi HTTP API.
|
Package domain provides primitives to interact the openapi HTTP API. |
internal
|
|