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 }
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 }