Skip to content

Commit db22327

Browse files
author
Shukui Yang
committed
Register imagePullThroughput and count with MiB
Signed-off-by: Shukui Yang <[email protected]>
1 parent 988ee8f commit db22327

4 files changed

Lines changed: 30 additions & 13 deletions

File tree

pkg/cri/sbserver/images/image_pull.go

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

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

219220
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/images/metrics.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,30 @@ import (
2424
var (
2525
imagePulls metrics.LabeledCounter
2626
inProgressImagePulls metrics.Gauge
27-
// pull duration / (image size / 1MBi)
27+
// image size in MB / image pull duration in seconds
2828
imagePullThroughput prom.Histogram
2929
)
3030

3131
func init() {
32+
const (
33+
namespace = "containerd"
34+
subsystem = "cri_sandboxed"
35+
)
36+
3237
// these CRI metrics record latencies for successful operations around a sandbox and container's lifecycle.
33-
ns := metrics.NewNamespace("containerd", "cri_sandboxed", nil)
38+
ns := metrics.NewNamespace(namespace, subsystem, nil)
3439

3540
imagePulls = ns.NewLabeledCounter("image_pulls", "succeeded and failed counters", "status")
3641
inProgressImagePulls = ns.NewGauge("in_progress_image_pulls", "in progress pulls", metrics.Total)
3742
imagePullThroughput = prom.NewHistogram(
3843
prom.HistogramOpts{
39-
Name: "image_pulling_throughput",
40-
Help: "image pull throughput",
41-
Buckets: prom.DefBuckets,
44+
Namespace: namespace,
45+
Subsystem: subsystem,
46+
Name: "image_pulling_throughput",
47+
Help: "image pull throughput",
48+
Buckets: prom.DefBuckets,
4249
},
4350
)
44-
51+
ns.Add(imagePullThroughput)
4552
metrics.Register(ns)
4653
}

pkg/cri/server/image_pull.go

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

212+
const mbToByte = 1024 * 1024
212213
size, _ := image.Size(ctx)
213-
imagePullingSpeed := float64(size) / time.Since(startTime).Seconds()
214+
imagePullingSpeed := float64(size) / mbToByte / time.Since(startTime).Seconds()
214215
imagePullThroughput.Observe(imagePullingSpeed)
215216

216217
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)