1 Star 0 Fork 0

zhuchance/kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
types.go 2.60 KB
一键复制 编辑 原始数据 按行查看 历史
package metrics
import (
"encoding/json"
"fmt"
// "time"
)
// MetricType restrictions
type MetricType int
const (
Gauge = iota
Availability
Counter
Generic
)
var longForm = []string{
"gauges",
"availability",
"counters",
"metrics",
}
var shortForm = []string{
"gauge",
"availability",
"counter",
"metrics",
}
func (self MetricType) validate() error {
if int(self) > len(longForm) && int(self) > len(shortForm) {
return fmt.Errorf("Given MetricType value %d is not valid", self)
}
return nil
}
func (self MetricType) String() string {
if err := self.validate(); err != nil {
return "unknown"
}
return longForm[self]
}
func (self MetricType) shortForm() string {
if err := self.validate(); err != nil {
return "unknown"
}
return shortForm[self]
}
// Custom unmarshaller
func (self *MetricType) UnmarshalJSON(b []byte) error {
var f interface{}
err := json.Unmarshal(b, &f)
if err != nil {
return err
}
if str, ok := f.(string); ok {
for i, v := range shortForm {
if str == v {
*self = MetricType(i)
break
}
}
}
return nil
}
func (self MetricType) MarshalJSON() ([]byte, error) {
return json.Marshal(self.String())
}
type SortKey struct {
Tenant string
Type MetricType
}
// Hawkular-Metrics external structs
// Do I need external.. hmph.
type MetricHeader struct {
Tenant string `json:"-"`
Type MetricType `json:"-"`
Id string `json:"id"`
Data []Datapoint `json:"data"`
}
// Value should be convertible to float64 for numeric values
// Timestamp is milliseconds since epoch
type Datapoint struct {
Timestamp int64 `json:"timestamp"`
Value interface{} `json:"value"`
Tags map[string]string `json:"tags,omitempty"`
}
type HawkularError struct {
ErrorMsg string `json:"errorMsg"`
}
type MetricDefinition struct {
Tenant string `json:"-"`
Type MetricType `json:"type,omitempty"`
Id string `json:"id"`
Tags map[string]string `json:"tags,omitempty"`
RetentionTime int `json:"dataRetention,omitempty"`
}
// TODO Fix the Start & End to return a time.Time
type Bucketpoint struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Avg float64 `json:"avg"`
Median float64 `json:"median"`
Empty bool `json:"empty"`
Samples int64 `json:"samples"`
Percentiles []Percentile `json:"percentiles"`
}
type Percentile struct {
Quantile float64 `json:"quantile"`
Value float64 `json:"value"`
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.2.0-beta.0

搜索帮助

Cb406eda 1850385 E526c682 1850385