forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiskmetrics.go
216 lines (191 loc) · 7.02 KB
/
diskmetrics.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright (c) 2020-2024. Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"strings"
"github.com/lf-edge/eve/pkg/pillar/base"
)
// ReportDiskPaths Report disk usage for these paths
var ReportDiskPaths = []string{
"/", // overlayfs inside EVE
"/hostfs", // actual IMGx inside EVE
IdentityDirname,
PersistDir,
}
// ReportDirPaths Report directory usage for these paths
var ReportDirPaths = []string{
PersistConfigDir,
PersistStatusDir,
CertificateDirname,
SealedDirName,
ClearDirName,
PersistDebugDir,
PersistInstallerDir,
IngestedDirname,
NewlogDir,
MemoryMonitorOutputDir,
PersistDir + "/containerd", // Old location
PersistDir + "/tmp", // Should not be used by anything
PersistDir + "/log",
PersistDir + "/checkpoint",
PersistDir + "/containerd-system-root",
PersistDir + "/netdump",
PersistDir + "/pubsub-large",
PersistDir + "/reserved",
PersistDir + "/etcd-storage",
PersistDir + "/kcrashes",
PersistDir + "/eve-info",
PersistDir + "/kubelog",
PersistDir + "/kube-save-var-lib",
}
// AppPersistPaths Application-related files live here
// XXX do we need to exclude the ContentTrees used for eve image update?
// If so how do we tell them apart?
var AppPersistPaths = []string{
VolumeEncryptedDirName,
VolumeClearDirName,
DownloaderDir,
VerifierDir,
ContainerdDir,
SnapshotsDirname,
PersistCachePatchEnvelopes,
PersistCachePatchEnvelopesUsage,
}
// DiskMetric holds metrics data per disk
type DiskMetric struct {
DiskPath string
ReadBytes uint64 // Value in Bytes. Number read Bytes.
WriteBytes uint64 // Value in Bytes. Number written Bytes.
ReadCount uint64 // Number of read operations.
WriteCount uint64 // Number of write operations.
TotalBytes uint64 // Value in Bytes. Total number of allotted Bytes for the disk.
UsedBytes uint64 // Value in Bytes. Total number of used Bytes by the disk.
FreeBytes uint64 // Value in Bytes. Total number of free Bytes for the disk.
IsDir bool // Will be true if DiskPath is a mountPath, will false if it's a disk.
}
// Key returns the pubsub Key.
func (status DiskMetric) Key() string {
return PathToKey(status.DiskPath)
}
// LogCreate :
func (status DiskMetric) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.DiskMetricType, status.DiskPath, nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("diskpath", status.DiskPath).
AddField("readbytes-int64", status.ReadBytes).
AddField("writebytes-int64", status.WriteBytes).
AddField("readcount-int64", status.ReadCount).
AddField("writecount-int64", status.WriteCount).
AddField("totalbytes-int64", status.TotalBytes).
AddField("userbytes-int64", status.UsedBytes).
AddField("freebytes-int64", status.FreeBytes).
AddField("isdor", status.IsDir).
Metricf("DiskMetric status create")
}
// LogModify :
func (status DiskMetric) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.DiskMetricType, status.DiskPath, nilUUID, status.LogKey())
if _, ok := old.(DiskMetric); !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of DiskMetric type")
}
logObject.CloneAndAddField("diskpath", status.DiskPath).
AddField("old-readbytes-int64", status.ReadBytes).
AddField("old-writebytes-int64", status.WriteBytes).
AddField("old-readcount-int64", status.ReadCount).
AddField("old-writecount-int64", status.WriteCount).
AddField("totalbytes-int64", status.TotalBytes).
AddField("old-userbytes-int64", status.UsedBytes).
AddField("old-freebytes-int64", status.FreeBytes).
AddField("isdor", status.IsDir).
Metricf("DiskMetric status modify")
}
// LogDelete :
func (status DiskMetric) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.DiskMetricType, status.DiskPath, nilUUID, status.LogKey())
logObject.CloneAndAddField("diskpath", status.DiskPath).
AddField("totalbytes-int64", status.TotalBytes).
AddField("userbytes-int64", status.UsedBytes).
AddField("freebytes-int64", status.FreeBytes).
AddField("isdor", status.IsDir).
Metricf("DiskMetric status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status DiskMetric) LogKey() string {
return string(base.DiskMetricType) + "-" + status.Key()
}
// AppDiskMetric hold metrics data per appInstance volume
type AppDiskMetric struct {
DiskPath string
ProvisionedBytes uint64 // Value in Bytes. Total number of allotted Bytes for the disk.
UsedBytes uint64 // Value in Bytes. Total number of used Bytes by the disk.
DiskType string
Dirty bool
}
// Key returns the pubsub Key.
func (status AppDiskMetric) Key() string {
return PathToKey(status.DiskPath)
}
// LogCreate :
func (status AppDiskMetric) LogCreate(logBase *base.LogObject) {
logObject := base.NewLogObject(logBase, base.AppDiskMetricType, status.DiskPath, nilUUID, status.LogKey())
if logObject == nil {
return
}
logObject.CloneAndAddField("diskpath", status.DiskPath).
AddField("userbytes-int64", status.UsedBytes).
AddField("provisionedbytes-int64", status.ProvisionedBytes).
AddField("disktype", status.DiskType).
AddField("dirty", status.Dirty).
Metricf("AppDiskMetric status create")
}
// LogModify :
func (status AppDiskMetric) LogModify(logBase *base.LogObject, old interface{}) {
logObject := base.EnsureLogObject(logBase, base.AppDiskMetricType, status.DiskPath, nilUUID, status.LogKey())
if _, ok := old.(AppDiskMetric); !ok {
logObject.Clone().Fatalf("LogModify: Old object interface passed is not of AppDiskMetric type")
}
logObject.CloneAndAddField("diskpath", status.DiskPath).
AddField("old-userbytes-int64", status.UsedBytes).
AddField("provisionedbytes-int64", status.ProvisionedBytes).
AddField("disktype", status.DiskType).
AddField("dirty", status.Dirty).
Metricf("AppDiskMetric status modify")
}
// LogDelete :
func (status AppDiskMetric) LogDelete(logBase *base.LogObject) {
logObject := base.EnsureLogObject(logBase, base.AppDiskMetricType, status.DiskPath, nilUUID, status.LogKey())
logObject.CloneAndAddField("diskpath", status.DiskPath).
AddField("provisionedbytes-int64", status.ProvisionedBytes).
AddField("disktype", status.DiskType).
AddField("dirty", status.Dirty).
Metricf("AppDiskMetric status delete")
base.DeleteLogObject(logBase, status.LogKey())
}
// LogKey :
func (status AppDiskMetric) LogKey() string {
return string(base.AppDiskMetricType) + "-" + status.Key()
}
// PathToKey converts /path/to/dir to path-to-dir.
func PathToKey(path string) string {
path = strings.TrimPrefix(path, "/")
key := strings.ReplaceAll(path, "/", "-")
return key
}
// ImgInfo matches the json output of qemu-img info
type ImgInfo struct {
VirtualSize uint64 `json:"virtual-size"`
Filename string `json:"filename"`
ClusterSize uint64 `json:"cluster-size"`
Format string `json:"format"`
ActualSize uint64 `json:"actual-size"`
DirtyFlag bool `json:"dirty-flag"`
}
// UsageStat stores usage information about directory
type UsageStat struct {
Total uint64
Used uint64
Free uint64
}