コード例 #1
0
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
0
ファイル: client.go プロジェクト: guaiguaihw/influxdb-move
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
0
ファイル: main.go プロジェクト: jmptrader/sysinfo_influxdb
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
0
ファイル: testutil.go プロジェクト: Asana/telegraf
// 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
0
ファイル: opentsdb_test.go プロジェクト: nibosho/telegraf
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
0
ファイル: influxdb.go プロジェクト: pablrod/telegraf
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
0
ファイル: influxdb.go プロジェクト: kokarn/telegraf
// 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
}