-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
116 lines (89 loc) · 2.68 KB
/
main_test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
_ "github.com/exporterpush/config"
"github.com/exporterpush/global"
"github.com/exporterpush/internal/model"
"github.com/exporterpush/pkg/prom2json"
"strconv"
"testing"
"time"
)
func clickHouseCalc(metric *prom2json.Family) float64 {
gaugeOrCounter := prom2json.Metric{}
if metric.Type == "GAUGE" || metric.Type == "COUNTER" {
gaugeOrCounter = metric.Metrics[0].(prom2json.Metric)
}
valueInt, _ := strconv.ParseFloat(gaugeOrCounter.Value, 64)
return valueInt
}
func TestFunc(t *testing.T) {
metric := prom2json.GetProm2JsonMapStruct("http://127.0.0.1:9363/metrics")
//clickhouseTcpCon := metric[global.ClickhouseTcpConnection]
//tcp_valueMap, ok := clickhouseTcpCon.Metrics[0].(map[string]string)
//if ok {
// fmt.Printf("interface{} to map ok:%v\n", tcp_valueMap)
//}
//tcp_valueInt, _ := strconv.Atoi(tcp_valueMap["value"])
//tcp_connect := model.Batchs{
// Unit: "count",
// Name: "tcp_connection",
// Value: tcp_valueInt,
//}
clickhouseTcpCon := metric[global.ClickhouseTcpConnection]
tcp_connect := model.Batchs{
Unit: "count",
Name: "tcp_connection",
Value: clickHouseCalc(clickhouseTcpCon),
}
fmt.Printf("tcp conn:%+v\n", tcp_connect)
}
func TestMainFunc(t *testing.T) {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
//Oldmp := map[string]Test{}
//Oldmp["old"] = Test{name: "oldname"}
//fmt.Printf("oldmap info:%+v\n", Oldmp)
//oldtest := &Test{name: "old test"}
Oldmp := map[string]*Test{}
Oldmp["old"] = &Test{name: "oldname"}
fmt.Printf("oldmap info:%+v\n", Oldmp["old"])
count := 0
for {
select {
case <-ticker.C:
//fmt.Printf("befor newmap oldmap info:%+v\n", Oldmp)
//NewMap(&Oldmp, "new-"+strconv.Itoa(count))
//fmt.Printf("after newmap oldmap info:%+v\n", Oldmp)
//fmt.Printf("befor NewTestStrc oldtest info:%+v\n", oldtest)
//NewTestStrc(oldtest, "new-"+strconv.Itoa(count))
//fmt.Printf("after NewTestStrc oldtest info:%+v\n", oldtest)
fmt.Printf("befor NewTestStrcMap oldtest info:%+v\n", Oldmp["old"])
NewTestStrcMap(&Oldmp, "new-"+strconv.Itoa(count))
fmt.Printf("after NewTestStrcMap oldtest info:%+v\n", Oldmp["old"])
count++
if count == 2 {
return
}
}
}
}
type Test struct {
name string
}
func NewMap(oldmap *map[string]Test, names string) {
newmap := map[string]Test{}
newmap["new"] = Test{name: names}
//oldmap = &newmap
(*oldmap)["old"] = newmap["new"]
}
func NewTestStrc(oldtest *Test, names string) {
newtest := &Test{name: names}
*oldtest = *newtest
}
func NewTestStrcMap(oldmap *map[string]*Test, names string) {
newmap := map[string]*Test{}
newmap["new"] = &Test{name: names}
//oldmap = &newmap
(*oldmap)["old"] = newmap["new"]
}