The Chronix Go Client Library
This repository contains the Go client library for Chronix. It allows writing
time series data into Chronix and reading it back. While the write
implementation allows storing structured time series data, the read
implementation is still rudimentary and returns only an opaque byte slice
(usually containing JSON, but this depends on the fl
query parameter).
For full details on usage, see the
Go package documentation.
Example Usage
This example
stores several test time series in Chronix and reads them back.
Importing
import "github.com/ChronixDB/chronix.go/chronix"
Creating a Chronix Client
// Parse the Solr/Chronix URL.
u, err := url.Parse("http://<solr-url>/solr/chronix")
if err != nil {
// Handle error.
}
// Create a Solr client.
solr := chronix.NewSolrClient(u, nil)
// Construct a Chronix client based on the Solr client.
c := chronix.New(solr)
Writing Series Data
// Construct a test time series with one data point.
series := []chronix.TimeSeries{
{
Metric: "testmetric",
Attributes: map[string]string{
"host": "testhost",
},
Points: []chronix.Point{
{
Timestamp: 1470784794,
Value: 42.23,
},
},
},
}
// Store the test series and commit within one second.
err := c.Store(series, false, time.Second)
if err != nil {
// Handle error.
}
Querying Series Data
// Define the Chronix query parameters.
q := "metric:(testmetric) AND start:1470784794000 AND end:1470784794000"
fq := "join=host_s,metric"
fl := "dataAsJson"
// Execute the query.
resp, err := c.Query(q, fq, fl)
if err != nil {
// Handle error.
}