Skip to content

Commit

Permalink
Register imagePullThroughput and count with MiB
Browse files Browse the repository at this point in the history
Signed-off-by: Shukui Yang <yangshukui@bytedance.com>
(cherry picked from commit db22327)
  • Loading branch information
Shukui Yang authored and ialidzhikov committed Feb 26, 2024
1 parent 825d583 commit 711cebd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion pkg/cri/sbserver/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
}
}

const mbToByte = 1024 * 1024
size, _ := image.Size(ctx)
imagePullingSpeed := float64(size) / time.Since(startTime).Seconds()
imagePullingSpeed := float64(size) / mbToByte / time.Since(startTime).Seconds()
imagePullThroughput.Observe(imagePullingSpeed)

log.G(ctx).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q, size %q in %s", imageRef, imageID,
Expand Down
19 changes: 13 additions & 6 deletions pkg/cri/sbserver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ var (

imagePulls metrics.LabeledCounter
inProgressImagePulls metrics.Gauge
// pull duration / (image size / 1MBi)
// image size in MB / image pull duration in seconds
imagePullThroughput prom.Histogram
)

func init() {
const (
namespace = "containerd"
subsystem = "cri_sandboxed"
)

// these CRI metrics record latencies for successful operations around a sandbox and container's lifecycle.
ns := metrics.NewNamespace("containerd", "cri_sandboxed", nil)
ns := metrics.NewNamespace(namespace, subsystem, nil)

sandboxListTimer = ns.NewTimer("sandbox_list", "time to list sandboxes")
sandboxCreateNetworkTimer = ns.NewTimer("sandbox_create_network", "time to create the network for a sandbox")
Expand All @@ -72,12 +77,14 @@ func init() {
inProgressImagePulls = ns.NewGauge("in_progress_image_pulls", "in progress pulls", metrics.Total)
imagePullThroughput = prom.NewHistogram(
prom.HistogramOpts{
Name: "image_pulling_throughput",
Help: "image pull throughput",
Buckets: prom.DefBuckets,
Namespace: namespace,
Subsystem: subsystem,
Name: "image_pulling_throughput",
Help: "image pull throughput",
Buckets: prom.DefBuckets,
},
)

ns.Add(imagePullThroughput)
metrics.Register(ns)
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/cri/server/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ func (c *criService) PullImage(ctx context.Context, r *runtime.PullImageRequest)
}
}

const mbToByte = 1024 * 1024
size, _ := image.Size(ctx)
imagePullingSpeed := float64(size) / time.Since(startTime).Seconds()
imagePullingSpeed := float64(size) / mbToByte / time.Since(startTime).Seconds()
imagePullThroughput.Observe(imagePullingSpeed)

log.G(ctx).Infof("Pulled image %q with image id %q, repo tag %q, repo digest %q, size %q in %s", imageRef, imageID,
Expand Down
18 changes: 13 additions & 5 deletions pkg/cri/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ var (

imagePulls metrics.LabeledCounter
inProgressImagePulls metrics.Gauge
// pull duration / (image size / 1MBi)
// image size in MB / image pull duration in seconds
imagePullThroughput prom.Histogram
)

func init() {
const (
namespace = "containerd"
subsystem = "cri"
)

// these CRI metrics record latencies for successful operations around a sandbox and container's lifecycle.
ns := metrics.NewNamespace("containerd", "cri", nil)
ns := metrics.NewNamespace(namespace, subsystem, nil)

sandboxListTimer = ns.NewTimer("sandbox_list", "time to list sandboxes")
sandboxCreateNetworkTimer = ns.NewTimer("sandbox_create_network", "time to create the network for a sandbox")
Expand All @@ -72,12 +77,15 @@ func init() {
inProgressImagePulls = ns.NewGauge("in_progress_image_pulls", "in progress pulls", metrics.Total)
imagePullThroughput = prom.NewHistogram(
prom.HistogramOpts{
Name: "image_pulling_throughput",
Help: "image pull throughput",
Buckets: prom.DefBuckets,
Namespace: namespace,
Subsystem: subsystem,
Name: "image_pulling_throughput",
Help: "image pull throughput",
Buckets: prom.DefBuckets,
},
)

ns.Add(imagePullThroughput)
metrics.Register(ns)
}

Expand Down

0 comments on commit 711cebd

Please sign in to comment.