Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EpochToTime ¶ added in v0.9.0
EpochToTime takes a unix epoch time and uses precision to return back a time.Time
Types ¶
type BatchPoints ¶ added in v0.9.0
type BatchPoints struct { Points []Point `json:"points,omitempty"` Database string `json:"database,omitempty"` RetentionPolicy string `json:"retentionPolicy,omitempty"` Tags map[string]string `json:"tags,omitempty"` Time time.Time `json:"time,omitempty"` Precision string `json:"precision,omitempty"` }
BatchPoints is used to send batched data in a single write. Database and Points are required If no retention policy is specified, it will use the databases default retention policy. If tags are specified, they will be "merged" with all points. If a point already has that tag, it is ignored. If time is specified, it will be applied to any point with an empty time. Precision can be specified if the time is in epoch format (integer). Valid values for Precision are n, u, ms, s, m, and h
func (*BatchPoints) UnmarshalJSON ¶ added in v0.9.0
func (bp *BatchPoints) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes the data into the BatchPoints struct
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to make calls to the server.
func NewClient ¶
NewClient will instantiate and return a connected client to issue commands to the server.
Example ¶
package main import ( "fmt" "log" "net/url" "os" "github.com/influxdb/influxdb/client" ) func main() { host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086)) if err != nil { log.Fatal(err) } // NOTE: this assumes you've setup a user and have setup shell env variables, // namely INFLUX_USER/INFLUX_PWD. If not just ommit Username/Password below. conf := client.Config{ URL: *host, Username: os.Getenv("INFLUX_USER"), Password: os.Getenv("INFLUX_PWD"), } con, err := client.NewClient(conf) if err != nil { log.Fatal(err) } log.Println("Connection", con) }
Output:
func (*Client) Addr ¶ added in v0.9.0
Addr provides the current url as a string of the server the client is connected to.
func (*Client) Dump ¶ added in v0.9.0
func (c *Client) Dump(db string) (io.ReadCloser, error)
Dump connects to server and retrieves all data stored for specified database. If successful, Dump returns the entire response body, which is an io.ReadCloser
func (*Client) Ping ¶
Ping will check to see if the server is up Ping returns how long the requeset took, the version of the server it connected to, and an error if one occured.
Example ¶
package main import ( "fmt" "log" "net/url" "github.com/influxdb/influxdb/client" ) func main() { host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086)) if err != nil { log.Fatal(err) } con, err := client.NewClient(client.Config{URL: *host}) if err != nil { log.Fatal(err) } dur, ver, err := con.Ping() if err != nil { log.Fatal(err) } log.Printf("Happy as a hippo! %v, %s", dur, ver) }
Output:
func (*Client) Query ¶
Query sends a command to the server and returns the Response
Example ¶
package main import ( "fmt" "log" "net/url" "github.com/influxdb/influxdb/client" ) func main() { host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086)) if err != nil { log.Fatal(err) } con, err := client.NewClient(client.Config{URL: *host}) if err != nil { log.Fatal(err) } q := client.Query{ Command: "select count(value) from shapes", Database: "square_holes", } if response, err := con.Query(q); err == nil && response.Error() == nil { log.Println(response.Results) } }
Output:
func (*Client) Write ¶ added in v0.9.0
func (c *Client) Write(bp BatchPoints) (*Response, error)
Write takes BatchPoints and allows for writing of multiple points with defaults If successful, error is nil and Response is nil If an error occurs, Response may contain additional information if populated.
Example ¶
package main import ( "fmt" "log" "math/rand" "net/url" "strconv" "time" "github.com/influxdb/influxdb/client" ) func main() { host, err := url.Parse(fmt.Sprintf("http://%s:%d", "localhost", 8086)) if err != nil { log.Fatal(err) } con, err := client.NewClient(client.Config{URL: *host}) if err != nil { log.Fatal(err) } var ( shapes = []string{"circle", "rectangle", "square", "triangle"} colors = []string{"red", "blue", "green"} sampleSize = 1000 pts = make([]client.Point, sampleSize) ) rand.Seed(42) for i := 0; i < sampleSize; i++ { pts[i] = client.Point{ Name: "shapes", Tags: map[string]string{ "color": strconv.Itoa(rand.Intn(len(colors))), "shape": strconv.Itoa(rand.Intn(len(shapes))), }, Fields: map[string]interface{}{ "value": rand.Intn(sampleSize), }, Time: time.Now(), Precision: "s", } } bps := client.BatchPoints{ Points: pts, Database: "BumbeBeeTuna", RetentionPolicy: "default", } _, err = con.Write(bps) if err != nil { log.Fatal(err) } }
Output:
type Config ¶ added in v0.9.0
Config is used to specify what server to connect to. URL: The URL of the server connecting to. Username/Password are optional. They will be passed via basic auth if provided. UserAgent: If not provided, will default "InfluxDBClient",
type Point ¶ added in v0.9.0
type Point struct { Name string Tags map[string]string Time time.Time Fields map[string]interface{} Precision string }
Point defines the fields that will be written to the database Name, Time, and Fields are required Precision can be specified if the time is in epoch format (integer). Valid values for Precision are n, u, ms, s, m, and h
func (*Point) MarshalJSON ¶ added in v0.9.0
MarshalJSON will format the time in RFC3339Nano Precision is also ignored as it is only used for writing, not reading Or another way to say it is we always send back in nanosecond precision
func (*Point) UnmarshalJSON ¶ added in v0.9.0
UnmarshalJSON decodes the data into the Point struct
type Query ¶ added in v0.9.0
Query is used to send a command to the server. Both Command and Database are required.
type Response ¶ added in v0.9.0
Response represents a list of statement results.
func (Response) Error ¶ added in v0.9.0
Error returns the first error from any statement. Returns nil if no errors occurred on any statements.
func (*Response) MarshalJSON ¶ added in v0.9.0
MarshalJSON encodes the response into JSON.
func (*Response) UnmarshalJSON ¶ added in v0.9.0
UnmarshalJSON decodes the data into the Response struct
type Result ¶ added in v0.9.0
Result represents a resultset returned from a single statement.
func (*Result) MarshalJSON ¶ added in v0.9.0
MarshalJSON encodes the result into JSON.
func (*Result) UnmarshalJSON ¶ added in v0.9.0
UnmarshalJSON decodes the data into the Result struct