61 Star 341 Fork 416

infraboard / go-course

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
model.go 1.59 KB
Copy Edit Raw Blame History
Mr.Yu authored 2022-08-05 19:06 . 补充script_exporter
package collector
import (
"encoding/json"
"strconv"
)
type RocketMQMetric struct {
Group string
Count string
Version string
Type string
Model string
TPS string
DiffTotal string
}
func (m *RocketMQMetric) IntCount() float64 {
i, _ := strconv.ParseFloat(m.Count, 64)
return i
}
func (m *RocketMQMetric) IntTPS() float64 {
i, _ := strconv.ParseFloat(m.TPS, 64)
return i
}
func (m *RocketMQMetric) IntDiffTotal() float64 {
i, _ := strconv.ParseFloat(m.DiffTotal, 64)
return i
}
func (m *RocketMQMetric) String() string {
v, err := json.Marshal(m)
if err != nil {
panic(err)
}
return string(v)
}
func NewRocketMQMetricSet() *RocketMQMetricSet {
return &RocketMQMetricSet{
Items: []*RocketMQMetric{},
}
}
type RocketMQMetricSet struct {
Items []*RocketMQMetric
}
func (s *RocketMQMetricSet) Add(item *RocketMQMetric) {
s.Items = append(s.Items, item)
}
func (s *RocketMQMetricSet) String() string {
v, err := json.Marshal(s)
if err != nil {
panic(err)
}
return string(v)
}
func ParseLine(line string) *RocketMQMetric {
words := []string{}
chars := []rune{}
for _, c := range line {
if c == ' ' {
if len(chars) > 0 {
words = append(words, string(chars))
}
chars = []rune{}
} else {
chars = append(chars, c)
}
}
if len(chars) > 0 {
words = append(words, string(chars))
}
m := &RocketMQMetric{
Group: words[0],
Count: words[1],
Version: words[2],
Type: words[3],
}
if len(words) <= 6 {
m.TPS = words[4]
m.DiffTotal = words[5]
} else {
m.Model = words[4]
m.TPS = words[5]
m.DiffTotal = words[6]
}
return m
}
Go
1
https://gitee.com/infraboard/go-course.git
git@gitee.com:infraboard/go-course.git
infraboard
go-course
go-course
d5aecf891a93

Search