本文整理匯總了Golang中github.com/influxdata/influxdb/client/v2.NewPoint函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewPoint函數的具體用法?Golang NewPoint怎麽用?Golang NewPoint使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewPoint函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
示例2: 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
}
示例3: 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
}
示例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: 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)
}
示例6: Fire
// Fire adds a new InfluxDB point based off of Logrus entry
func (hook *InfluxDBHook) Fire(entry *logrus.Entry) (err error) {
// If passing a "message" field then it will be overridden by the entry Message
entry.Data["message"] = entry.Message
measurement := hook.measurement
if result, ok := getTag(entry.Data, "measurement"); ok {
measurement = result
}
tags := make(map[string]string)
// Set the level of the entry
tags["level"] = entry.Level.String()
// getAndDel and getAndDelRequest are taken from https://github.com/evalphobia/logrus_sentry
if logger, ok := getTag(entry.Data, "logger"); ok {
tags["logger"] = logger
}
for _, tag := range hook.tagList {
if tagValue, ok := getTag(entry.Data, tag); ok {
tags[tag] = tagValue
}
}
pt, err := influxdb.NewPoint(measurement, tags, entry.Data, entry.Time)
if err != nil {
return fmt.Errorf("Fire: %v", err)
}
return hook.addPoint(pt)
}
示例7: influxWriter
func (self *Server) influxWriter(influxClient influxdb.Client, options InfluxOptions) {
defer close(self.influxChan)
defer influxClient.Close()
for stat := range self.influxChan {
tags := map[string]string{
"id": stat.ID.String(),
"family": stat.ID.Family(),
"name": stat.SensorConfig.String(),
}
fields := map[string]interface{}{
"temperature": stat.Temperature.Float64(),
}
// write
point, err := influxdb.NewPoint("onewire", tags, fields, stat.Time)
if err != nil {
log.Printf("server.Server: influxWriter: influxdb.NewPoint: %v\n", err)
}
points, err := options.batchPoints()
if err != nil {
log.Printf("server.Server: influxWriter: newBatchPoints: %v\n", err)
continue
}
points.AddPoint(point)
if err := influxClient.Write(points); err != nil {
log.Printf("server.Server: influxWriter: influxdb.Client %v: Write %v: %v\n", influxClient, points, err)
continue
}
}
}
示例8: Point
// Point stamps out a new influx data point and COPIES the tags, and CLEARS
// the fields for this Capture so that it can be fields with new values.
// The new data point is stamped with the current time.
func (mm *Measurement) Point() (*influx.Point, error) {
tags := mm.tags
fields := mm.fields
mm.tags = make(map[string]string)
mm.fields = make(map[string]interface{})
for k, v := range tags {
mm.tags[k] = v
}
for k, v := range fields {
mm.fields[k] = v
}
pt, err := influx.NewPoint(
mm.measurement,
mm.tags,
mm.fields,
time.Now(),
)
if err != nil {
return nil, err
} else {
return pt, nil
}
}
示例9: 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
}
})
}
}
示例10: NewBlankTestPoint
func NewBlankTestPoint() *influx.Point {
meas := "measurement"
tags := map[string]string{"fooTag": "fooTagValue"}
fields := map[string]interface{}{"value": 5920}
utc, _ := time.LoadLocation("UTC")
timestamp := time.Date(2016, time.Month(4), 20, 0, 0, 0, 0, utc)
pt, _ := influx.NewPoint(meas, tags, fields, timestamp)
return pt
}
示例11: calcDailyBytesServed
func calcDailyBytesServed(client influx.Client, bp influx.BatchPoints, startTime time.Time, endTime time.Time, config StartupConfig) {
bytesToTerabytes := 1000000000.00
sampleTimeSecs := 60.00
bitsTobytes := 8.00
queryString := fmt.Sprintf(`select mean(value) from "monthly"."bandwidth.cdn.1min" where time > '%s' and time < '%s' group by time(1m), cdn`, startTime.Format(time.RFC3339), endTime.Format(time.RFC3339))
log.Infof("queryString = %v\n", queryString)
res, err := queryDB(client, queryString, "cache_stats")
if err != nil {
log.Error("An error occured getting max bandwidth!\n")
return
}
if res != nil && len(res[0].Series) > 0 {
for _, row := range res[0].Series {
bytesServed := float64(0)
cdn := row.Tags["cdn"]
for _, record := range row.Values {
if record[1] != nil {
value, err := record[1].(json.Number).Float64()
if err != nil {
log.Errorf("Couldn't parse value from record %v\n", record)
continue
}
bytesServed += value * sampleTimeSecs / bitsTobytes
}
}
bytesServedTB := bytesServed / bytesToTerabytes
log.Infof("TBytes served for cdn %v = %v", cdn, bytesServedTB)
//write to Traffic Ops
var statsSummary traffic_ops.StatsSummary
statsSummary.CDNName = cdn
statsSummary.DeliveryService = "all"
statsSummary.StatName = "daily_bytesserved"
statsSummary.StatValue = strconv.FormatFloat(bytesServedTB, 'f', 2, 64)
statsSummary.SummaryTime = time.Now().Format(time.RFC3339)
statsSummary.StatDate = startTime.Format("2006-01-02")
go writeSummaryStats(config, statsSummary)
//write to Influxdb
tags := map[string]string{"cdn": cdn, "deliveryservice": "all"}
fields := map[string]interface{}{
"value": bytesServedTB, //converted to TB
}
pt, err := influx.NewPoint(
"daily_bytesserved",
tags,
fields,
startTime,
)
if err != nil {
log.Errorf("error adding creating data point for max Gbps...%v\n", err)
continue
}
bp.AddPoint(pt)
}
config.BpsChan <- bp
}
}
示例12: Point
// Returns a point representation of the report to be written to the ResultsDB
func (qr *queryReport) Point() *influx.Point {
measurement := "testDefault"
tags := map[string]string{}
fields := map[string]interface{}{"field": "blank"}
point, err := influx.NewPoint(measurement, tags, fields, time.Now())
if err != nil {
log.Fatalf("Error creating queryReport point\n measurement: %v\n tags: %v\n fields: %v\n error: %v\n", measurement, tags, fields, err)
}
return point
}
示例13: calcDailyMaxGbps
func calcDailyMaxGbps(client influx.Client, bp influx.BatchPoints, startTime time.Time, endTime time.Time, config StartupConfig) {
kilobitsToGigabits := 1000000.00
queryString := fmt.Sprintf(`select time, cdn, max(value) from "monthly"."bandwidth.cdn.1min" where time > '%s' and time < '%s' group by cdn`, startTime.Format(time.RFC3339), endTime.Format(time.RFC3339))
log.Infof("queryString = %v\n", queryString)
res, err := queryDB(client, queryString, "cache_stats")
if err != nil {
log.Errorf("An error occured getting max bandwidth! %v\n", err)
return
}
if res != nil && len(res[0].Series) > 0 {
for _, row := range res[0].Series {
for _, record := range row.Values {
t := record[0].(string)
if record[1] != nil {
cdn := record[1].(string)
value, err := record[2].(json.Number).Float64()
if err != nil {
log.Errorf("Couldn't parse value from record %v\n", record)
continue
}
value = value / kilobitsToGigabits
statTime, _ := time.Parse(time.RFC3339, t)
log.Infof("max gbps for cdn %v = %v", cdn, value)
var statsSummary traffic_ops.StatsSummary
statsSummary.CDNName = cdn
statsSummary.DeliveryService = "all"
statsSummary.StatName = "daily_maxgbps"
statsSummary.StatValue = strconv.FormatFloat(value, 'f', 2, 64)
statsSummary.SummaryTime = time.Now().Format(time.RFC3339)
statsSummary.StatDate = statTime.Format("2006-01-02")
go writeSummaryStats(config, statsSummary)
//write to influxdb
tags := map[string]string{"cdn": cdn, "deliveryservice": "all"}
fields := map[string]interface{}{
"value": value,
}
pt, err := influx.NewPoint(
"daily_maxgbps",
tags,
fields,
statTime,
)
if err != nil {
fmt.Printf("error adding creating data point for max Gbps...%v\n", err)
continue
}
bp.AddPoint(pt)
}
}
}
}
config.BpsChan <- bp
}
示例14: createPoint
func (g *gauge) createPoint() {
tags := map[string]string{}
for _, tag := range g.tags {
tags[tag.Key] = tag.Value
}
fields := map[string]interface{}{}
for _, field := range g.fields {
fields[field.Key] = field.Value
}
fields["value"] = g.value
pt, _ := stdinflux.NewPoint(g.key, tags, fields, time.Now())
g.bp.AddPoint(pt)
}
示例15: blankResponse
func blankResponse() stressClient.Response {
// Points must have at least one field
fields := map[string]interface{}{"done": true}
// Make a 'blank' point
p, err := influx.NewPoint("done", make(map[string]string), fields, time.Now())
// Panic on error
if err != nil {
log.Fatalf("Error creating blank response point\n error: %v\n", err)
}
// Add a tracer to prevent program from returning too early
tracer := stressClient.NewTracer(make(map[string]string))
// Add to the WaitGroup
tracer.Add(1)
// Make a new response with the point and the tracer
resp := stressClient.NewResponse(p, tracer)
return resp
}