-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
fakeCollector.go
66 lines (52 loc) · 1.54 KB
/
fakeCollector.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
package prometheus
import (
"github.com/prometheus/client_golang/prometheus"
libvirt "libvirt.org/libvirt-go"
k6tv1 "kubevirt.io/client-go/api/v1"
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/stats"
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/statsconv"
"kubevirt.io/kubevirt/pkg/virt-launcher/virtwrap/statsconv/util"
)
type fakeCollector struct {
}
func (fc fakeCollector) Describe(_ chan<- *prometheus.Desc) {
}
//Collect needs to report all metrics to see it in docs
func (fc fakeCollector) Collect(ch chan<- prometheus.Metric) {
ps := prometheusScraper{ch: ch}
libstatst, err := util.LoadStats()
if err != nil {
panic(err)
}
in := &libstatst[0]
inMem := []libvirt.DomainMemoryStat{}
out := stats.DomainStats{}
ident := statsconv.DomainIdentifier(&fakeIdentifier{})
if err = statsconv.Convert_libvirt_DomainStats_to_stats_DomainStats(ident, in, inMem, &out); err != nil {
panic(err)
}
out.Memory.ActualBalloonSet = true
out.Memory.UnusedSet = true
out.Memory.AvailableSet = true
out.Memory.RSSSet = true
out.Memory.SwapInSet = true
out.CPUMapSet = true
vmi := k6tv1.VirtualMachineInstance{
Status: k6tv1.VirtualMachineInstanceStatus{
Phase: k6tv1.Running,
},
}
ps.Report("test", &vmi, &out)
updateVMIsPhase("test", []*k6tv1.VirtualMachineInstance{&vmi}, ch)
}
type fakeIdentifier struct {
}
func (*fakeIdentifier) GetName() (string, error) {
return "test", nil
}
func (*fakeIdentifier) GetUUIDString() (string, error) {
return "uuid", nil
}
func RegisterFakeCollector() {
prometheus.MustRegister(fakeCollector{})
}