influx

package
v2.31.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 6 Imported by: 1

README

Perkakas Influx Library

This library helps you to send point to influx. It supports sending one point at a time or you can create batch points and send it at once.

How To Send Point

config := ClientConfig{
    Addr:               "http://localhost:8086",
    Database:           "myDB",
    Timeout:            5 * time.Second,
}

// Please note that tags is indexed.
// So please consider place a value to tags
// if you want to filter it on your query
// to achieve performance.
tags := Tags{
    "id": "123456",
    "price": "10000",
}

// Fields is not indexed, so you can consider it
// as additional data
fields := Fields{
    "name": "Mechanical Keyboard",
    "manufacturer": "Logitech",
}

c, err := NewClient(config)
if err != nil {
    t.Log(err)
    t.FailNow()
}

// You can say that the first parameter is the table name in SQL.
// The precision argument specifies the format/precision of any 
// returned timestamps.
c.WritePoints("products", tags, fields, "s")

How To Send Batch Points

config := ClientConfig{
    Addr:               "http://localhost:8086",
    Database:           "myDB",
    Timeout:            5 * time.Second,
}

tags := Tags{
    "id": "123456",
    "price": "10000",
}

fields := Fields{
    "name": "Mechanical Keyboard",
    "manufacturer": "Logitech",
}

c, err := NewClient(config)
if err != nil {
    t.Log(err)
    t.FailNow()
}

b, err := c.NewBatchPointsWriter("s")
if err != nil {
    t.Log(err)
    t.FailNow()
}

b.AddPoints("products", tags, fields) // you can add more points later

b.Write() // finally write the points

Important Notes

Please close the client when your application exits

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BatchPointsWriter

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

func (BatchPointsWriter) AddPoints

func (b BatchPointsWriter) AddPoints(name string, tags Tags, fields Fields)

func (BatchPointsWriter) Write

func (b BatchPointsWriter) Write() (err error)

type Client

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

func NewClient

func NewClient(config ClientConfig) (c *Client, err error)

func (*Client) NewBatchPointsWriter

func (c *Client) NewBatchPointsWriter(precision string) (bpw BatchPointsWriter, err error)

func (*Client) Ping added in v2.8.2

func (c *Client) Ping() (err error)

func (*Client) WritePoints

func (c *Client) WritePoints(name string, tags Tags, fields Fields, precision string) (err error)

type ClientConfig

type ClientConfig struct {
	Addr               string
	Username           string
	Password           string
	Database           string
	RetentionPolicy    string
	UserAgent          string
	Timeout            time.Duration
	InsecureSkipVerify bool
	TLSConfig          *tls.Config
	Proxy              func(req *http.Request) (*url.URL, error)
}

type Fields

type Fields map[string]interface{}

type Tags

type Tags map[string]string

Jump to

Keyboard shortcuts

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