tsdb.go 952 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. package main
  5. import "fmt"
  6. // DataPoint for OpenTSDB to store.
  7. type DataPoint struct {
  8. // Metric name.
  9. Metric string `json:"metric"`
  10. // UNIX timestamp with millisecond resolution.
  11. Timestamp uint64 `json:"timestamp"`
  12. // Value of the data point (integer or floating point).
  13. Value interface{} `json:"value"`
  14. // Tags. The host is automatically populated by the OpenTSDBConn.
  15. Tags map[string]string `json:"tags"`
  16. }
  17. func (d *DataPoint) String() string {
  18. var tags string
  19. if len(d.Tags) != 0 {
  20. for tag, value := range d.Tags {
  21. tags += " " + tag + "=" + value
  22. }
  23. }
  24. return fmt.Sprintf("put %s %d %#v%s\n", d.Metric, d.Timestamp/1e9, d.Value, tags)
  25. }
  26. // OpenTSDBConn is a managed connection to an OpenTSDB instance (or cluster).
  27. type OpenTSDBConn interface {
  28. Put(d *DataPoint) error
  29. }