本文整理匯總了Golang中github.com/influxdata/influxdb/client/v2.NewBatchPoints函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewBatchPoints函數的具體用法?Golang NewBatchPoints怎麽用?Golang NewBatchPoints使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewBatchPoints函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
if conf.StatisticEnable {
var err error
influxClient, err = influx.NewHTTPClient(
influx.HTTPConfig{
Addr: conf.InfluxURL,
Username: conf.InfluxUser,
Password: conf.InfluxPassword,
})
if err != nil {
log.Println("Failed to init influx client: ", err.Error())
os.Exit(1)
}
influxBatchPoints, err = influx.NewBatchPoints(influx.BatchPointsConfig{
Database: conf.InfluxDB,
Precision: "s",
})
if err != nil {
log.Println("Failed to init influx batch points: ", err.Error())
os.Exit(1)
}
go logStatisticTask()
}
}
示例2: writeEntries
// Perform the batch write
func (w *Writer) writeEntries(entries []Entry) {
bps, err := client.NewBatchPoints(client.BatchPointsConfig{
Database: w.DB,
RetentionPolicy: "default",
Precision: "s",
// WriteConsistency: string,
})
Checkerr(err)
for _, entry := range entries {
name := "watt" // Measurement
tags := map[string]string{ /*"ted1k",...*/ }
fields := map[string]interface{}{
"value": entry.Watt,
}
pt, err := client.NewPoint(name, tags, fields, entry.Stamp)
Checkerr(err)
bps.AddPoint(pt)
// fmt.Printf("point: %v\n", pt)
}
// TODO(daneroo): retry, if error is timeout?
err = w.con.Write(bps)
Checkerr(err)
}
示例3: TestHistogramWithTags
func TestHistogramWithTags(t *testing.T) {
expectedName := "test_histogram"
expectedTags := map[string]string{
"key1": "value1",
"key2": "value2",
}
expectedFields := []map[string]map[string]interface{}{
{
"test_histogram_p50": {"value": 5.0},
"test_histogram_p90": {"value": 5.0},
"test_histogram_p95": {"value": 5.0},
"test_histogram_p99": {"value": 5.0},
},
{
"test_histogram_p50": {"Test": "Test", "value": 5.0},
"test_histogram_p90": {"Test": "Test", "value": 10.0},
"test_histogram_p95": {"Test": "Test", "value": 10.0},
"test_histogram_p99": {"Test": "Test", "value": 10.0},
},
{
"test_histogram_p50": {"Test": "Test", "value": 5.0},
"test_histogram_p90": {"Test": "Test", "value": 10.0},
"test_histogram_p95": {"Test": "Test", "value": 10.0},
"test_histogram_p99": {"Test": "Test", "value": 10.0},
},
}
quantiles := []int{50, 90, 95, 99}
cl := &mockClient{}
cl.Add(12)
bp, _ := stdinflux.NewBatchPoints(stdinflux.BatchPointsConfig{
Database: "testing",
Precision: "s",
})
tags := []metrics.Field{}
for key, value := range expectedTags {
tags = append(tags, metrics.Field{Key: key, Value: value})
}
triggerChan := make(chan time.Time)
histogram := influxdb.NewHistogramTick(cl, bp, expectedName, tags, triggerChan, 0, 100, 3, quantiles...)
histogram.Observe(5)
histogram = histogram.With(metrics.Field{Key: "Test", Value: "Test"})
histogram.Observe(10)
histogram.Observe(4)
triggerChan <- time.Now()
cl.Wait()
for i := 0; i <= 11; i++ {
actualName := cl.Points[i].Name()
givenName := expectedName + actualName[len(actualName)-4:]
givenPoint := mockPoint{
Name: givenName,
Tags: expectedTags,
Fields: expectedFields[i/4][actualName],
}
comparePoint(t, i, givenPoint, cl.Points[i])
}
}
示例4: syncDeliveryServiceStat
func syncDeliveryServiceStat(sourceClient influx.Client, targetClient influx.Client, statName string, days int) {
db := "deliveryservice_stats"
bps, _ := influx.NewBatchPoints(influx.BatchPointsConfig{
Database: db,
Precision: "ms",
RetentionPolicy: "monthly",
})
queryString := fmt.Sprintf("select time, cachegroup, cdn, deliveryservice, value from \"monthly\".\"%s\"", statName)
if days > 0 {
queryString += fmt.Sprintf(" where time > now() - %dd", days)
}
fmt.Println("queryString ", queryString)
res, err := queryDB(sourceClient, queryString, db)
if err != nil {
errorMessage = fmt.Sprintf("An error occured getting %s records from sourceDb: %v\n", statName, err)
fmt.Println(errorMessage)
return
}
sourceStats := getDeliveryServiceStats(res)
// get value from target DB
targetRes, err := queryDB(targetClient, queryString, db)
if err != nil {
errorMessage = fmt.Sprintf("An error occured getting %s record from target db: %v\n", statName, err)
fmt.Println(errorMessage)
return
}
targetStats := getDeliveryServiceStats(targetRes)
for ssKey := range sourceStats {
ts := targetStats[ssKey]
ss := sourceStats[ssKey]
if ts.value > ss.value {
//fmt.Printf("target value %v is at least equal to source value %v\n", ts.value, ss.value)
continue //target value is bigger so leave it
}
statTime, _ := time.Parse(time.RFC3339, ss.t)
tags := map[string]string{
"cdn": ss.cdn,
"cachegroup": ss.cacheGroup,
"deliveryservice": ss.deliveryService,
}
fields := map[string]interface{}{
"value": ss.value,
}
pt, err := influx.NewPoint(
statName,
tags,
fields,
statTime,
)
if err != nil {
fmt.Printf("error adding creating point for %v...%v\n", statName, err)
continue
}
bps.AddPoint(pt)
}
targetClient.Write(bps)
}
示例5: InfluxDB
// InfluxDB writes interest processing time to influxDB.
//
// The data collected can be viewed with: SELECT "value" FROM :name WHERE "name" = ':interest_name'.
func InfluxDB(client influxdb.Client, db, name string, tags map[string]string) mux.Middleware {
return func(next mux.Handler) mux.Handler {
return mux.HandlerFunc(func(w ndn.Sender, i *ndn.Interest) {
before := time.Now()
next.ServeNDN(w, i)
t := make(map[string]string)
for k, v := range tags {
t[k] = v
}
t["name"] = i.Name.String()
pt, _ := influxdb.NewPoint(name, t, map[string]interface{}{
"value": float64(time.Since(before)) / float64(time.Millisecond),
}, time.Now())
bp, _ := influxdb.NewBatchPoints(influxdb.BatchPointsConfig{
Database: db,
})
bp.AddPoint(pt)
err := client.Write(bp)
if err != nil {
log.Println(err)
return
}
})
}
}
示例6: calcDailySummary
func calcDailySummary(now time.Time, config StartupConfig, runningConfig RunningConfig) {
log.Infof("lastSummaryTime is %v", runningConfig.LastSummaryTime)
if runningConfig.LastSummaryTime.Day() != now.Day() {
startTime := now.Truncate(24 * time.Hour).Add(-24 * time.Hour)
endTime := startTime.Add(24 * time.Hour)
log.Info("Summarizing from ", startTime, " (", startTime.Unix(), ") to ", endTime, " (", endTime.Unix(), ")")
// influx connection
influxClient, err := influxConnect(config, runningConfig)
if err != nil {
log.Error("Could not connect to InfluxDb to get daily summary stats!!")
errHndlr(err, ERROR)
return
}
bp, _ := influx.NewBatchPoints(influx.BatchPointsConfig{
Database: "daily_stats",
Precision: "s",
RetentionPolicy: config.DailySummaryRetentionPolicy,
})
calcDailyMaxGbps(influxClient, bp, startTime, endTime, config)
calcDailyBytesServed(influxClient, bp, startTime, endTime, config)
log.Info("Collected daily stats @ ", now)
}
}
示例7: NewResultsPointBatch
// NewResultsPointBatch creates a new batch of points for the results
func (st *StressTest) NewResultsPointBatch() influx.BatchPoints {
bp, _ := influx.NewBatchPoints(influx.BatchPointsConfig{
Database: st.TestDB,
Precision: "ns",
})
return bp
}
示例8: TickHandler
func (t *tickData) TickHandler(ctx context.Context, tick *tickRecorder.Tick) error {
var err error
t.log.Infoln("Received data")
tags := map[string]string{"pair": "AUDUSD"}
fields := map[string]interface{}{
"bid": tick.Bid,
"ask": tick.Ask,
"last": tick.Last,
}
point, err := influx.NewPoint("tick_data", tags, fields, time.Unix(0, tick.Time))
bp, err := influx.NewBatchPoints(influx.BatchPointsConfig{
Database: "tick",
Precision: "ns",
})
bp.AddPoint(point)
t.log.Infoln("Created batch point:", bp)
if influxErr := t.influx.Write(bp); influxErr != nil {
t.log.Error(influxErr)
}
return err
}
示例9: createInfluxDBMetrics
func createInfluxDBMetrics(ping Ping) (influxdbclient.BatchPoints, error) {
var err error
bp, err := influxdbclient.NewBatchPoints(influxdbclient.BatchPointsConfig{
Database: receiverDatabaseFlag,
Precision: "s",
})
if err != nil {
return nil, err
}
tags := map[string]string{
"origin": ping.origin,
"destination": ping.destination,
}
fields := map[string]interface{}{
"loss": ping.stats.loss,
"min": ping.stats.min,
"avg": ping.stats.avg,
"max": ping.stats.max,
"mdev": ping.stats.mdev,
}
pt, err := influxdbclient.NewPoint("ping", tags, fields, time.Unix(ping.time, 0))
if err != nil {
return nil, err
}
bp.AddPoint(pt)
return bp, nil
}
示例10: WriteTo
// WriteTo flushes the buffered content of the metrics to the writer, in an
// Influx BatchPoints format. WriteTo abides best-effort semantics, so
// observations are lost if there is a problem with the write. Clients should be
// sure to call WriteTo regularly, ideally through the WriteLoop helper method.
func (in *Influx) WriteTo(w BatchPointsWriter) (err error) {
bp, err := influxdb.NewBatchPoints(in.conf)
if err != nil {
return err
}
now := time.Now()
in.counters.Reset().Walk(func(name string, lvs lv.LabelValues, values []float64) bool {
fields := fieldsFrom(lvs)
fields["count"] = sum(values)
var p *influxdb.Point
p, err = influxdb.NewPoint(name, in.tags, fields, now)
if err != nil {
return false
}
bp.AddPoint(p)
return true
})
if err != nil {
return err
}
in.gauges.Reset().Walk(func(name string, lvs lv.LabelValues, values []float64) bool {
fields := fieldsFrom(lvs)
fields["value"] = last(values)
var p *influxdb.Point
p, err = influxdb.NewPoint(name, in.tags, fields, now)
if err != nil {
return false
}
bp.AddPoint(p)
return true
})
if err != nil {
return err
}
in.histograms.Reset().Walk(func(name string, lvs lv.LabelValues, values []float64) bool {
fields := fieldsFrom(lvs)
ps := make([]*influxdb.Point, len(values))
for i, v := range values {
fields["value"] = v // overwrite each time
ps[i], err = influxdb.NewPoint(name, in.tags, fields, now)
if err != nil {
return false
}
}
bp.AddPoints(ps)
return true
})
if err != nil {
return err
}
return w.Write(bp)
}
示例11: NewReporter
func NewReporter(conf flux.BatchPointsConfig, stats chan flux.BatchPoints, points chan *flux.Point) (*Reporter, error) {
bp, err := flux.NewBatchPoints(conf)
if err != nil {
return nil, err
}
r := &Reporter{
accum: stats,
batch: bp,
conf: conf,
points: points,
}
return r, nil
}
示例12: TestStoreFrontBatcher
func TestStoreFrontBatcher(t *testing.T) {
sf, _, _ := NewTestStoreFront()
bpconf := influx.BatchPointsConfig{
Database: fmt.Sprintf("_%v", sf.TestName),
Precision: "ns",
}
bp, _ := influx.NewBatchPoints(bpconf)
pt := NewBlankTestPoint()
bp = sf.batcher(pt, bp, bpconf)
if len(bp.Points()) != 1 {
t.Fail()
}
}
示例13: TestStressTestBatcher
func TestStressTestBatcher(t *testing.T) {
sf, _, _ := NewTestStressTest()
bpconf := influx.BatchPointsConfig{
Database: sf.TestDB,
Precision: "ns",
}
bp, _ := influx.NewBatchPoints(bpconf)
pt := NewBlankTestPoint()
bp = sf.batcher(pt, bp)
if len(bp.Points()) != 1 {
t.Fail()
}
}
示例14: newBatchPoints
func (hook *InfluxDBHook) newBatchPoints() (err error) {
// make sure we're only creating new batch points when we don't already have them
if hook.batchP != nil {
return nil
}
hook.batchP, err = influxdb.NewBatchPoints(influxdb.BatchPointsConfig{
Database: hook.database,
Precision: hook.precision,
})
if err != nil {
return err
}
return nil
}
示例15: logStatistic
func logStatistic(p *influx.Point) {
influxBatchPoints.AddPoint(p)
if len(influxBatchPoints.Points()) < conf.InfluxBatchPointsCount {
return
}
if err := influxClient.Write(influxBatchPoints); err != nil {
log.Println("Failed to dump point to influxdb: ", err.Error())
}
influxBatchPoints, _ = influx.NewBatchPoints(
influx.BatchPointsConfig{
Database: conf.InfluxDB,
Precision: "s",
})
}