influxdb

package module
v0.1.6-0...-dc950e9 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: MIT Imports: 26 Imported by: 0

README

influxdb-client-go

A home for InfluxDB’s 2.x's golang client. This client is not compatible with InfluxDB 1.x--if you are looking for the 1.x golang client you can find it here.

Example:

influx, err := influxdb.New(myHTTPInfluxAddress, myToken, influxdb.WithHTTPClient(myHTTPClient))
if err != nil {
	panic(err) // error handling here; normally we wouldn't use fmt but it works for the example
}

// we use client.NewRowMetric for the example because it's easy, but if you need extra performance
// it is fine to manually build the []client.Metric{}.
myMetrics := []influxdb.Metric{
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 8, time.UTC)),
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 9, time.UTC)),
}

// The actual write..., this method can be called concurrently.
if _, err := influx.Write(context.Background(), "my-awesome-bucket", "my-very-awesome-org", myMetrics...); err != nil {
	log.Fatal(err) // as above use your own error handling here.
}
influx.Close() // closes the client.  After this the client is useless.

Releases

We will be using git-flow style releases, the current stable release will be listed in the master readme.

Requirements

influxdb-client-go requires go version 1.12 or newer to build.

Documentation

Overview

Package influxdb implements InfluxDB’s 2.x's golang client. This client is not compatible with InfluxDB 1.x -- if you are looking for the 1.x golang client you can find it at https://github.com/influxdata/influxdb1-client.

Example:

influx, err := influxdb.New(
	myHTTPInfluxAddress,
	myToken,
	influxdb.WithHTTPClient(myHTTPClient))

if err != nil {
	return err
}
defer influx.Close() // closes the client.  After this the client is useless.

// we use client.NewRowMetric for the example because it's easy, but if you
// need extra performance it is fine to manually build the []client.Metric{}.
metrics := []influxdb.Metric{
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 8, time.UTC)),
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 9, time.UTC)),
}

// the actual write. this method can be called concurrently.
if _, err := influx.write(context.background(), "my-awesome-bucket", "my-very-awesome-org", metrics...); err != nil {
	return err
}

Index

Examples

Constants

View Source
const (
	EInternal            = "internal error"
	ENotFound            = "not found"
	EConflict            = "conflict"             // action cannot be performed
	EInvalid             = "invalid"              // validation failed
	EUnprocessableEntity = "unprocessable entity" // data type is correct, but out of range
	EEmptyValue          = "empty value"
	EUnavailable         = "unavailable"
	EForbidden           = "forbidden"
	ETooManyRequests     = "too many requests"
	EUnauthorized        = "unauthorized"
	EMethodNotAllowed    = "method not allowed"
	ETooLarge            = "request too large"
)

Error code constants copied from influxdb

Variables

View Source
var ErrUnimplemented = errors.New("unimplemented")

ErrUnimplemented is an error for when pieces of the client's functionality is unimplemented.

Functions

func HTTPClientWithTLSConfig

func HTTPClientWithTLSConfig(conf *tls.Config) *http.Client

HTTPClientWithTLSConfig returns an *http.Client with sane timeouts and the provided TLSClientConfig.

func NewWriteGzipRequest

func NewWriteGzipRequest(url *url.URL, userAgent, token, bucket, org string, compressionLevel int, body io.Reader) (*http.Request, error)

func NewWriteRequest

func NewWriteRequest(url *url.URL, userAgent, token, bucket, org string, body io.Reader) (*http.Request, error)

Types

type AuthorizationCreated

type AuthorizationCreated struct {
	Status      string `json:"status"`
	Description string `json:"description"`
	CreatedAt   string `json:"createdAt"`
	UpdatedAt   string `json:"updatedAt"`
	OrgID       string `json:"orgID"`
	Permissions []struct {
		Action   string `json:"action"`
		Resource struct {
			Type  string `json:"type"`
			Id    string `json:"id"`
			Name  string `json:"name"`
			OrgId string `json:"orgID"`
			Org   string `json:"org"`
		} `json:"resource"`
	} `json:"permissions"`
	Id     string `json:"id"`
	Token  string `json:"token"`
	UserID string `json:"userID"`
	User   string `json:"user"`
	Org    string `json:"user"`
	Links  struct {
		Self string `json:"self"`
		User string `json:"user"`
	} `json:"links"`
}

type AuthorizationDetails

type AuthorizationDetails struct {
	Status      string `json:"status"`
	Description string `json:"description"`
	CreatedAt   string `json:"createdAt"`
	UpdatedAt   string `json:"updatedAt"`
	OrgID       string `json:"orgID"`
	Permissions []struct {
		Action   string `json:"action"`
		Resource struct {
			Type  string `json:"type"`
			Id    string `json:"id"`
			Name  string `json:"name"`
			OrgID string `json:"orgID"`
			Org   string `json:"org"`
		} `json:"resource"`
	} `json:"permissions"`
	Id     string `json:"id"`
	Token  string `json:"token"`
	UserID string `json:"userID"`
	User   string `json:"user"`
	Org    string `json:"org"`
	Links  struct {
		Self string `json:"self"`
		User string `json:"user"`
	} `json:"links"`
}

type AuthorizationsList

type AuthorizationsList struct {
	Links struct {
		Next string `json:"next"`
		Self string `json:"self"`
		Prev string `json:"prev"`
	} `json:"links"`
	Authorizations []struct {
		Status      string `json:"status"`
		Description string `json:"description"`
		CreatedAt   string `json:"createdAt"`
		UpdatedAt   string `json:"updatedAt"`
		OrgID       string `json:"orgID"`
		Permissions []struct {
			Action   string `json:"action"`
			Resource struct {
				Type  string `json:"type"`
				Id    string `json:"id"`
				Name  string `json:"name"`
				OrgID string `json:"orgID"`
				Org   string `json:"org"`
			} `json:"resource"`
		} `json:"permissions"`
		Id     string `json:"id"`
		Token  string `json:"token"`
		UserID string `json:"userID"`
		User   string `json:"user"`
		Org    string `json:"org"`
		Links  struct {
			Self string `json:"self"`
			User string `json:"user"`
		} `json:"links"`
	} `json:"authorizations"`
}

type BucketCreate

type BucketCreate struct {
	Links struct {
		Labels  string `json:"labels"`
		Logs    string `json:"logs"`
		Members string `json:"members"`
		Org     string `json:"org"`
		Owners  string `json:"owners"`
		Self    string `json:"self"`
		Write   string `json:"write"`
	} `json:"links"`
	Id             string           `json:"id"`
	Type           string           `json:"user"`
	Name           string           `json:"name"`
	Description    string           `json:"description"`
	OrgID          string           `json:"orgID"`
	Rp             string           `json:"rp"`
	CreatedAt      string           `json:"createdAt"`
	UpdatedAt      string           `json:"updatedAt"`
	RetentionRules []RetentionRules `json:"retentionRules"`
	Labels         []struct {
		Id         string `json:"id"`
		OrgID      string `json:"orgID"`
		Name       string `json:"name"`
		Properties string `json:"properties"`
	} `json:"labels"`
}

type BucketLogs

type BucketLogs struct {
	Logs []struct {
		Description string `json:"description"`
		Time        string `json:"time"`
		UserID      string `json:"userID"`
		Links       struct {
			User string `json:"user"`
		} `json:"links"`
	} `json:"logs"`
	Links struct {
		Next string `json:"next"`
		Self string `json:"self"`
		Prev string `json:"prev"`
	} `json:"links"`
}

type BucketMemberAdded

type BucketMemberAdded struct {
	Id      string `json:"id"`
	OauthID string `json:"oauthID"`
	Name    string `json:"name"`
	Status  string `json:"status"`
	Links   struct {
		Self string `json:"self"`
		Logs string `json:"logs"`
	} `json:"links"`
	Role string `json:"role"`
}

type BucketOwner

type BucketOwner struct {
	Links struct {
		Self string `json:"self"`
	} `json:"links"`
	Users []struct {
		Id      string `json:"id"`
		OauthID string `json:"oauthID"`
		Name    string `json:"name"`
		Status  string `json:"status"`
		Links   struct {
			Self string `json:"self"`
			Logs string `json:"logs"`
		} `json:"links"`
		Role string `json:"role"`
	} `json:"users"`
}

type BucketOwnerAdded

type BucketOwnerAdded struct {
	Id      string `json:"id"`
	OauthID string `json:"oauthID"`
	Name    string `json:"name"`
	Status  string `json:"status"`
	Links   struct {
		Self string `json:"self"`
		Logs string `json:"logs"`
	} `json:"links"`
	Role string `json:"role"`
}

type BucketSource

type BucketSource struct {
	Links struct {
		Next string `json:"next"`
		Self string `json:"self"`
		Prev string `json:"prev"`
	} `json:"links"`
	Buckets []struct {
		Links struct {
			Labels  string `json:"labels"`
			Logs    string `json:"logs"`
			Members string `json:"members"`
			Org     string `json:"org"`
			Owners  string `json:"owners"`
			Self    string `json:"self"`
			Write   string `json:"write"`
		} `json:"links"`
		Id             string           `json:"id"`
		Type           string           `json:"type"`
		Name           string           `json:"name"`
		Description    string           `json:"description"`
		OrgId          string           `json:"orgId"`
		Rp             string           `json:"rp"`
		CreatedAt      string           `json:"createdAt"`
		UpdatedAt      string           `json:"updatedAt"`
		RetentionRules []RetentionRules `json:"retentionRules"`
	} `json:"buckets"`
	Labels []struct {
		Id          string `json:"id"`
		OrgId       string `json:"orgId"`
		Name        string `json:"name"`
		Properties  string `json:"properties"`
		Color       string `json:"color"`
		Description string `json:"description"`
	} `json:"labels"`
}

type BucketUsers

type BucketUsers struct {
	Links struct {
		Self string `json:"self"`
	} `json:"links"`
	Users []struct {
		Id      string `json:"id"`
		OauthID string `json:"oauthID"`
		Name    string `json:"name"`
		Status  string `json:"status"`
		Links   []struct {
			Self string `json:"self"`
			Logs string `json:"logs"`
		} `json:"links"`
		Role string `json:"role"`
	} `json:"users"`
}

type Client

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

Client is a client for writing to influx.

func New

func New(connection string, token string, options ...Option) (*Client, error)

New creates a new Client. The client is concurrency safe, so feel free to use it and abuse it to your heart's content.

func (*Client) AddLabelToBucket

func (c *Client) AddLabelToBucket(bucketID string, labelID string) (*LabelsOfBucket, error)

func (*Client) AddMemberToBucket

func (c *Client) AddMemberToBucket(bucketID string, memberID string, memberName string) (*BucketMemberAdded, error)

func (*Client) AddOwnerToBucket

func (c *Client) AddOwnerToBucket(bucketID string, ownerID string, ownerName string) (*BucketOwnerAdded, error)

func (*Client) Close

func (c *Client) Close() error

Close closes any idle connections on the Client.

func (*Client) CreateAuthorization

func (c *Client) CreateAuthorization(description string, orgID string, permissions []Permissions, status string) (*AuthorizationCreated, error)

func (*Client) CreateBucket

func (c *Client) CreateBucket(description string, name string, orgID string, retentionRules []RetentionRules, rp string) (*BucketCreate, error)

func (*Client) CreateUser

func (c *Client) CreateUser(name string, oauthID string, status string) (*User, error)

func (*Client) DeleteABucket

func (c *Client) DeleteABucket(bucketID string) error

func (*Client) DeleteALabelFromBucket

func (c *Client) DeleteALabelFromBucket(bucketID string, labelID string) error

func (*Client) DeleteAnAuthorization

func (c *Client) DeleteAnAuthorization(authID string) error

func (*Client) DeleteUser

func (c *Client) DeleteUser(userID string) error

func (*Client) GetAllAuthorizations

func (c *Client) GetAllAuthorizations(org string, orgID string, user string, userID string) (*AuthorizationsList, error)

func (*Client) GetAllUsers

func (c *Client) GetAllUsers() (*UserList, error)

func (*Client) GetAuthorizationById

func (c *Client) GetAuthorizationById(authID string) (*AuthorizationDetails, error)

func (*Client) GetBucketByID

func (c *Client) GetBucketByID(bucketID string) (*SimpleBucket, error)

func (*Client) GetBuckets

func (c *Client) GetBuckets(limit int, name string, offset int, org string, orgID string) (*BucketSource, error)

func (*Client) GetBucketsInSource

func (c *Client) GetBucketsInSource(id string) (*BucketSource, error)

func (*Client) GetHealth

func (c *Client) GetHealth(ctx context.Context) (*Health, error)

func (*Client) GetListUsersOfBucket

func (c *Client) GetListUsersOfBucket(bucketID string) (*BucketUsers, error)

func (*Client) GetLogsOfBucket

func (c *Client) GetLogsOfBucket(bucketID string, limit int, offset int) (*BucketLogs, error)

func (*Client) GetLogsOfUser

func (c *Client) GetLogsOfUser(userID string, limit int, offset int) (*UserLogs, error)

func (*Client) GetOwnersOfBucket

func (c *Client) GetOwnersOfBucket(bucketID string) (*BucketOwner, error)

func (*Client) GetSetup

func (c *Client) GetSetup() (*Setup, error)

func (*Client) GetUrl

func (c *Client) GetUrl() (string, error)

func (*Client) GetUserById

func (c *Client) GetUserById(userID string) (*User, error)

func (*Client) ListLabelsForABucket

func (c *Client) ListLabelsForABucket(bucketID string) (*LabelsOfBucket, error)

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping checks the status of cluster.

func (*Client) QueryCSV

func (c *Client) QueryCSV(ctx context.Context, flux string, org string, extern ...interface{}) (*QueryCSVResult, error)

QueryCSV returns the result of a flux query. TODO: annotations

func (*Client) Ready

func (c *Client) Ready(ctx context.Context) (*ReadyResult, error)

func (*Client) RemoveMemberOfBucket

func (c *Client) RemoveMemberOfBucket(bucketID string, userID string) error

func (*Client) RemoveOwnerFromBucket

func (c *Client) RemoveOwnerFromBucket(bucketID string, ownerID string) error

func (*Client) Setup

func (c *Client) Setup(ctx context.Context, username, password, bucket string, org string, retentionPeriodHrs int) (*SetupResult, error)

Setup sets up a new influxdbv2 server. It requires a client be set up with a username and password. If successful will add a token to the client. RetentionPeriodHrs of zero will result in infinite retention.

Example
// just us setting up the server so the example will work.  You will likely have to use the old fasioned way to get an *http.Client and address
// alternatively you can leave the *http.Client nil, and it will intelligently create one with sane defaults.
myHTTPClient, myHTTPInfluxAddress, teardown := setupMockServer()
defer teardown() // we shut down our server at the end of the test, obviously you won't be doing this.

influx, err := influxdb.New(myHTTPInfluxAddress, "", influxdb.WithUserAndPass("my-username", "my-password"), influxdb.WithHTTPClient(myHTTPClient))
if err != nil {
	panic(err) // error handling here, normally we wouldn't use fmt, but it works for the example
}
resp, err := influx.Setup(context.Background(), "my-user", "my-password", "my-bucket", "my-org", 32)
if err != nil {
	log.Fatal(err)
}

fmt.Println(resp.Auth.Token)
myMetrics := []influxdb.Metric{
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 8, time.UTC)),
}

// We can now do a write even though we didn't put a token in
if _, err := influx.Write(context.Background(), "my-awesome-bucket", "my-very-awesome-org", myMetrics...); err != nil {
	log.Fatal(err)
}
influx.Close() // close the client after this the client is useless.
Output:

d7odFhI50cR8WcLrbfD1pkVenWy51zEM6WC2Md5McGGTxRbOEi5KS0qrXrTEweiH2z5uQjkNa-0YVmpTQlwM3w==
system-metrics,hostname=hal9000 cpu=0.93,memory=1000i 1520139967000000008

func (*Client) UpdateABucket

func (c *Client) UpdateABucket(bucketID string, description string, labels []Labels, name string, orgID string, retentionRules []RetentionRules, rp string) (*SimpleBucket, error)

func (*Client) UpdateAnAuthorizationStatus

func (c *Client) UpdateAnAuthorizationStatus(authID string, description string, status string) (*AuthorizationDetails, error)

func (*Client) UpdatePasswordOfUser

func (c *Client) UpdatePasswordOfUser(userID string, password string) error

func (*Client) UpdateUser

func (c *Client) UpdateUser(userID string, name string, oauthID string, status string) (*User, error)

func (*Client) Write

func (c *Client) Write(ctx context.Context, bucket, org string, m ...Metric) (n int, err error)

Write writes metrics to a bucket, and org. The result n is the number of points written.

Example (Basic)

ExampleClient_Write_basic is an example of basic writing to influxdb over http(s). While this is fine in a VPN or VPC, we recommend using TLS/HTTPS if you are sending data over the internet, or anywhere your tokens could be intercepted.

// just us setting up the server so the example will work.  You will likely have to use the old fasioned way to get an *http.Client and address
// alternatively you can leave the *http.Client nil, and it will intelligently create one with sane defaults.
myHTTPClient, myHTTPInfluxAddress, teardown := setupMockServer()
defer teardown() // we shut down our server at the end of the test, obviously you won't be doing this.
influx, err := influxdb.New(myHTTPInfluxAddress, "mytoken", influxdb.WithHTTPClient(myHTTPClient))
if err != nil {
	panic(err) // error handling here, normally we wouldn't use fmt, but it works for the example
}

// we use client.NewRowMetric for the example because its easy, but if you need extra performance
// it is fine to manually build the []client.Metric{}.
myMetrics := []influxdb.Metric{
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 8, time.UTC)),
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 9, time.UTC)),
}

// The actual write..., this method can be called concurrently.
if _, err := influx.Write(context.Background(), "my-awesome-bucket", "my-very-awesome-org", myMetrics...); err != nil {
	log.Fatal(err) // as above use your own error handling here.
}
influx.Close() // closes the client.  After this the client is useless.
Output:

system-metrics,hostname=hal9000 cpu=0.93,memory=1000i 1520139967000000008
system-metrics,hostname=hal9000 cpu=0.93,memory=1000i 1520139967000000009
Example (TlsMutualAuthentication)
// just us setting up the server so the example will work.  You will likely have to use the old fasioned way to get an *http.Client and address
_, certFileName, keyfileName, myHTTPInfluxAddress, teardown := setupTLSMockserver()
defer teardown() // we shut down our server at the end of the test, obviously you won't be doing this.

certPem, err := ioutil.ReadFile(certFileName)
if err != nil {
	log.Fatal(err)
}
keyPem, err := ioutil.ReadFile(keyfileName)
if err != nil {
	log.Fatal(err)
}
cert, err := tls.X509KeyPair(certPem, keyPem)
if err != nil {
	log.Fatal(err)
}

certPool := x509.NewCertPool()

// read in the ca cert, in our case since we are self-signing, we are using the same cert
caCertPem, err := ioutil.ReadFile(certFileName)
if err != nil {
	log.Fatal(err)
}
certPool.AppendCertsFromPEM(caCertPem)

if err != nil {
	log.Fatal(err)
}
tlsConfig := &tls.Config{
	// Reject any TLS certificate that cannot be validated
	ClientAuth: tls.RequireAndVerifyClientCert,
	// Ensure that we only use our "CA" to validate certificates
	// Force it server side
	Certificates: []tls.Certificate{cert},
	RootCAs:      certPool,
}
tlsConfig.BuildNameToCertificate()

influx, err := influxdb.New(myHTTPInfluxAddress, "mytoken", influxdb.WithHTTPClient(influxdb.HTTPClientWithTLSConfig(tlsConfig)))
if err != nil {
	log.Fatal(err)
}

// we use client.NewRowMetric for the example because its easy, but if you need extra performance
// it is fine to manually build the []client.Metric{}
myMetrics := []influxdb.Metric{
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 8, time.UTC)),
	influxdb.NewRowMetric(
		map[string]interface{}{"memory": 1000, "cpu": 0.93},
		"system-metrics",
		map[string]string{"hostname": "hal9000"},
		time.Date(2018, 3, 4, 5, 6, 7, 9, time.UTC)),
}

// The actual write...
if _, err := influx.Write(context.Background(), "my-awesome-bucket", "my-very-awesome-org", myMetrics...); err != nil {
	log.Fatal(err)
}
influx.Close() // close the client after this the client is useless.
Output:

system-metrics,hostname=hal9000 cpu=0.93,memory=1000i 1520139967000000008
system-metrics,hostname=hal9000 cpu=0.93,memory=1000i 1520139967000000009

type Error

type Error struct {
	StatusCode int
	Code       string
	Message    string
	Err        string
	Op         string
	Line       *int32
	MaxLength  *int32
	RetryAfter *int32
}

Error is an error returned by a client operation It contains a number of contextual fields which describe the nature and cause of the error

func (*Error) Error

func (e *Error) Error() string

Error returns the string representation of the Error struct

type Field

type Field = lp.Field

Field is just a github.com/influxdata/line-protocol.Field. We alias here to keep abstractions from leaking.

type HTTPConfig

type HTTPConfig struct {
	// Addr should be of the form "http://host:port"
	// or "http://[ipv6-host%zone]:port".
	Addr string

	// Username is the influxdb username, optional.
	Username string

	// Password is the influxdb password, optional.
	Password string

	// UserAgent is the http User Agent, defaults to "InfluxDBClient" plus os and version info.
	UserAgent string

	// Timeout for influxdb writes, if set to zero, it defaults to a 20 second timeout. This is a difference from the influxdb1-client.
	Timeout time.Duration

	// InsecureSkipVerify gets passed to the http client, if true, it will
	// skip https certificate verification. Defaults to false.
	// this currently isn't supported, set on the http client.
	InsecureSkipVerify bool

	// TLSConfig allows the user to set their own TLS config for the HTTP
	// Client. If set, this option overrides InsecureSkipVerify.
	// this currently isn't supported, set on the http client.
	TLSConfig *tls.Config

	// Proxy configures the Proxy function on the HTTP client.
	// this currently isn't supported
	Proxy func(req *http.Request) (*url.URL, error)

	// If HTTPClient is nil, the New Client function will use an http client with sane defaults.
	HTTPClient *http.Client
}

HTTPConfig is an https://github.com/influxdata/influxdb1-client compatible client for setting config options. This is here to make transition to the influxdb2 client easy from the old influxdb 1 client library. It is recommended that you set the options using the With___ functions instead.

type Health

type Health struct {
	Name    string     `json:"name"`
	Message string     `json:"message"`
	Checks  []struct{} `json:"checks"`
	Status  string     `json:"status"`
}

type Labels

type Labels struct {
	Name       string `json:"name"`
	Properties struct {
		Color       string `json:"color"`
		Description string `json:"description"`
	} `json:"properties"`
}

type LabelsOfBucket

type LabelsOfBucket struct {
	Labels []struct {
		Id         string `json:"id"`
		OrgId      string `json:"orgID"`
		Name       string `json:"name"`
		Properties struct {
			Color       string `json:"color"`
			Description string `json:"description"`
		} `json:"properties"`
	} `json:"labels"`
	Links struct {
		Next string `json:"next"`
		Self string `json:"self"`
		Prev string `json:"prev"`
	} `json:"links"`
}

type Metric

type Metric = lp.Metric

Metric is just a github.com/influxdata/line-protocol.Metric. We alias here to keep abstractions from leaking.

type NewUser

type NewUser struct {
	Name    string `json:"name"`
	OauthID string `json:"oauthID"`
	Status  string `json:"status"`
}

type Option

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

Option is an option for the client config. If you pass multiple incompatible Options the later one should override.

func WithGZIP

func WithGZIP(n int) Option

WithGZIP returns an option for setting gzip compression level. The default (should this option not be used ) is level 4.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient returns an option for setting a custom HTTP Client

func WithMaxLineBytes

func WithMaxLineBytes(n int) Option

WithMaxLineBytes returns an option for setting the max length of a line of influx line-protocol in bytes.

func WithNoCompression

func WithNoCompression() Option

WithNoCompression returns an option for writing the data to influxdb without compression.

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent returns an option for setting a custom useragent string.

func WithUserAndPass

func WithUserAndPass(username, password string) Option

WithUserAndPass returns an option for setting a username and password, which generates a session for use. TODO(docmerlin): session logic.

func WithV1Config

func WithV1Config(conf *HTTPConfig) Option

WithV1Config is an option for setting config in a way that makes it easy to convert from the old influxdb1 client config.

type Password

type Password struct {
	Password string `json:"password"`
}

type Permissions

type Permissions struct {
	Action   string   `json:"action"`
	Resource Resource `json:"resource"`
}

type QueryCSVResult

type QueryCSVResult struct {
	io.ReadCloser

	Row      []string
	ColNames []string

	Err error
	// contains filtered or unexported fields
}

QueryCSVResult is the result of a flux query in CSV format

func (*QueryCSVResult) Next

func (q *QueryCSVResult) Next() bool

Next iterates to the next row in the data set. Typically this is called like so:

for q.Next(){
	... // do thing here
}

It will call Close() on the result when it encounters EOF. Note: error columns are represented as columns not as QueryCSVResult.Err. QueryCSVResult.Err is for errors that do not show up as error columns, error columns in flux are treated as ordinary columns.

func (*QueryCSVResult) Unmarshal

func (q *QueryCSVResult) Unmarshal(x interface{}) error

Unmarshal alows you to easily unmarshal rows of results into your own types.

type ReadyResult

type ReadyResult struct {
	Started string `json:"started"`
	Status  string `json:"status"`
	Up      string `json:"up"`
}

type Resource

type Resource struct {
	Id    string `json:"id"`
	Name  string `json:"name"`
	Org   string `json:"org"`
	OrgID string `json:"orgID"`
	Type  string `json:"type"`
}

type RetentionRules

type RetentionRules struct {
	EverySeconds int    `json:"everySeconds"`
	Type         string `json:"type"`
}

type RowMetric

type RowMetric struct {
	NameStr string
	Tags    []*lp.Tag
	Fields  []*lp.Field
	TS      time.Time
}

RowMetric is a Metric, that has methods to make it easy to add tags and fields

func NewRowMetric

func NewRowMetric(
	fields map[string]interface{},
	name string,
	tags map[string]string,
	ts time.Time,
) *RowMetric

NewRowMetric creates a *RowMetric from tags, fields and a timestamp.

func (*RowMetric) AddField

func (m *RowMetric) AddField(k string, v interface{})

AddField adds an lp.Field to a metric.

func (*RowMetric) AddTag

func (m *RowMetric) AddTag(k, v string)

AddTag adds an lp.Tag to a metric.

func (*RowMetric) FieldList

func (m *RowMetric) FieldList() []*lp.Field

FieldList returns a slice containing the Fields of a Metric.

func (*RowMetric) Name

func (m *RowMetric) Name() string

Name returns the name of the metric.

func (*RowMetric) SortFields

func (m *RowMetric) SortFields()

SortFields orders the fields of a metric alphnumerically by key.

func (*RowMetric) SortTags

func (m *RowMetric) SortTags()

SortTags orders the tags of a metric alphnumerically by key. This is just here as a helper, to make it easy to keep tags sorted if you are creating a RowMetric manually.

func (*RowMetric) TagList

func (m *RowMetric) TagList() []*lp.Tag

TagList returns a slice containing Tags of a Metric.

func (*RowMetric) Time

func (m *RowMetric) Time() time.Time

Time is the timestamp of a metric.

type Setup

type Setup struct {
	Allowed bool `json:"allowed"`
}

type SetupCreateBucket

type SetupCreateBucket struct {
	Description    string           `json:"description"`
	Name           string           `json:"name"`
	OrgID          string           `json:"orgID"`
	RetentionRules []RetentionRules `json:"retentionRules"`
	Rp             string           `json:"rp"`
}

type SetupNewAuthorization

type SetupNewAuthorization struct {
	Description string        `json:"description"`
	OrgID       string        `json:"orgID"`
	Permissions []Permissions `json:"permissions"`
	Status      string        `json:"status"`
}

type SetupRequest

type SetupRequest struct {
	Username           string `json:"username"`
	Password           string `json:"password"`
	Org                string `json:"org"`
	Bucket             string `json:"bucket"`
	RetentionPeriodHrs int    `json:"retentionPeriodHrs"`
}

SetupRequest is a request to setup a new influx instance.

type SetupResult

type SetupResult struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	User    struct {
		Links struct {
			Logs string `json:"logs"`
			Self string `json:"self"`
		} `json:"links"`
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"user"`
	Bucket struct {
		ID             string `json:"id"`
		OrganizationID string `json:"organizationID"`
		Organization   string `json:"organization"`
		Name           string `json:"name"`
		RetentionRules []struct {
			Type         string `json:"type"`
			EverySeconds int    `json:"everySeconds"`
		} `json:"retentionRules"`
		Links struct {
			Labels  string `json:"labels"`
			Logs    string `json:"logs"`
			Members string `json:"members"`
			Org     string `json:"org"`
			Owners  string `json:"owners"`
			Self    string `json:"self"`
			Write   string `json:"write"`
		} `json:"links"`
	} `json:"bucket"`
	Org struct {
		Links struct {
			Buckets    string `json:"buckets"`
			Dashboards string `json:"dashboards"`
			Labels     string `json:"labels"`
			Logs       string `json:"logs"`
			Members    string `json:"members"`
			Owners     string `json:"owners"`
			Secrets    string `json:"secrets"`
			Self       string `json:"self"`
			Tasks      string `json:"tasks"`
		} `json:"links"`
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"org"`
	Auth struct {
		ID          string `json:"id"`
		Token       string `json:"token"`
		Status      string `json:"status"`
		Description string `json:"description"`
		OrgID       string `json:"orgID"`
		Org         string `json:"org"`
		UserID      string `json:"userID"`
		User        string `json:"user"`
		Permissions []struct {
			Action   string `json:"action"`
			Resource struct {
				Type string `json:"type"`
			} `json:"resource"`
		} `json:"permissions"`
		Links struct {
			Self string `json:"self"`
			User string `json:"user"`
		} `json:"links"`
	} `json:"auth"`
}

SetupResult is the result of setting up a new influx instance.

type SetupUpdateBucket

type SetupUpdateBucket struct {
	Description    string           `json:"description"`
	Labels         []Labels         `json:"labels"`
	Name           string           `json:"name"`
	OrgID          string           `json:"orgID"`
	RetentionRules []RetentionRules `json:"retentionRules"`
	Rp             string           `json:"rp"`
}

type SimpleBucket

type SimpleBucket struct {
	Links struct {
		Labels  string `json:"labels"`
		Logs    string `json:"logs"`
		Members string `json:"members"`
		Org     string `json:"org"`
		Owners  string `json:"owners"`
		Self    string `json:"self"`
		Write   string `json:"write"`
	} `json:"links"`
	Id             string           `json:"id"`
	Type           string           `json:"user"`
	Name           string           `json:"name"`
	Description    string           `json:"description"`
	OrgID          string           `json:"orgID"`
	Rp             string           `json:"rp"`
	CreatedAt      string           `json:"createdAt"`
	UpdatedAt      string           `json:"updatedAt"`
	RetentionRules []RetentionRules `json:"retentionRules"`
	Labels         []struct {
		Id         string `json:"id"`
		OrgID      string `json:"orgID"`
		Name       string `json:"name"`
		Properties struct {
			Color       string `json:"color"`
			Description string `json:"description"`
		} `json:"properties"`
	} `json:"labels"`
}

type Status

type Status struct {
	Description string `json:"description"`
	Status      string `json:"status"`
}

type Tag

type Tag = lp.Tag

Tag is just a github.com/influxdata/line-protocol.Tag. We alias here to keep abstractions from leaking.

type User

type User struct {
	Id      string `json:"id"`
	OauthID string `json:"oauthID"`
	Name    string `json:"name"`
	Status  string `json:"status"`
	Links   struct {
		Self string `json:"self"`
		Logs string `json:"logs"`
	} `json:"links"`
}

type UserList

type UserList struct {
	Links struct {
		Self string `json:"self"`
	} `json:"links"`
	Users []User `json:"users"`
}

type UserLogs

type UserLogs struct {
	Logs []struct {
		Description string `json:"description"`
		Time        string `json:"time"`
		UserID      string `json:"userID"`
		Links       struct {
			User string `json:"user"`
		} `json:"links"`
	} `json:"logs"`
	Links struct {
		Next string `json:"next"`
		Self string `json:"self"`
		Prev string `json:"prev"`
	} `json:"links"`
}

Directories

Path Synopsis
Code generated for client DO NOT EDIT.
Code generated for client DO NOT EDIT.
internal
ast
Package ast provides tools for manipulating the flux ast.
Package ast provides tools for manipulating the flux ast.
Package writer contains useful types for buffering, batching and periodically syncing writes onto a provided metric writing client.
Package writer contains useful types for buffering, batching and periodically syncing writes onto a provided metric writing client.

Jump to

Keyboard shortcuts

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