/
perfcounterpack.go
80 lines (71 loc) · 2.05 KB
/
perfcounterpack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package netdata
import (
packconstants "github.com/scouter-contrib/scouter-agent-golang/scouterx/common/constants/packconstant"
)
const TimeTypeRealTime int8 = 1
const TimeTypeFiveMin int8 = 3
//PerfCounterPack has metric counter which has key/value type
type PerfCounterPack struct {
Time int64
ObjName string
Timetype int8
Data *MapValue
}
// NewPerfCounterPack returns PerfCounterPack instance
func NewPerfCounterPack() *PerfCounterPack {
pack := new(PerfCounterPack)
pack.Data = NewMapValue()
return pack
}
// Write will write PerfCounterPack to datoutputx
func (pack *PerfCounterPack) Write(out *DataOutputX) error {
_, err := out.WriteInt64(pack.Time)
_, err = out.WriteString(pack.ObjName)
_, err = out.WriteInt8(pack.Timetype)
_, err = out.WriteValue(pack.Data)
return err
}
// Read will read PerfCounterPack from datainputx
func (pack *PerfCounterPack) Read(in *DataInputX) (Pack, error) {
var err error
pack.Time, err = in.ReadInt64()
pack.ObjName, err = in.ReadString()
pack.Timetype, err = in.ReadInt8()
value, err := in.ReadValue()
pack.Data = value.(*MapValue)
return pack, err
}
// Put will put key/value to PerfCounterPack
func (pack *PerfCounterPack) Put(key string, any interface{}) {
switch v := any.(type) {
case int32:
pack.Data.Put(key, NewDecimalValue(int64(v)))
case int64:
pack.Data.Put(key, NewDecimalValue(int64(v)))
case uint32:
pack.Data.Put(key, NewDecimalValue(int64(v)))
case uint64:
pack.Data.Put(key, NewDecimalValue(int64(v)))
case int:
pack.Data.Put(key, NewDecimalValue(int64(v)))
case float32:
pack.Data.Put(key, NewFloatValue(v))
case float64:
pack.Data.Put(key, NewFloatValue(float32(v)))
case string:
pack.Data.Put(key, NewTextValue(v))
case bool:
pack.Data.Put(key, NewBooleanValue(v))
default:
pack.Data.Put(key, any)
}
}
// ToString returns converted perfcounterpack value
func (pack *PerfCounterPack) ToString() string {
str := pack.Data.ToString()
return str
}
//GetPackType returns pack type
func (pack *PerfCounterPack) GetPackType() byte {
return packconstants.PERFCOUNTER
}