tsdb

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

百度TSDB GO SDK

Bce-tsdb-go

License codebeat badge Go Report Card GoDoc Build Status Coverage Status

百度时序数据库基本操作,API文档参考官方

安装

go get github.com/colakuma/bce-tsdb-go

许可证

这个项目是在Apache许可证下进行的。请参阅完整许可证文本的许可证文件。

功能

  • WriteDatapoint: 写入data point
  • ListMetric: 获取metric列表
  • ListFieldByMetric: 获取field列表
  • ListTagByMetric: 获取tag列表
  • ListDatapointByQuery: 查询data point
  • ListRowBySql: 基于sql查询row
  • GeneratePresignedUrl: 生成查询URL

例子

  1. 创建客户端
import "github.com/colakuma/bce-tsdb-go"

func main() {
	// 创建TSDB服务的Client对象
	AK, SK := <your-access-key-id>, <your-secret-access-key>
	// 指明使用HTTPS协议
	ENDPOINT := "https://xxxxx.tsdb.iot.bj.baidubce.com"
	cli, err := tsdb.NewClient(AK, SK,ENDPOINT)
}
  1. 写入数据
err = cli.WriteDatapoint([]Datapoint{{
	Metric: "cpu_idle",
	Tags: Tags{
		"host": "server1",
		"rack": "rack1",
	},
	Value: 51,
}})

Documentation

Index

Constants

View Source
const (
	URI_DATAPOINT = "/v1/datapoint"
	URI_TAG       = "/v1/metric/%s/tag"
	URI_FIELD     = "/v1/metric/%s/field"
	URI_METRIC    = "/v1/metric"
	URI_ROW_SQL   = "/v1/row"
)
View Source
const (
	Long   ValueType = "Long"
	Double           = "Double"
	String           = "String"
	Bytes            = "Bytes"
	Number           = "Number"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregator

type Aggregator struct {
	Name       string  `json:"name"`
	Sampling   string  `json:"sampling,omitempty"`
	Percentile float64 `json:"percentile,omitempty"`
	Divisor    float64 `json:"divisor,omitempty"`
	Factor     float64 `json:"factor,omitempty"`
	TimeUnit   string  `json:"timeUnit,omitempty"`
}

type Client

type Client struct {
	*bce.BceClient
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ak, sk, endpoint string) (*Client, error)

func NewClientWithConfig added in v0.1.2

func NewClientWithConfig(c *Config) (*Client, error)

func NewClientWithDB

func NewClientWithDB(ak, sk, endpoint, database string) (*Client, error)

func (*Client) GeneratePresignedUrl

func (c *Client) GeneratePresignedUrl(query Queries, expireSeconds int, endpoint ...string) (string, error)

func (*Client) ListDatapointByQuery

func (c *Client) ListDatapointByQuery(query Queries, disablePresampling ...bool) ([]QueryResult, error)

func (*Client) ListFieldByMetric

func (c *Client) ListFieldByMetric(metric string) (map[string]Field, error)

func (*Client) ListMetric

func (c *Client) ListMetric() ([]string, error)

func (*Client) ListRowBySql

func (c *Client) ListRowBySql(statement string) (*RowResult, error)

func (*Client) ListTagByMetric

func (c *Client) ListTagByMetric(metric string) (map[string]TagValues, error)

func (*Client) WriteDatapoint

func (c *Client) WriteDatapoint(data []Datapoint) error

type Column

type Column struct {
	Name string `json:"name"`
}

type Config added in v0.1.2

type Config struct {
	Endpoint string
	AK       string
	SK       string
	Database string
	ProxyUrl string
}

type Datapoint

type Datapoint struct {
	Metric    string          `json:"metric"`
	Field     string          `json:"field,omitempty"`
	Tags      Tags            `json:"tags"`
	Type      ValueType       `json:"type,omitempty"`
	Timestamp int64           `json:"timestamp,omitempty"`
	Value     interface{}     `json:"value,omitempty"`
	Values    [][]interface{} `json:"values,omitempty"`
}

type Field

type Field struct {
	Type ValueType `json:"fields"`
}

type FieldFilter

type FieldFilter struct {
	Field string `json:"field"`
	Value string `json:"value"`
}

type Fill

type Fill struct {
	Name             string `json:"type"`
	Interval         string `json:"interval"`
	MaxWriteInterval string `json:"maxWriteInterval,omitempty"`
}

type Filter

type Filter struct {
	Start  interface{}          `json:"start"`
	End    interface{}          `json:"end,omitempty"`
	Tags   map[string]TagValues `json:"tags,omitempty"`
	Value  string               `json:"value,omitempty"`
	Fields []FieldFilter        `json:"fields,omitempty"`
	Or     []Filter             `json:"or,omitempty"`
}

type Group

type Group struct {
	GroupInfos []GroupInfo `json:"groupInfos"`
	Values     []Value     `json:"values"`
}

type GroupBy

type GroupBy struct {
	Name string   `json:"name"`
	Tags []string `json:"tags,omitempty"`
}

type GroupInfo

type GroupInfo struct {
	Name string               `json:"name"`
	Tags map[string]TagValues `json:"tags"`
}

type ListDatapointArgs

type ListDatapointArgs struct {
	Queries            Queries `json:"queries"`
	DisablePresampling bool    `json:"disablePresampling,omitempty"`
}

type ListDatapointResult

type ListDatapointResult struct {
	Results []QueryResult `json:"results"`
}

type ListFieldResult

type ListFieldResult struct {
	Fields map[string]Field `json:"fields"`
}

type ListMetricsResult

type ListMetricsResult struct {
	Metrics []string `json:"metrics"`
}

type ListTagsResult

type ListTagsResult struct {
	Tags map[string]TagValues `json:"tags"`
}

type Queries

type Queries []Query

type Query

type Query struct {
	Metric      string       `json:"metric"`
	Field       string       `json:"field,omitempty"`
	Fields      []string     `json:"fields,omitempty"`
	Tags        []string     `json:"tags,omitempty"`
	Filters     Filter       `json:"filters"`
	GroupBy     []GroupBy    `json:"groupBy,omitempty"`
	Limit       int          `json:"limit,omitempty"`
	Aggregators []Aggregator `json:"aggregators,omitempty"`
	Order       string       `json:"order,omitempty"`
	Fill        *Fill        `json:"fill,omitempty"`
	Fills       []Fill       `json:"fills,omitempty"`
	Marker      string       `json:"marker,omitempty"`
}

type QueryResult

type QueryResult struct {
	Metric            string   `json:"metric"`
	Field             string   `json:"field"`
	Fields            []string `json:"fields"`
	Tags              []string `json:"tags"`
	RawCount          int      `json:"rawCount"`
	Groups            []Group  `json:"groups"`
	Truncated         bool     `json:"truncated"`
	NextMarker        string   `json:"nextMarker"`
	PresamplingRuleId string   `json:"presamplingRuleId"`
}

type Row added in v0.1.2

type Row []interface{}

type RowResult

type RowResult struct {
	Columns []Column `json:"columns"`
	Rows    []Row    `json:"rows"`
}

type TagFilter

type TagFilter struct {
	Tag   string   `json:"tag"`
	In    []string `json:"in"`
	NotIn []string `json:"notIn"`
	Like  string   `json:"like"`
}

type TagValues

type TagValues []string

type Tags

type Tags map[string]string

type Value

type Value []interface{}

func (Value) Tag

func (v Value) Tag(i int) interface{}

func (Value) Timestamp

func (v Value) Timestamp() int64

func (Value) Value

func (v Value) Value() interface{}

type ValueType

type ValueType string

type WriteDataPointArgs

type WriteDataPointArgs struct {
	DataPoints []Datapoint `json:"datapoints"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL