1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ts_points.go 1.68 KB
一键复制 编辑 原始数据 按行查看 历史
Lukasz Gryglicki 提交于 2019-03-18 20:33 +08:00 . Fixing package name and tests
package devstatscode
import (
"fmt"
"time"
)
// TSPoint keeps single time series point
type TSPoint struct {
t time.Time
added time.Time
period string
name string
tags map[string]string
fields map[string]interface{}
}
// TSPoints keeps batch of TSPoint values to write
type TSPoints []TSPoint
// Str - string pretty print
func (p *TSPoint) Str() string {
return fmt.Sprintf(
"%s %s %s period: %s tags: %+v fields: %+v",
ToYMDHDate(p.t),
ToYMDHDate(p.added),
p.name,
p.period,
p.tags,
p.fields,
)
}
// Str - string pretty print
func (ps *TSPoints) Str() string {
s := ""
for i, p := range *ps {
s += fmt.Sprintf("#%d %s\n", i+1, p.Str())
}
return s
}
// NewTSPoint returns new point as specified by args
func NewTSPoint(ctx *Ctx, name, period string, tags map[string]string, fields map[string]interface{}, t time.Time, exact bool) TSPoint {
var (
otags map[string]string
ofields map[string]interface{}
)
if tags != nil {
otags = make(map[string]string)
for k, v := range tags {
otags[k] = v
}
}
if fields != nil {
ofields = make(map[string]interface{})
for k, v := range fields {
ofields[k] = v
}
}
var pt time.Time
if exact {
pt = t
} else {
pt = HourStart(t)
}
p := TSPoint{
t: pt,
added: time.Now(),
name: name,
period: period,
tags: otags,
fields: ofields,
}
if ctx.Debug > 0 {
Printf("NewTSPoint: %s\n", p.Str())
}
return p
}
// AddTSPoint add single point to the batch
func AddTSPoint(ctx *Ctx, pts *TSPoints, pt TSPoint) {
if ctx.Debug > 0 {
Printf("AddTSPoint: %s\n", pt.Str())
}
*pts = append(*pts, pt)
if ctx.Debug > 0 {
Printf("AddTSPoint: point added, now %d points\n", len(*pts))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助