github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/cmd/octsdb/tsdb.go (about) 1 // Copyright (c) 2016 Arista Networks, Inc. 2 // Use of this source code is governed by the Apache License 2.0 3 // that can be found in the COPYING file. 4 5 package main 6 7 import "fmt" 8 9 // DataPoint for OpenTSDB to store. 10 type DataPoint struct { 11 // Metric name. 12 Metric string `json:"metric"` 13 14 // UNIX timestamp with millisecond resolution. 15 Timestamp uint64 `json:"timestamp"` 16 17 // Value of the data point (integer or floating point). 18 Value interface{} `json:"value"` 19 20 // Tags. The host is automatically populated by the OpenTSDBConn. 21 Tags map[string]string `json:"tags"` 22 } 23 24 func (d *DataPoint) String() string { 25 var tags string 26 if len(d.Tags) != 0 { 27 for tag, value := range d.Tags { 28 tags += " " + tag + "=" + value 29 } 30 } 31 return fmt.Sprintf("put %s %d %v%s\n", d.Metric, d.Timestamp/1e9, d.Value, tags) 32 } 33 34 // OpenTSDBConn is a managed connection to an OpenTSDB instance (or cluster). 35 type OpenTSDBConn interface { 36 Put(d *DataPoint) error 37 }