예제 #1
0
파일: postgres.go 프로젝트: tgres/tgres
func (p *pgSerDe) FlushDataSource(ds *rrd.DataSource) error {
	for _, rra := range ds.RRAs() {
		if rra.PointCount() > 0 {
			if err := p.flushRoundRobinArchive(rra); err != nil {
				log.Printf("FlushDataSource(): error flushing RRA, probable data loss: %v", err)
				return err
			}
		}
	}

	if debug {
		log.Printf("FlushDataSource(): Id %d: LastUpdate: %v, LastDs: %v, Value: %v, Duration: %v", ds.Id(), ds.LastUpdate(), ds.LastDs(), ds.Value(), ds.Duration())
	}
	durationMs := ds.Duration().Nanoseconds() / 1000000
	if rows, err := p.sql7.Query(ds.LastUpdate(), ds.LastDs(), ds.Value(), durationMs, ds.Id()); err != nil {
		log.Printf("FlushDataSource(): database error: %v flushing data source %#v", err, ds)
		return err
	} else {
		rows.Close()
	}

	return nil
}
예제 #2
0
파일: postgres.go 프로젝트: tgres/tgres
func (p *pgSerDe) fetchRoundRobinArchives(ds *rrd.DataSource) ([]*rrd.RoundRobinArchive, error) {

	const sql = `SELECT id, ds_id, cf, steps_per_row, size, width, xff, value, duration_ms, latest FROM %[1]srra rra WHERE ds_id = $1`

	rows, err := p.dbConn.Query(fmt.Sprintf(sql, p.prefix), ds.Id())
	if err != nil {
		log.Printf("fetchRoundRobinArchives(): error querying database: %v", err)
		return nil, err
	}
	defer rows.Close()

	var rras []*rrd.RoundRobinArchive
	for rows.Next() {
		if rra, err := roundRobinArchiveFromRow(rows, ds.Step()); err == nil {
			rras = append(rras, rra)
		} else {
			log.Printf("fetchRoundRobinArchives(): error: %v", err)
			return nil, err
		}
	}

	return rras, nil
}