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) 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) 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) SetTlsConfig(tlsConfig *tls.Config) *Options
- func (o *Options) SetUseGZip(useGZip bool) *Options
- func (o *Options) TLSConfig() *tls.Config
- func (o *Options) TlsConfig() *tls.Config
- func (o *Options) UseGZip() bool
- func (o *Options) WriteOptions() *write.Options
Examples ¶
Constants ¶
const (
Version = "1.4.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 // ServerURL returns the url of the server url client talks to // Deprecated: Use ServerURL instead. ServerUrl() string // WriteAPI returns the asynchronous, non-blocking, Write client WriteAPI(org, bucket string) api.WriteAPI // WriteApi returns the asynchronous, non-blocking, Write client // Deprecated: Use WriteAPI instead WriteApi(org, bucket string) api.WriteApi // WriteAPIBlocking returns the synchronous, blocking, Write client WriteAPIBlocking(org, bucket string) api.WriteAPIBlocking // WriteApi returns the synchronous, blocking, Write client. // Deprecated: Use WriteAPIBlocking instead. WriteApiBlocking(org, bucket string) api.WriteApiBlocking // QueryAPI returns Query client QueryAPI(org string) api.QueryAPI // QueryApi returns Query client // Deprecated: Use QueryAPI instead. QueryApi(org string) api.QueryApi // AuthorizationsAPI returns Authorizations API client. AuthorizationsAPI() api.AuthorizationsAPI // AuthorizationsApi returns Authorizations API client. // Deprecated: Use AuthorizationsAPI instead. AuthorizationsApi() api.AuthorizationsApi // OrganizationsAPI returns Organizations API client OrganizationsAPI() api.OrganizationsAPI // OrganizationsApi returns Organizations API client. // Deprecated: Use OrganizationsAPI instead. OrganizationsApi() api.OrganizationsApi // UsersAPI returns Users API client. UsersAPI() api.UsersAPI // UsersApi returns Users API client. // Deprecated: Use UsersAPI instead. UsersApi() api.UsersApi // DeleteAPI returns Delete API client DeleteAPI() api.DeleteAPI // DeleteApi returns Delete API client. // Deprecated: Use DeleteAPI instead. DeleteApi() api.DeleteApi // BucketsAPI returns Buckets API client BucketsAPI() api.BucketsAPI // BucketsApi returns Buckets API client. // Deprecated: Use BucketsAPI instead. BucketsApi() api.BucketsApi // LabelsAPI returns Labels API client LabelsAPI() api.LabelsAPI // LabelsApi returns Labels API client; // Deprecated: Use LabelsAPI instead. 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.4.0
HTTPOptions returns HTTP related options
func (*Options) HTTPRequestTimeout ¶ added in v1.4.0
HTTPRequestTimeout returns HTTP request timeout
func (*Options) HttpOptions ¶ added in v1.2.0
HttpOptions returns http related options Deprecated: Use HTTPOptions instead
func (*Options) HttpRequestTimeout ¶ added in v1.1.0
HttpRequestTimeout returns HTTP request timeout. Deprecated: Use HTTPRequestTimeout instead.
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.4.0
SetHTTPRequestTimeout sets HTTP request timeout in sec
func (*Options) SetHttpRequestTimeout ¶ added in v1.1.0
SetHttpRequestTimeout sets HTTP request timeout in sec Deprecated: Use SetHTTPRequestTimeout instead
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.4.0
SetTLSConfig sets TLS configuration for secure connection
func (*Options) SetTlsConfig ¶ added in v1.0.0
SetTlsConfig sets TLS configuration for secure connection. Deprecated: Use SetTLSConfig instead.
func (*Options) SetUseGZip ¶ added in v1.0.0
SetUseGZip specifies whether to use GZip compression in write requests.
func (*Options) TlsConfig ¶ added in v1.0.0
TlsConfig returns TLS config. Deprecated: Use TLSConfig instead.
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. |
http
Package http holds HTTP options
|
Package http holds HTTP options |
query
Package query defined types for representing flux query result
|
Package query defined types for representing flux query result |
write
Package write provides the Point struct
|
Package write provides the Point struct |
Package domain provides primitives to interact the openapi HTTP API.
|
Package domain provides primitives to interact the openapi HTTP API. |
internal
|
|
examples
Package examples contains fake client with the same interface as real client to overcome import-cycle problem to allow real E2E examples for apis in this package
|
Package examples contains fake client with the same interface as real client to overcome import-cycle problem to allow real E2E examples for apis in this package |
gzip
Package gzip provides GZip related functionality
|
Package gzip provides GZip related functionality |
http
Package http provides http related servicing stuff
|
Package http provides http related servicing stuff |
log
Package log provides internal logging infrastructure
|
Package log provides internal logging infrastructure |
write
Package write provides service and its stuff
|
Package write provides service and its stuff |