-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
types.go
191 lines (180 loc) · 5.18 KB
/
types.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* This file is part of the KubeVirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2018 Red Hat, Inc.
*/
package stats
// stats Package wraps the libvirt bulk stats data types.
//
// The libvirt.DomainStats type is not a POD type, it includes a pointer to the
// generating libvirt.Domain. But consumers of the virtwrap package should not deal
// with libvirt types directly.
// Furthermore, we need to close gaps about the bulk stats API. We care about memory
// stats, but these aren't yet delivered as bulk stats output; again the client code
// should not worry about this.
// The solution is to handle all the low-level details in the cli subpackage (see its docs).
// Doing so, however, prevents us to add the types and the converter in the canonical places,
// namely the virtwrap main package and the api subpackage, to avoid dependency cycles.
// The cleanest approach to untangle the mess is thus to create a separate subpackage.
//
// We choose to replicate the libvirt structs here, kinda like the rest of the virtwrap
// package tree does, again to be independent with respec to the libvirt data types,
// and to avoid that client code (e.g. anything that uses cmd-client) needs to import it,
// dragging the libvirt dependency in the final binary.
// For versioning of the virt-handler and -launcher communication,
// you need to increase the Version const when making changes,
// and make necessary changes in the cmd rpc implementation!
const (
DomainStatsVersion = "v1"
// VIR_VCPU_OFFLINE = 0, /* the virtual CPU is offline */
VCPUOffline = 0
// VIR_VCPU_RUNNING = 1, /* the virtual CPU is running */
VCPURunning = 1
// VIR_VCPU_BLOCKED = 2, /* the virtual CPU is blocked on resource */
VCPUBlocked = 2
)
type DomainStats struct {
// the following aren't really needed for stats, but it's practical to report
// OTOH, the whole "Domain" is too much data to be unconditionally reported
Name string
UUID string
// omitted from libvirt-go: Domain
// omitted from libvirt-go: State
Cpu *DomainStatsCPU
// new, see below
Memory *DomainStatsMemory
// omitted from libvirt-go: DomainJobInfo
MigrateDomainJobInfo *DomainJobInfo
// omitted from libvirt-go: Balloon
Vcpu []DomainStatsVcpu
Net []DomainStatsNet
Block []DomainStatsBlock
// omitted from libvirt-go: Perf
// extra stats
CPUMapSet bool
CPUMap [][]bool
NrVirtCpu uint
}
type DomainStatsCPU struct {
TimeSet bool
Time uint64
UserSet bool
User uint64
SystemSet bool
System uint64
}
type DomainStatsVcpu struct {
StateSet bool
State int // VcpuState
TimeSet bool
Time uint64
WaitSet bool
Wait uint64
DelaySet bool
Delay uint64
}
type DomainStatsNet struct {
NameSet bool
Name string
AliasSet bool
Alias string
RxBytesSet bool
RxBytes uint64
RxPktsSet bool
RxPkts uint64
RxErrsSet bool
RxErrs uint64
RxDropSet bool
RxDrop uint64
TxBytesSet bool
TxBytes uint64
TxPktsSet bool
TxPkts uint64
TxErrsSet bool
TxErrs uint64
TxDropSet bool
TxDrop uint64
}
type DomainStatsBlock struct {
NameSet bool
Name string
Alias string
BackingIndexSet bool
BackingIndex uint
PathSet bool
Path string
RdReqsSet bool
RdReqs uint64
RdBytesSet bool
RdBytes uint64
RdTimesSet bool
RdTimes uint64
WrReqsSet bool
WrReqs uint64
WrBytesSet bool
WrBytes uint64
WrTimesSet bool
WrTimes uint64
FlReqsSet bool
FlReqs uint64
FlTimesSet bool
FlTimes uint64
ErrorsSet bool
Errors uint64
AllocationSet bool
Allocation uint64
CapacitySet bool
Capacity uint64
PhysicalSet bool
Physical uint64
}
// mimic existing structs, but data is taken from
// DomainMemoryStat
type DomainStatsMemory struct {
UnusedSet bool
Unused uint64
CachedSet bool
Cached uint64
AvailableSet bool
Available uint64
ActualBalloonSet bool
ActualBalloon uint64
RSSSet bool
RSS uint64
SwapInSet bool
SwapIn uint64
SwapOutSet bool
SwapOut uint64
MajorFaultSet bool
MajorFault uint64
MinorFaultSet bool
MinorFault uint64
UsableSet bool
Usable uint64
TotalSet bool
Total uint64
}
// mimic existing structs, but data is taken from
// DomainJobInfo
type DomainJobInfo struct {
DataProcessedSet bool
DataProcessed uint64
MemoryBpsSet bool
MemoryBps uint64
DataRemainingSet bool
DataRemaining uint64
MemDirtyRateSet bool
MemDirtyRate uint64
}