當前位置: 首頁>>代碼示例>>Golang>>正文


Golang client.BatchPoints類代碼示例

本文整理匯總了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")
		}
	}
}
開發者ID:GeorgeAndretsos,項目名稱:traffic_control,代碼行數:32,代碼來源:traffic_stats.go

示例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
}
開發者ID:guaiguaihw,項目名稱:influxdb-move,代碼行數:57,代碼來源:client.go

示例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
}
開發者ID:jmptrader,項目名稱:sysinfo_influxdb,代碼行數:10,代碼來源:main.go

示例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
}
開發者ID:Asana,項目名稱:telegraf,代碼行數:13,代碼來源:testutil.go

示例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)

}
開發者ID:nibosho,項目名稱:telegraf,代碼行數:49,代碼來源:opentsdb_test.go

示例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
}
開發者ID:pablrod,項目名稱:telegraf,代碼行數:7,代碼來源:influxdb.go

示例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
}
開發者ID:kokarn,項目名稱:telegraf,代碼行數:19,代碼來源:influxdb.go


注:本文中的github.com/influxdb/influxdb/client.BatchPoints類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。