Esempio n. 1
0
// Adds additional tags to the existing tags of a point
func addTagsToPoint(point *influxdb.Point, tags map[string]string) {
	if point.Tags == nil {
		point.Tags = tags
	} else {
		for k, v := range tags {
			point.Tags[k] = v
		}
	}
}
Esempio n. 2
0
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
}
Esempio n. 3
0
// deepcopy returns a deep copy of the BatchPoints object. This is primarily so
// we can do multithreaded output flushing (see Agent.flush)
func (bp *BatchPoints) deepcopy() *BatchPoints {
	bp.mu.Lock()
	defer bp.mu.Unlock()

	var bpc BatchPoints
	bpc.Time = bp.Time
	bpc.Precision = bp.Precision

	bpc.Tags = make(map[string]string)
	for k, v := range bp.Tags {
		bpc.Tags[k] = v
	}

	var pts []client.Point
	for _, pt := range bp.Points {
		var ptc client.Point

		ptc.Measurement = pt.Measurement
		ptc.Time = pt.Time
		ptc.Precision = pt.Precision
		ptc.Raw = pt.Raw

		ptc.Tags = make(map[string]string)
		ptc.Fields = make(map[string]interface{})

		for k, v := range pt.Tags {
			ptc.Tags[k] = v
		}

		for k, v := range pt.Fields {
			ptc.Fields[k] = v
		}
		pts = append(pts, ptc)
	}

	bpc.Points = pts
	return &bpc
}