influxdb

package
v1.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 24 Imported by: 90

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticationMethod

type AuthenticationMethod int

AuthenticationMethod defines the type of authentication used.

const (
	NoAuthentication AuthenticationMethod = iota
	UserAuthentication
	BearerAuthentication
	TokenAuthentication // like bearer authentication but with the word Token
)

Supported authentication methods.

type BatchPoints

type BatchPoints interface {
	// AddPoint adds the given point to the Batch of points
	AddPoint(p Point)
	// AddPoints adds the given points to the Batch of points
	AddPoints(ps []Point)
	// Points lists the points in the Batch
	Points() []Point

	// Precision returns the currently set precision of this Batch
	Precision() string
	// SetPrecision sets the precision of this batch.
	SetPrecision(s string) error

	// Database returns the currently set database of this Batch
	Database() string
	// SetDatabase sets the database of this Batch
	SetDatabase(s string)

	// WriteConsistency returns the currently set write consistency of this Batch
	WriteConsistency() string
	// SetWriteConsistency sets the write consistency of this Batch
	SetWriteConsistency(s string)

	// RetentionPolicy returns the currently set retention policy of this Batch
	RetentionPolicy() string
	// SetRetentionPolicy sets the retention policy of this Batch
	SetRetentionPolicy(s string)
}

BatchPoints is an interface into a batched grouping of points to write into InfluxDB together. BatchPoints is NOT thread-safe, you must create a separate batch for each goroutine.

func NewBatchPoints

func NewBatchPoints(conf BatchPointsConfig) (BatchPoints, error)

NewBatchPoints returns a BatchPoints interface based on the given config.

type BatchPointsConfig

type BatchPointsConfig struct {
	// Precision is the write precision of the points, defaults to "ns"
	Precision string

	// Database is the database to write points to
	Database string

	// RetentionPolicy is the retention policy of the points
	RetentionPolicy string

	// Write consistency is the number of servers required to confirm write
	WriteConsistency string
}

BatchPointsConfig is the config data needed to create an instance of the BatchPoints struct

type Client

type Client interface {
	// Ping checks that status of cluster
	// The provided context can be used to cancel the request.
	Ping(ctx context.Context) (time.Duration, string, error)

	// Write takes a BatchPoints object and writes all Points to InfluxDB.
	Write(bp BatchPoints) error

	// WriteV2 takes a FluxWrite object and writes all Points to InfluxDB using the V2 interface.
	WriteV2(w FluxWrite) error

	// Query makes an InfluxDB Query on the database.
	// The response is checked for an error and the is returned
	// if it exists
	Query(q Query) (*Response, error)

	// QueryFlux is for querying Influxdb with the Flux language
	// The response is checked for an error and the is returned
	// if it exists
	QueryFlux(q FluxQuery) (flux.ResultIterator, error)

	// QueryFlux is for querying Influxdb with the Flux language
	// The response is checked for an error and the is returned
	// if it exists.  Unlike QueryFlux, this returns a *Response
	// object.
	QueryFluxResponse(q FluxQuery) (*Response, error)

	// CreateBucketV2 uses the 2.x /api/v2/bucket api to create a bucket.
	// Note that 1.x does not support this API
	CreateBucketV2(bucket string, org string, orgID string) error
}

Client is an interface for writing to and querying from an InfluxDB instance.

type ClientCreator

type ClientCreator struct{}

Simple type to create github.com/influxdata/kapacitor/influxdb clients.

func (ClientCreator) Create

func (ClientCreator) Create(config Config) (ClientUpdater, error)

type ClientUpdater added in v1.1.0

type ClientUpdater interface {
	Client
	Update(new Config) error
	Close() error
}

type Config added in v1.1.0

type Config struct {
	// The URL of the InfluxDB server.
	URLs []string

	// Optional credentials for authenticating with the server.
	Credentials Credentials

	// UserAgent is the http User Agent, defaults to "KapacitorInfluxDBClient"
	UserAgent string

	// Timeout for requests, defaults to no timeout.
	Timeout time.Duration

	// Transport is the HTTP transport to use for requests
	// If nil, a default transport will be used.
	Transport *http.Transport

	// Which compression should we use for writing to influxdb, defaults to "gzip".
	Compression string
}

HTTPConfig is the config data needed to create an HTTP Client

type Credentials

type Credentials struct {
	Method AuthenticationMethod

	// UserAuthentication fields
	Username string
	Password string

	// TokenAuthentication fields
	Token string

	// BearerAuthentication fields
	HttpSharedSecret bool
}

Set of credentials depending on the authentication method

type Diagnostic added in v1.6.0

type Diagnostic interface {
	Error(msg string, err error, ctx ...keyvalue.T)
}

type FluxCSVEventHandler added in v1.6.0

type FluxCSVEventHandler interface {
	// Error event represents a ',error' table in the flux result, which is special
	Error(err string)

	// GroupStart gives the metadata for a new group of tables
	GroupStart(names []string, types []string, groups []bool)

	// TableStart marks the start of a table
	TableStart(meta FluxTableMetaData, firstRow []string)

	// DataRow is called for each regular data row
	DataRow(meta FluxTableMetaData, row []string)

	// TableEnd marks the end of a table
	TableEnd()
}

type FluxCSVEventParser added in v1.6.0

type FluxCSVEventParser struct {
	// contains filtered or unexported fields
}

FluxCSVEventParser is an event-based parser for flux csv it assumes a csv dialect with Annotations: []string{"datatype", "group"}, Delimiter: ",", Header: true,

func NewFluxCSVEventParser added in v1.6.0

func NewFluxCSVEventParser(r io.Reader, handler FluxCSVEventHandler) *FluxCSVEventParser

func (*FluxCSVEventParser) Parse added in v1.6.0

func (q *FluxCSVEventParser) Parse() error

type FluxQuery added in v1.6.0

type FluxQuery struct {
	Org   string
	OrgID string
	Query string
	Now   time.Time
}

type FluxTableMetaData added in v1.6.0

type FluxTableMetaData struct {
	TableNumber string
	DataTypes   []string
	ColumnNames []string
	Groups      []bool
}

type FluxWrite added in v1.6.0

type FluxWrite struct {
	Bucket string
	Org    string
	OrgID  string
	Points models.Points
}

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

HTTPClient is safe for concurrent use.

func NewHTTPClient

func NewHTTPClient(conf Config) (*HTTPClient, error)

NewHTTPClient returns a new Client from the provided config. Client is safe for concurrent use by multiple goroutines.

func (*HTTPClient) Close

func (c *HTTPClient) Close() error

func (*HTTPClient) CreateBucketV2 added in v1.6.2

func (c *HTTPClient) CreateBucketV2(bucket, org, orgID string) error

func (*HTTPClient) Ping

func (c *HTTPClient) Ping(ctx context.Context) (time.Duration, string, error)

Ping will check to see if the server is up with an optional timeout on waiting for leader. Ping returns how long the request took, the version of the server it connected to, and an error if one occurred.

func (*HTTPClient) Query

func (c *HTTPClient) Query(q Query) (*Response, error)

Query sends a command to the server and returns the Response

func (*HTTPClient) QueryFlux added in v1.6.0

func (c *HTTPClient) QueryFlux(q FluxQuery) (flux.ResultIterator, error)

func (*HTTPClient) QueryFluxResponse added in v1.6.0

func (c *HTTPClient) QueryFluxResponse(q FluxQuery) (*Response, error)

func (*HTTPClient) Update added in v1.1.0

func (c *HTTPClient) Update(new Config) error

UpdateURLs updates the running list of URLs.

func (*HTTPClient) Write

func (c *HTTPClient) Write(bp BatchPoints) error

func (*HTTPClient) WriteV2 added in v1.6.0

func (c *HTTPClient) WriteV2(w FluxWrite) error

type Message

type Message struct {
	Level string
	Text  string
}

Message represents a user message.

type Point

type Point struct {
	Name   string
	Tags   map[string]string
	Fields map[string]interface{}
	Time   time.Time
}

func (Point) Bytes

func (p Point) Bytes(precision string) []byte

Returns byte array of a line protocol representation of the point

func (Point) BytesWithLineFeed added in v1.5.9

func (p Point) BytesWithLineFeed(precision string) []byte

type Query

type Query struct {
	Command   string
	Database  string
	Precision string
}

Query defines a query to send to the server

type Response

type Response struct {
	Results []Result
	Err     string `json:"error,omitempty"`
}

Response represents a list of statement results.

func NewFluxQueryResponse added in v1.6.0

func NewFluxQueryResponse(r io.Reader) (*Response, error)

func (*Response) Error

func (r *Response) Error() error

Error returns the first error from any statement. Returns nil if no errors occurred on any statements.

type Result

type Result struct {
	Series   []imodels.Row
	Messages []*Message
	Err      string `json:"error,omitempty"`
}

Result represents a resultset returned from a single statement.

type TokenClientCreator added in v1.6.0

type TokenClientCreator struct {
	// contains filtered or unexported fields
}

func NewTokenClientCreator added in v1.6.0

func NewTokenClientCreator(httpSharedSecret []byte, tokenDuration time.Duration, d Diagnostic) *TokenClientCreator

func (*TokenClientCreator) Create added in v1.6.0

func (cc *TokenClientCreator) Create(config Config) (ClientUpdater, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL