Skip to content

Commit 711cebd

Browse files
Shukui Yangialidzhikov
authored andcommitted
Register imagePullThroughput and count with MiB
Signed-off-by: Shukui Yang <[email protected]> (cherry picked from commit db22327)
1 parent 825d583 commit 711cebd

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

pkg/cri/sbserver/image_pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
213213
}
214214
}
215215

216+
const mbToByte = 1024 * 1024
216217
size, _ := image.Size(ctx)
217-
imagePullingSpeed := float64(size) / time.Since(startTime).Seconds()
218+
imagePullingSpeed := float64(size) / mbToByte / time.Since(startTime).Seconds()
218219
imagePullThroughput.Observe(imagePullingSpeed)
219220

220221
log.G(ctx).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q, size %q in %s", imageRef, imageID,

pkg/cri/sbserver/metrics.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ var (
4242

4343
imagePulls metrics.LabeledCounter
4444
inProgressImagePulls metrics.Gauge
45-
// pull duration / (image size / 1MBi)
45+
// image size in MB / image pull duration in seconds
4646
imagePullThroughput prom.Histogram
4747
)
4848

4949
func init() {
50+
const (
51+
namespace = "containerd"
52+
subsystem = "cri_sandboxed"
53+
)
54+
5055
// these CRI metrics record latencies for successful operations around a sandbox and container's lifecycle.
51-
ns := metrics.NewNamespace("containerd", "cri_sandboxed", nil)
56+
ns := metrics.NewNamespace(namespace, subsystem, nil)
5257

5358
sandboxListTimer = ns.NewTimer("sandbox_list", "time to list sandboxes")
5459
sandboxCreateNetworkTimer = ns.NewTimer("sandbox_create_network", "time to create the network for a sandbox")
@@ -72,12 +77,14 @@ func init() {
7277
inProgressImagePulls = ns.NewGauge("in_progress_image_pulls", "in progress pulls", metrics.Total)
7378
imagePullThroughput = prom.NewHistogram(
7479
prom.HistogramOpts{
75-
Name: "image_pulling_throughput",
76-
Help: "image pull throughput",
77-
Buckets: prom.DefBuckets,
80+
Namespace: namespace,
81+
Subsystem: subsystem,
82+
Name: "image_pulling_throughput",
83+
Help: "image pull throughput",
84+
Buckets: prom.DefBuckets,
7885
},
7986
)
80-
87+
ns.Add(imagePullThroughput)
8188
metrics.Register(ns)
8289
}
8390

pkg/cri/server/image_pull.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
215215
}
216216
}
217217

218+
const mbToByte = 1024 * 1024
218219
size, _ := image.Size(ctx)
219-
imagePullingSpeed := float64(size) / time.Since(startTime).Seconds()
220+
imagePullingSpeed := float64(size) / mbToByte / time.Since(startTime).Seconds()
220221
imagePullThroughput.Observe(imagePullingSpeed)
221222

222223
log.G(ctx).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q, size %q in %s", imageRef, imageID,

pkg/cri/server/metrics.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ var (
4242

4343
imagePulls metrics.LabeledCounter
4444
inProgressImagePulls metrics.Gauge
45-
// pull duration / (image size / 1MBi)
45+
// image size in MB / image pull duration in seconds
4646
imagePullThroughput prom.Histogram
4747
)
4848

4949
func init() {
50+
const (
51+
namespace = "containerd"
52+
subsystem = "cri"
53+
)
54+
5055
// these CRI metrics record latencies for successful operations around a sandbox and container's lifecycle.
51-
ns := metrics.NewNamespace("containerd", "cri", nil)
56+
ns := metrics.NewNamespace(namespace, subsystem, nil)
5257

5358
sandboxListTimer = ns.NewTimer("sandbox_list", "time to list sandboxes")
5459
sandboxCreateNetworkTimer = ns.NewTimer("sandbox_create_network", "time to create the network for a sandbox")
@@ -72,12 +77,15 @@ func init() {
7277
inProgressImagePulls = ns.NewGauge("in_progress_image_pulls", "in progress pulls", metrics.Total)
7378
imagePullThroughput = prom.NewHistogram(
7479
prom.HistogramOpts{
75-
Name: "image_pulling_throughput",
76-
Help: "image pull throughput",
77-
Buckets: prom.DefBuckets,
80+
Namespace: namespace,
81+
Subsystem: subsystem,
82+
Name: "image_pulling_throughput",
83+
Help: "image pull throughput",
84+
Buckets: prom.DefBuckets,
7885
},
7986
)
8087

88+
ns.Add(imagePullThroughput)
8189
metrics.Register(ns)
8290
}
8391

0 commit comments

Comments
 (0)