本文整理匯總了Golang中github.com/influxdb/influxdb/client.BatchPoints類的典型用法代碼示例。如果您正苦於以下問題:Golang BatchPoints類的具體用法?Golang BatchPoints怎麽用?Golang BatchPoints使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BatchPoints類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sendMetrics
func sendMetrics(config StartupConfig, runningConfig RunningConfig, bps influx.BatchPoints, retry bool) {
//influx connection
influxClient, err := influxConnect(config, runningConfig)
if err != nil {
if retry {
config.BpsChan <- bps
}
errHndlr(err, ERROR)
return
}
pts := bps.Points
for len(pts) > 0 {
chunk_bps := influx.BatchPoints{
Database: bps.Database,
RetentionPolicy: bps.RetentionPolicy,
}
chunk_bps.Points = pts[:IntMin(maxPublishSize, len(pts))]
pts = pts[IntMin(maxPublishSize, len(pts)):]
_, err = influxClient.Write(chunk_bps)
if err != nil {
if retry {
config.BpsChan <- chunk_bps
}
errHndlr(err, ERROR)
} else {
log.Debug("Sent ", len(chunk_bps.Points), " stats")
}
}
}
示例2: ReadDB
func ReadDB(c *client.Client, sdb, ddb, cmd string) client.BatchPoints {
q := client.Query{
Command: cmd,
Database: sdb,
}
//get type client.BatchPoints
var batchpoints client.BatchPoints
response, err := c.Query(q)
if err != nil {
fmt.Printf("Fail to get response from database, read database error: %s\n", err.Error())
}
res := response.Results
if len(res) == 0 {
fmt.Printf("The response of database is null, read database error!\n")
} else {
res_length := len(res)
for k := 0; k < res_length; k++ {
//show progress of reading series
count := len(res[k].Series)
bar := pb.StartNew(count)
for _, ser := range res[k].Series {
//get type client.Point
var point client.Point
point.Measurement = ser.Name
point.Tags = ser.Tags
for _, v := range ser.Values {
point.Time, _ = time.Parse(time.RFC3339, v[0].(string))
field := make(map[string]interface{})
l := len(v)
for i := 1; i < l; i++ {
if v[i] != nil {
field[ser.Columns[i]] = v[i]
}
}
point.Fields = field
point.Precision = "s"
batchpoints.Points = append(batchpoints.Points, point)
}
bar.Increment()
time.Sleep(3 * time.Millisecond)
}
bar.FinishPrint("Read series has finished!\n")
}
batchpoints.Database = ddb
batchpoints.RetentionPolicy = "default"
}
return batchpoints
}
示例3: send
func send(client *influxClient.Client, series []influxClient.Point) error {
w := influxClient.BatchPoints{Database: databaseFlag, Points: series}
if retentionPolicyFlag != "" {
w.RetentionPolicy = retentionPolicyFlag
}
_, err := client.Write(w)
return err
}
示例4: MockBatchPoints
// MockBatchPoints returns a mock BatchPoints object for using in unit tests
// of telegraf output sinks.
func MockBatchPoints() client.BatchPoints {
var bp client.BatchPoints
bp.Time = time.Now()
bp.Tags = map[string]string{"tag1": "value1"}
bp.Points = []client.Point{
{
Fields: map[string]interface{}{"value": 1.0},
},
}
return bp
}
示例5: TestWrite
func TestWrite(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
o := &OpenTSDB{
Host: testutil.GetLocalHost(),
Port: 24242,
Prefix: "prefix.test.",
}
// Verify that we can connect to the OpenTSDB instance
err := o.Connect()
require.NoError(t, err)
// Verify that we can successfully write data to OpenTSDB
err = o.Write(testutil.MockBatchPoints())
require.NoError(t, err)
// Verify postive and negative test cases of writing data
var bp client.BatchPoints
bp.Time = time.Now()
bp.Tags = map[string]string{"testkey": "testvalue"}
bp.Points = []client.Point{
{
Measurement: "justametric.float",
Fields: map[string]interface{}{"value": float64(1.0)},
},
{
Measurement: "justametric.int",
Fields: map[string]interface{}{"value": int64(123456789)},
},
{
Measurement: "justametric.uint",
Fields: map[string]interface{}{"value": uint64(123456789012345)},
},
{
Measurement: "justametric.string",
Fields: map[string]interface{}{"value": "Lorem Ipsum"},
},
{
Measurement: "justametric.anotherfloat",
Fields: map[string]interface{}{"value": float64(42.0)},
},
}
err = o.Write(bp)
require.NoError(t, err)
}
示例6: Write
func (i *InfluxDB) Write(bp client.BatchPoints) error {
bp.Database = i.Database
if _, err := i.conn.Write(bp); err != nil {
return err
}
return nil
}
示例7: Write
// Choose a random server in the cluster to write to until a successful write
// occurs, logging each unsuccessful. If all servers fail, return error.
func (i *InfluxDB) Write(bp client.BatchPoints) error {
bp.Database = i.Database
// This will get set to nil if a successful write occurs
err := errors.New("Could not write to any InfluxDB server in cluster")
p := rand.Perm(len(i.conns))
for _, n := range p {
if _, e := i.conns[n].Write(bp); e != nil {
log.Println("ERROR: " + e.Error())
} else {
err = nil
break
}
}
return err
}