Debian Codegraph @

semconv/v1.40.0/containerconv/metric.go

raw
1 // Code generated from semantic convention specification. DO NOT EDIT.
2
3 // Copyright The OpenTelemetry Authors
4 // SPDX-License-Identifier: Apache-2.0
5
6 // Package containerconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "container" namespace.
8 package containerconv
9
10 import (
11 "context"
12 "sync"
13
14 "go.opentelemetry.io/otel/attribute"
15 "go.opentelemetry.io/otel/metric"
16 "go.opentelemetry.io/otel/metric/noop"
17 )
18
19 var (
20 addOptPool = &sync.Pool{New: func() any { return &[]metric.AddOption{} }}
21 recOptPool = &sync.Pool{New: func() any { return &[]metric.RecordOption{} }}
22 )
23
24 // CPUModeAttr is an attribute conforming to the cpu.mode semantic conventions.
25 // It represents the CPU mode for this data point. A container's CPU metric
26 // SHOULD be characterized *either* by data points with no `mode` labels,
27 // *or only* data points with `mode` labels.
28 type CPUModeAttr string
29
30 var (
31 // CPUModeUser is the user.
32 CPUModeUser CPUModeAttr = "user"
33 // CPUModeSystem is the system.
34 CPUModeSystem CPUModeAttr = "system"
35 // CPUModeNice is the nice.
36 CPUModeNice CPUModeAttr = "nice"
37 // CPUModeIdle is the idle.
38 CPUModeIdle CPUModeAttr = "idle"
39 // CPUModeIOWait is the IO Wait.
40 CPUModeIOWait CPUModeAttr = "iowait"
41 // CPUModeInterrupt is the interrupt.
42 CPUModeInterrupt CPUModeAttr = "interrupt"
43 // CPUModeSteal is the steal.
44 CPUModeSteal CPUModeAttr = "steal"
45 // CPUModeKernel is the kernel.
46 CPUModeKernel CPUModeAttr = "kernel"
47 )
48
49 // DiskIODirectionAttr is an attribute conforming to the disk.io.direction
50 // semantic conventions. It represents the disk IO operation direction.
51 type DiskIODirectionAttr string
52
53 var (
54 // DiskIODirectionRead is the standardized value "read" of DiskIODirectionAttr.
55 DiskIODirectionRead DiskIODirectionAttr = "read"
56 // DiskIODirectionWrite is the standardized value "write" of
57 // DiskIODirectionAttr.
58 DiskIODirectionWrite DiskIODirectionAttr = "write"
59 )
60
61 // NetworkIODirectionAttr is an attribute conforming to the network.io.direction
62 // semantic conventions. It represents the network IO operation direction.
63 type NetworkIODirectionAttr string
64
65 var (
66 // NetworkIODirectionTransmit is the standardized value "transmit" of
67 // NetworkIODirectionAttr.
68 NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
69 // NetworkIODirectionReceive is the standardized value "receive" of
70 // NetworkIODirectionAttr.
71 NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
72 )
73
74 // SystemPagingFaultTypeAttr is an attribute conforming to the
75 // system.paging.fault.type semantic conventions. It represents the paging fault
76 // type.
77 type SystemPagingFaultTypeAttr string
78
79 var (
80 // SystemPagingFaultTypeMajor is the standardized value "major" of
81 // SystemPagingFaultTypeAttr.
82 SystemPagingFaultTypeMajor SystemPagingFaultTypeAttr = "major"
83 // SystemPagingFaultTypeMinor is the standardized value "minor" of
84 // SystemPagingFaultTypeAttr.
85 SystemPagingFaultTypeMinor SystemPagingFaultTypeAttr = "minor"
86 )
87
88 // CPUTime is an instrument used to record metric values conforming to the
89 // "container.cpu.time" semantic conventions. It represents the total CPU time
90 // consumed.
91 type CPUTime struct {
92 metric.Float64Counter
93 }
94
95 var newCPUTimeOpts = []metric.Float64CounterOption{
96 metric.WithDescription("Total CPU time consumed."),
97 metric.WithUnit("s"),
98 }
99
100 // NewCPUTime returns a new CPUTime instrument.
101 func NewCPUTime(
102 m metric.Meter,
103 opt ...metric.Float64CounterOption,
104 ) (CPUTime, error) {
105 // Check if the meter is nil.
106 if m == nil {
107 return CPUTime{noop.Float64Counter{}}, nil
108 }
109
110 if len(opt) == 0 {
111 opt = newCPUTimeOpts
112 } else {
113 opt = append(opt, newCPUTimeOpts...)
114 }
115
116 i, err := m.Float64Counter(
117 "container.cpu.time",
118 opt...,
119 )
120 if err != nil {
121 return CPUTime{noop.Float64Counter{}}, err
122 }
123 return CPUTime{i}, nil
124 }
125
126 // Inst returns the underlying metric instrument.
127 func (m CPUTime) Inst() metric.Float64Counter {
128 return m.Float64Counter
129 }
130
131 // Name returns the semantic convention name of the instrument.
132 func (CPUTime) Name() string {
133 return "container.cpu.time"
134 }
135
136 // Unit returns the semantic convention unit of the instrument
137 func (CPUTime) Unit() string {
138 return "s"
139 }
140
141 // Description returns the semantic convention description of the instrument
142 func (CPUTime) Description() string {
143 return "Total CPU time consumed."
144 }
145
146 // Add adds incr to the existing count for attrs.
147 //
148 // All additional attrs passed are included in the recorded value.
149 //
150 // Total CPU time consumed by the specific container on all available CPU cores
151 func (m CPUTime) Add(
152 ctx context.Context,
153 incr float64,
154 attrs ...attribute.KeyValue,
155 ) {
156 if len(attrs) == 0 {
157 m.Float64Counter.Add(ctx, incr)
158 return
159 }
160
161 o := addOptPool.Get().(*[]metric.AddOption)
162 defer func() {
163 *o = (*o)[:0]
164 addOptPool.Put(o)
165 }()
166
167 *o = append(
168 *o,
169 metric.WithAttributes(
170 attrs...,
171 ),
172 )
173
174 m.Float64Counter.Add(ctx, incr, *o...)
175 }
176
177 // AddSet adds incr to the existing count for set.
178 //
179 // Total CPU time consumed by the specific container on all available CPU cores
180 func (m CPUTime) AddSet(ctx context.Context, incr float64, set attribute.Set) {
181 if set.Len() == 0 {
182 m.Float64Counter.Add(ctx, incr)
183 return
184 }
185
186 o := addOptPool.Get().(*[]metric.AddOption)
187 defer func() {
188 *o = (*o)[:0]
189 addOptPool.Put(o)
190 }()
191
192 *o = append(*o, metric.WithAttributeSet(set))
193 m.Float64Counter.Add(ctx, incr, *o...)
194 }
195
196 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
197 // convention. It represents the CPU mode for this data point. A container's CPU
198 // metric SHOULD be characterized *either* by data points with no `mode` labels,
199 // *or only* data points with `mode` labels.
200 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
201 return attribute.String("cpu.mode", string(val))
202 }
203
204 // CPUUsage is an instrument used to record metric values conforming to the
205 // "container.cpu.usage" semantic conventions. It represents the container's CPU
206 // usage, measured in cpus. Range from 0 to the number of allocatable CPUs.
207 type CPUUsage struct {
208 metric.Int64Gauge
209 }
210
211 var newCPUUsageOpts = []metric.Int64GaugeOption{
212 metric.WithDescription("Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs."),
213 metric.WithUnit("{cpu}"),
214 }
215
216 // NewCPUUsage returns a new CPUUsage instrument.
217 func NewCPUUsage(
218 m metric.Meter,
219 opt ...metric.Int64GaugeOption,
220 ) (CPUUsage, error) {
221 // Check if the meter is nil.
222 if m == nil {
223 return CPUUsage{noop.Int64Gauge{}}, nil
224 }
225
226 if len(opt) == 0 {
227 opt = newCPUUsageOpts
228 } else {
229 opt = append(opt, newCPUUsageOpts...)
230 }
231
232 i, err := m.Int64Gauge(
233 "container.cpu.usage",
234 opt...,
235 )
236 if err != nil {
237 return CPUUsage{noop.Int64Gauge{}}, err
238 }
239 return CPUUsage{i}, nil
240 }
241
242 // Inst returns the underlying metric instrument.
243 func (m CPUUsage) Inst() metric.Int64Gauge {
244 return m.Int64Gauge
245 }
246
247 // Name returns the semantic convention name of the instrument.
248 func (CPUUsage) Name() string {
249 return "container.cpu.usage"
250 }
251
252 // Unit returns the semantic convention unit of the instrument
253 func (CPUUsage) Unit() string {
254 return "{cpu}"
255 }
256
257 // Description returns the semantic convention description of the instrument
258 func (CPUUsage) Description() string {
259 return "Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs."
260 }
261
262 // Record records val to the current distribution for attrs.
263 //
264 // All additional attrs passed are included in the recorded value.
265 //
266 // CPU usage of the specific container on all available CPU cores, averaged over
267 // the sample window
268 func (m CPUUsage) Record(
269 ctx context.Context,
270 val int64,
271 attrs ...attribute.KeyValue,
272 ) {
273 if len(attrs) == 0 {
274 m.Int64Gauge.Record(ctx, val)
275 return
276 }
277
278 o := recOptPool.Get().(*[]metric.RecordOption)
279 defer func() {
280 *o = (*o)[:0]
281 recOptPool.Put(o)
282 }()
283
284 *o = append(
285 *o,
286 metric.WithAttributes(
287 attrs...,
288 ),
289 )
290
291 m.Int64Gauge.Record(ctx, val, *o...)
292 }
293
294 // RecordSet records val to the current distribution for set.
295 //
296 // CPU usage of the specific container on all available CPU cores, averaged over
297 // the sample window
298 func (m CPUUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) {
299 if set.Len() == 0 {
300 m.Int64Gauge.Record(ctx, val)
301 return
302 }
303
304 o := recOptPool.Get().(*[]metric.RecordOption)
305 defer func() {
306 *o = (*o)[:0]
307 recOptPool.Put(o)
308 }()
309
310 *o = append(*o, metric.WithAttributeSet(set))
311 m.Int64Gauge.Record(ctx, val, *o...)
312 }
313
314 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
315 // convention. It represents the CPU mode for this data point. A container's CPU
316 // metric SHOULD be characterized *either* by data points with no `mode` labels,
317 // *or only* data points with `mode` labels.
318 func (CPUUsage) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
319 return attribute.String("cpu.mode", string(val))
320 }
321
322 // DiskIO is an instrument used to record metric values conforming to the
323 // "container.disk.io" semantic conventions. It represents the disk bytes for the
324 // container.
325 type DiskIO struct {
326 metric.Int64Counter
327 }
328
329 var newDiskIOOpts = []metric.Int64CounterOption{
330 metric.WithDescription("Disk bytes for the container."),
331 metric.WithUnit("By"),
332 }
333
334 // NewDiskIO returns a new DiskIO instrument.
335 func NewDiskIO(
336 m metric.Meter,
337 opt ...metric.Int64CounterOption,
338 ) (DiskIO, error) {
339 // Check if the meter is nil.
340 if m == nil {
341 return DiskIO{noop.Int64Counter{}}, nil
342 }
343
344 if len(opt) == 0 {
345 opt = newDiskIOOpts
346 } else {
347 opt = append(opt, newDiskIOOpts...)
348 }
349
350 i, err := m.Int64Counter(
351 "container.disk.io",
352 opt...,
353 )
354 if err != nil {
355 return DiskIO{noop.Int64Counter{}}, err
356 }
357 return DiskIO{i}, nil
358 }
359
360 // Inst returns the underlying metric instrument.
361 func (m DiskIO) Inst() metric.Int64Counter {
362 return m.Int64Counter
363 }
364
365 // Name returns the semantic convention name of the instrument.
366 func (DiskIO) Name() string {
367 return "container.disk.io"
368 }
369
370 // Unit returns the semantic convention unit of the instrument
371 func (DiskIO) Unit() string {
372 return "By"
373 }
374
375 // Description returns the semantic convention description of the instrument
376 func (DiskIO) Description() string {
377 return "Disk bytes for the container."
378 }
379
380 // Add adds incr to the existing count for attrs.
381 //
382 // All additional attrs passed are included in the recorded value.
383 //
384 // The total number of bytes read/written successfully (aggregated from all
385 // disks).
386 func (m DiskIO) Add(
387 ctx context.Context,
388 incr int64,
389 attrs ...attribute.KeyValue,
390 ) {
391 if len(attrs) == 0 {
392 m.Int64Counter.Add(ctx, incr)
393 return
394 }
395
396 o := addOptPool.Get().(*[]metric.AddOption)
397 defer func() {
398 *o = (*o)[:0]
399 addOptPool.Put(o)
400 }()
401
402 *o = append(
403 *o,
404 metric.WithAttributes(
405 attrs...,
406 ),
407 )
408
409 m.Int64Counter.Add(ctx, incr, *o...)
410 }
411
412 // AddSet adds incr to the existing count for set.
413 //
414 // The total number of bytes read/written successfully (aggregated from all
415 // disks).
416 func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
417 if set.Len() == 0 {
418 m.Int64Counter.Add(ctx, incr)
419 return
420 }
421
422 o := addOptPool.Get().(*[]metric.AddOption)
423 defer func() {
424 *o = (*o)[:0]
425 addOptPool.Put(o)
426 }()
427
428 *o = append(*o, metric.WithAttributeSet(set))
429 m.Int64Counter.Add(ctx, incr, *o...)
430 }
431
432 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
433 // semantic convention. It represents the disk IO operation direction.
434 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
435 return attribute.String("disk.io.direction", string(val))
436 }
437
438 // AttrSystemDevice returns an optional attribute for the "system.device"
439 // semantic convention. It represents the device identifier.
440 func (DiskIO) AttrSystemDevice(val string) attribute.KeyValue {
441 return attribute.String("system.device", val)
442 }
443
444 // FilesystemAvailable is an instrument used to record metric values conforming
445 // to the "container.filesystem.available" semantic conventions. It represents
446 // the container filesystem available bytes.
447 type FilesystemAvailable struct {
448 metric.Int64UpDownCounter
449 }
450
451 var newFilesystemAvailableOpts = []metric.Int64UpDownCounterOption{
452 metric.WithDescription("Container filesystem available bytes."),
453 metric.WithUnit("By"),
454 }
455
456 // NewFilesystemAvailable returns a new FilesystemAvailable instrument.
457 func NewFilesystemAvailable(
458 m metric.Meter,
459 opt ...metric.Int64UpDownCounterOption,
460 ) (FilesystemAvailable, error) {
461 // Check if the meter is nil.
462 if m == nil {
463 return FilesystemAvailable{noop.Int64UpDownCounter{}}, nil
464 }
465
466 if len(opt) == 0 {
467 opt = newFilesystemAvailableOpts
468 } else {
469 opt = append(opt, newFilesystemAvailableOpts...)
470 }
471
472 i, err := m.Int64UpDownCounter(
473 "container.filesystem.available",
474 opt...,
475 )
476 if err != nil {
477 return FilesystemAvailable{noop.Int64UpDownCounter{}}, err
478 }
479 return FilesystemAvailable{i}, nil
480 }
481
482 // Inst returns the underlying metric instrument.
483 func (m FilesystemAvailable) Inst() metric.Int64UpDownCounter {
484 return m.Int64UpDownCounter
485 }
486
487 // Name returns the semantic convention name of the instrument.
488 func (FilesystemAvailable) Name() string {
489 return "container.filesystem.available"
490 }
491
492 // Unit returns the semantic convention unit of the instrument
493 func (FilesystemAvailable) Unit() string {
494 return "By"
495 }
496
497 // Description returns the semantic convention description of the instrument
498 func (FilesystemAvailable) Description() string {
499 return "Container filesystem available bytes."
500 }
501
502 // Add adds incr to the existing count for attrs.
503 //
504 // In K8s, this metric is derived from the
505 // [FsStats.AvailableBytes] field
506 // of the [ContainerStats.Rootfs]
507 // of the Kubelet's stats API.
508 //
509 // [FsStats.AvailableBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
510 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
511 func (m FilesystemAvailable) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
512 if len(attrs) == 0 {
513 m.Int64UpDownCounter.Add(ctx, incr)
514 return
515 }
516
517 o := addOptPool.Get().(*[]metric.AddOption)
518 defer func() {
519 *o = (*o)[:0]
520 addOptPool.Put(o)
521 }()
522
523 *o = append(*o, metric.WithAttributes(attrs...))
524 m.Int64UpDownCounter.Add(ctx, incr, *o...)
525 }
526
527 // AddSet adds incr to the existing count for set.
528 //
529 // In K8s, this metric is derived from the
530 // [FsStats.AvailableBytes] field
531 // of the [ContainerStats.Rootfs]
532 // of the Kubelet's stats API.
533 //
534 // [FsStats.AvailableBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
535 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
536 func (m FilesystemAvailable) AddSet(ctx context.Context, incr int64, set attribute.Set) {
537 if set.Len() == 0 {
538 m.Int64UpDownCounter.Add(ctx, incr)
539 return
540 }
541
542 o := addOptPool.Get().(*[]metric.AddOption)
543 defer func() {
544 *o = (*o)[:0]
545 addOptPool.Put(o)
546 }()
547
548 *o = append(*o, metric.WithAttributeSet(set))
549 m.Int64UpDownCounter.Add(ctx, incr, *o...)
550 }
551
552 // FilesystemCapacity is an instrument used to record metric values conforming to
553 // the "container.filesystem.capacity" semantic conventions. It represents the
554 // container filesystem capacity.
555 type FilesystemCapacity struct {
556 metric.Int64UpDownCounter
557 }
558
559 var newFilesystemCapacityOpts = []metric.Int64UpDownCounterOption{
560 metric.WithDescription("Container filesystem capacity."),
561 metric.WithUnit("By"),
562 }
563
564 // NewFilesystemCapacity returns a new FilesystemCapacity instrument.
565 func NewFilesystemCapacity(
566 m metric.Meter,
567 opt ...metric.Int64UpDownCounterOption,
568 ) (FilesystemCapacity, error) {
569 // Check if the meter is nil.
570 if m == nil {
571 return FilesystemCapacity{noop.Int64UpDownCounter{}}, nil
572 }
573
574 if len(opt) == 0 {
575 opt = newFilesystemCapacityOpts
576 } else {
577 opt = append(opt, newFilesystemCapacityOpts...)
578 }
579
580 i, err := m.Int64UpDownCounter(
581 "container.filesystem.capacity",
582 opt...,
583 )
584 if err != nil {
585 return FilesystemCapacity{noop.Int64UpDownCounter{}}, err
586 }
587 return FilesystemCapacity{i}, nil
588 }
589
590 // Inst returns the underlying metric instrument.
591 func (m FilesystemCapacity) Inst() metric.Int64UpDownCounter {
592 return m.Int64UpDownCounter
593 }
594
595 // Name returns the semantic convention name of the instrument.
596 func (FilesystemCapacity) Name() string {
597 return "container.filesystem.capacity"
598 }
599
600 // Unit returns the semantic convention unit of the instrument
601 func (FilesystemCapacity) Unit() string {
602 return "By"
603 }
604
605 // Description returns the semantic convention description of the instrument
606 func (FilesystemCapacity) Description() string {
607 return "Container filesystem capacity."
608 }
609
610 // Add adds incr to the existing count for attrs.
611 //
612 // In K8s, this metric is derived from the
613 // [FsStats.CapacityBytes] field
614 // of the [ContainerStats.Rootfs]
615 // of the Kubelet's stats API.
616 //
617 // [FsStats.CapacityBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
618 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
619 func (m FilesystemCapacity) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
620 if len(attrs) == 0 {
621 m.Int64UpDownCounter.Add(ctx, incr)
622 return
623 }
624
625 o := addOptPool.Get().(*[]metric.AddOption)
626 defer func() {
627 *o = (*o)[:0]
628 addOptPool.Put(o)
629 }()
630
631 *o = append(*o, metric.WithAttributes(attrs...))
632 m.Int64UpDownCounter.Add(ctx, incr, *o...)
633 }
634
635 // AddSet adds incr to the existing count for set.
636 //
637 // In K8s, this metric is derived from the
638 // [FsStats.CapacityBytes] field
639 // of the [ContainerStats.Rootfs]
640 // of the Kubelet's stats API.
641 //
642 // [FsStats.CapacityBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
643 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
644 func (m FilesystemCapacity) AddSet(ctx context.Context, incr int64, set attribute.Set) {
645 if set.Len() == 0 {
646 m.Int64UpDownCounter.Add(ctx, incr)
647 return
648 }
649
650 o := addOptPool.Get().(*[]metric.AddOption)
651 defer func() {
652 *o = (*o)[:0]
653 addOptPool.Put(o)
654 }()
655
656 *o = append(*o, metric.WithAttributeSet(set))
657 m.Int64UpDownCounter.Add(ctx, incr, *o...)
658 }
659
660 // FilesystemUsage is an instrument used to record metric values conforming to
661 // the "container.filesystem.usage" semantic conventions. It represents the
662 // container filesystem usage.
663 type FilesystemUsage struct {
664 metric.Int64UpDownCounter
665 }
666
667 var newFilesystemUsageOpts = []metric.Int64UpDownCounterOption{
668 metric.WithDescription("Container filesystem usage."),
669 metric.WithUnit("By"),
670 }
671
672 // NewFilesystemUsage returns a new FilesystemUsage instrument.
673 func NewFilesystemUsage(
674 m metric.Meter,
675 opt ...metric.Int64UpDownCounterOption,
676 ) (FilesystemUsage, error) {
677 // Check if the meter is nil.
678 if m == nil {
679 return FilesystemUsage{noop.Int64UpDownCounter{}}, nil
680 }
681
682 if len(opt) == 0 {
683 opt = newFilesystemUsageOpts
684 } else {
685 opt = append(opt, newFilesystemUsageOpts...)
686 }
687
688 i, err := m.Int64UpDownCounter(
689 "container.filesystem.usage",
690 opt...,
691 )
692 if err != nil {
693 return FilesystemUsage{noop.Int64UpDownCounter{}}, err
694 }
695 return FilesystemUsage{i}, nil
696 }
697
698 // Inst returns the underlying metric instrument.
699 func (m FilesystemUsage) Inst() metric.Int64UpDownCounter {
700 return m.Int64UpDownCounter
701 }
702
703 // Name returns the semantic convention name of the instrument.
704 func (FilesystemUsage) Name() string {
705 return "container.filesystem.usage"
706 }
707
708 // Unit returns the semantic convention unit of the instrument
709 func (FilesystemUsage) Unit() string {
710 return "By"
711 }
712
713 // Description returns the semantic convention description of the instrument
714 func (FilesystemUsage) Description() string {
715 return "Container filesystem usage."
716 }
717
718 // Add adds incr to the existing count for attrs.
719 //
720 // This may not equal capacity - available.
721 //
722 // In K8s, this metric is derived from the
723 // [FsStats.UsedBytes] field
724 // of the [ContainerStats.Rootfs]
725 // of the Kubelet's stats API.
726 //
727 // [FsStats.UsedBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
728 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
729 func (m FilesystemUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
730 if len(attrs) == 0 {
731 m.Int64UpDownCounter.Add(ctx, incr)
732 return
733 }
734
735 o := addOptPool.Get().(*[]metric.AddOption)
736 defer func() {
737 *o = (*o)[:0]
738 addOptPool.Put(o)
739 }()
740
741 *o = append(*o, metric.WithAttributes(attrs...))
742 m.Int64UpDownCounter.Add(ctx, incr, *o...)
743 }
744
745 // AddSet adds incr to the existing count for set.
746 //
747 // This may not equal capacity - available.
748 //
749 // In K8s, this metric is derived from the
750 // [FsStats.UsedBytes] field
751 // of the [ContainerStats.Rootfs]
752 // of the Kubelet's stats API.
753 //
754 // [FsStats.UsedBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
755 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
756 func (m FilesystemUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
757 if set.Len() == 0 {
758 m.Int64UpDownCounter.Add(ctx, incr)
759 return
760 }
761
762 o := addOptPool.Get().(*[]metric.AddOption)
763 defer func() {
764 *o = (*o)[:0]
765 addOptPool.Put(o)
766 }()
767
768 *o = append(*o, metric.WithAttributeSet(set))
769 m.Int64UpDownCounter.Add(ctx, incr, *o...)
770 }
771
772 // MemoryAvailable is an instrument used to record metric values conforming to
773 // the "container.memory.available" semantic conventions. It represents the
774 // container memory available.
775 type MemoryAvailable struct {
776 metric.Int64UpDownCounter
777 }
778
779 var newMemoryAvailableOpts = []metric.Int64UpDownCounterOption{
780 metric.WithDescription("Container memory available."),
781 metric.WithUnit("By"),
782 }
783
784 // NewMemoryAvailable returns a new MemoryAvailable instrument.
785 func NewMemoryAvailable(
786 m metric.Meter,
787 opt ...metric.Int64UpDownCounterOption,
788 ) (MemoryAvailable, error) {
789 // Check if the meter is nil.
790 if m == nil {
791 return MemoryAvailable{noop.Int64UpDownCounter{}}, nil
792 }
793
794 if len(opt) == 0 {
795 opt = newMemoryAvailableOpts
796 } else {
797 opt = append(opt, newMemoryAvailableOpts...)
798 }
799
800 i, err := m.Int64UpDownCounter(
801 "container.memory.available",
802 opt...,
803 )
804 if err != nil {
805 return MemoryAvailable{noop.Int64UpDownCounter{}}, err
806 }
807 return MemoryAvailable{i}, nil
808 }
809
810 // Inst returns the underlying metric instrument.
811 func (m MemoryAvailable) Inst() metric.Int64UpDownCounter {
812 return m.Int64UpDownCounter
813 }
814
815 // Name returns the semantic convention name of the instrument.
816 func (MemoryAvailable) Name() string {
817 return "container.memory.available"
818 }
819
820 // Unit returns the semantic convention unit of the instrument
821 func (MemoryAvailable) Unit() string {
822 return "By"
823 }
824
825 // Description returns the semantic convention description of the instrument
826 func (MemoryAvailable) Description() string {
827 return "Container memory available."
828 }
829
830 // Add adds incr to the existing count for attrs.
831 //
832 // Available memory for use. This is defined as the memory limit -
833 // workingSetBytes. If memory limit is undefined, the available bytes is omitted.
834 // In general, this metric can be derived from [cadvisor] and by subtracting the
835 // `container_memory_working_set_bytes` metric from the
836 // `container_spec_memory_limit_bytes` metric.
837 // In K8s, this metric is derived from the [MemoryStats.AvailableBytes] field of
838 // the [PodStats.Memory] of the Kubelet's stats API.
839 //
840 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
841 // [MemoryStats.AvailableBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
842 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
843 func (m MemoryAvailable) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
844 if len(attrs) == 0 {
845 m.Int64UpDownCounter.Add(ctx, incr)
846 return
847 }
848
849 o := addOptPool.Get().(*[]metric.AddOption)
850 defer func() {
851 *o = (*o)[:0]
852 addOptPool.Put(o)
853 }()
854
855 *o = append(*o, metric.WithAttributes(attrs...))
856 m.Int64UpDownCounter.Add(ctx, incr, *o...)
857 }
858
859 // AddSet adds incr to the existing count for set.
860 //
861 // Available memory for use. This is defined as the memory limit -
862 // workingSetBytes. If memory limit is undefined, the available bytes is omitted.
863 // In general, this metric can be derived from [cadvisor] and by subtracting the
864 // `container_memory_working_set_bytes` metric from the
865 // `container_spec_memory_limit_bytes` metric.
866 // In K8s, this metric is derived from the [MemoryStats.AvailableBytes] field of
867 // the [PodStats.Memory] of the Kubelet's stats API.
868 //
869 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
870 // [MemoryStats.AvailableBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
871 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
872 func (m MemoryAvailable) AddSet(ctx context.Context, incr int64, set attribute.Set) {
873 if set.Len() == 0 {
874 m.Int64UpDownCounter.Add(ctx, incr)
875 return
876 }
877
878 o := addOptPool.Get().(*[]metric.AddOption)
879 defer func() {
880 *o = (*o)[:0]
881 addOptPool.Put(o)
882 }()
883
884 *o = append(*o, metric.WithAttributeSet(set))
885 m.Int64UpDownCounter.Add(ctx, incr, *o...)
886 }
887
888 // MemoryPagingFaults is an instrument used to record metric values conforming to
889 // the "container.memory.paging.faults" semantic conventions. It represents the
890 // container memory paging faults.
891 type MemoryPagingFaults struct {
892 metric.Int64Counter
893 }
894
895 var newMemoryPagingFaultsOpts = []metric.Int64CounterOption{
896 metric.WithDescription("Container memory paging faults."),
897 metric.WithUnit("{fault}"),
898 }
899
900 // NewMemoryPagingFaults returns a new MemoryPagingFaults instrument.
901 func NewMemoryPagingFaults(
902 m metric.Meter,
903 opt ...metric.Int64CounterOption,
904 ) (MemoryPagingFaults, error) {
905 // Check if the meter is nil.
906 if m == nil {
907 return MemoryPagingFaults{noop.Int64Counter{}}, nil
908 }
909
910 if len(opt) == 0 {
911 opt = newMemoryPagingFaultsOpts
912 } else {
913 opt = append(opt, newMemoryPagingFaultsOpts...)
914 }
915
916 i, err := m.Int64Counter(
917 "container.memory.paging.faults",
918 opt...,
919 )
920 if err != nil {
921 return MemoryPagingFaults{noop.Int64Counter{}}, err
922 }
923 return MemoryPagingFaults{i}, nil
924 }
925
926 // Inst returns the underlying metric instrument.
927 func (m MemoryPagingFaults) Inst() metric.Int64Counter {
928 return m.Int64Counter
929 }
930
931 // Name returns the semantic convention name of the instrument.
932 func (MemoryPagingFaults) Name() string {
933 return "container.memory.paging.faults"
934 }
935
936 // Unit returns the semantic convention unit of the instrument
937 func (MemoryPagingFaults) Unit() string {
938 return "{fault}"
939 }
940
941 // Description returns the semantic convention description of the instrument
942 func (MemoryPagingFaults) Description() string {
943 return "Container memory paging faults."
944 }
945
946 // Add adds incr to the existing count for attrs.
947 //
948 // All additional attrs passed are included in the recorded value.
949 //
950 // In general, this metric can be derived from [cadvisor] and specifically the
951 // `container_memory_failures_total{failure_type=pgfault, scope=container}` and
952 // `container_memory_failures_total{failure_type=pgmajfault, scope=container}`
953 // metric.
954 // In K8s, this metric is derived from the [MemoryStats.PageFaults] and
955 // [MemoryStats.MajorPageFaults] field of the [PodStats.Memory] of the Kubelet's
956 // stats API.
957 //
958 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
959 // [MemoryStats.PageFaults]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
960 // [MemoryStats.MajorPageFaults]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
961 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
962 func (m MemoryPagingFaults) Add(
963 ctx context.Context,
964 incr int64,
965 attrs ...attribute.KeyValue,
966 ) {
967 if len(attrs) == 0 {
968 m.Int64Counter.Add(ctx, incr)
969 return
970 }
971
972 o := addOptPool.Get().(*[]metric.AddOption)
973 defer func() {
974 *o = (*o)[:0]
975 addOptPool.Put(o)
976 }()
977
978 *o = append(
979 *o,
980 metric.WithAttributes(
981 attrs...,
982 ),
983 )
984
985 m.Int64Counter.Add(ctx, incr, *o...)
986 }
987
988 // AddSet adds incr to the existing count for set.
989 //
990 // In general, this metric can be derived from [cadvisor] and specifically the
991 // `container_memory_failures_total{failure_type=pgfault, scope=container}` and
992 // `container_memory_failures_total{failure_type=pgmajfault, scope=container}`
993 // metric.
994 // In K8s, this metric is derived from the [MemoryStats.PageFaults] and
995 // [MemoryStats.MajorPageFaults] field of the [PodStats.Memory] of the Kubelet's
996 // stats API.
997 //
998 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
999 // [MemoryStats.PageFaults]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
1000 // [MemoryStats.MajorPageFaults]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
1001 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
1002 func (m MemoryPagingFaults) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1003 if set.Len() == 0 {
1004 m.Int64Counter.Add(ctx, incr)
1005 return
1006 }
1007
1008 o := addOptPool.Get().(*[]metric.AddOption)
1009 defer func() {
1010 *o = (*o)[:0]
1011 addOptPool.Put(o)
1012 }()
1013
1014 *o = append(*o, metric.WithAttributeSet(set))
1015 m.Int64Counter.Add(ctx, incr, *o...)
1016 }
1017
1018 // AttrSystemPagingFaultType returns an optional attribute for the
1019 // "system.paging.fault.type" semantic convention. It represents the paging fault
1020 // type.
1021 func (MemoryPagingFaults) AttrSystemPagingFaultType(val SystemPagingFaultTypeAttr) attribute.KeyValue {
1022 return attribute.String("system.paging.fault.type", string(val))
1023 }
1024
1025 // MemoryRss is an instrument used to record metric values conforming to the
1026 // "container.memory.rss" semantic conventions. It represents the container
1027 // memory RSS.
1028 type MemoryRss struct {
1029 metric.Int64UpDownCounter
1030 }
1031
1032 var newMemoryRssOpts = []metric.Int64UpDownCounterOption{
1033 metric.WithDescription("Container memory RSS."),
1034 metric.WithUnit("By"),
1035 }
1036
1037 // NewMemoryRss returns a new MemoryRss instrument.
1038 func NewMemoryRss(
1039 m metric.Meter,
1040 opt ...metric.Int64UpDownCounterOption,
1041 ) (MemoryRss, error) {
1042 // Check if the meter is nil.
1043 if m == nil {
1044 return MemoryRss{noop.Int64UpDownCounter{}}, nil
1045 }
1046
1047 if len(opt) == 0 {
1048 opt = newMemoryRssOpts
1049 } else {
1050 opt = append(opt, newMemoryRssOpts...)
1051 }
1052
1053 i, err := m.Int64UpDownCounter(
1054 "container.memory.rss",
1055 opt...,
1056 )
1057 if err != nil {
1058 return MemoryRss{noop.Int64UpDownCounter{}}, err
1059 }
1060 return MemoryRss{i}, nil
1061 }
1062
1063 // Inst returns the underlying metric instrument.
1064 func (m MemoryRss) Inst() metric.Int64UpDownCounter {
1065 return m.Int64UpDownCounter
1066 }
1067
1068 // Name returns the semantic convention name of the instrument.
1069 func (MemoryRss) Name() string {
1070 return "container.memory.rss"
1071 }
1072
1073 // Unit returns the semantic convention unit of the instrument
1074 func (MemoryRss) Unit() string {
1075 return "By"
1076 }
1077
1078 // Description returns the semantic convention description of the instrument
1079 func (MemoryRss) Description() string {
1080 return "Container memory RSS."
1081 }
1082
1083 // Add adds incr to the existing count for attrs.
1084 //
1085 // In general, this metric can be derived from [cadvisor] and specifically the
1086 // `container_memory_rss` metric.
1087 // In K8s, this metric is derived from the [MemoryStats.RSSBytes] field of the
1088 // [PodStats.Memory] of the Kubelet's stats API.
1089 //
1090 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
1091 // [MemoryStats.RSSBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
1092 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
1093 func (m MemoryRss) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1094 if len(attrs) == 0 {
1095 m.Int64UpDownCounter.Add(ctx, incr)
1096 return
1097 }
1098
1099 o := addOptPool.Get().(*[]metric.AddOption)
1100 defer func() {
1101 *o = (*o)[:0]
1102 addOptPool.Put(o)
1103 }()
1104
1105 *o = append(*o, metric.WithAttributes(attrs...))
1106 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1107 }
1108
1109 // AddSet adds incr to the existing count for set.
1110 //
1111 // In general, this metric can be derived from [cadvisor] and specifically the
1112 // `container_memory_rss` metric.
1113 // In K8s, this metric is derived from the [MemoryStats.RSSBytes] field of the
1114 // [PodStats.Memory] of the Kubelet's stats API.
1115 //
1116 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
1117 // [MemoryStats.RSSBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
1118 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
1119 func (m MemoryRss) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1120 if set.Len() == 0 {
1121 m.Int64UpDownCounter.Add(ctx, incr)
1122 return
1123 }
1124
1125 o := addOptPool.Get().(*[]metric.AddOption)
1126 defer func() {
1127 *o = (*o)[:0]
1128 addOptPool.Put(o)
1129 }()
1130
1131 *o = append(*o, metric.WithAttributeSet(set))
1132 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1133 }
1134
1135 // MemoryUsage is an instrument used to record metric values conforming to the
1136 // "container.memory.usage" semantic conventions. It represents the memory usage
1137 // of the container.
1138 type MemoryUsage struct {
1139 metric.Int64Counter
1140 }
1141
1142 var newMemoryUsageOpts = []metric.Int64CounterOption{
1143 metric.WithDescription("Memory usage of the container."),
1144 metric.WithUnit("By"),
1145 }
1146
1147 // NewMemoryUsage returns a new MemoryUsage instrument.
1148 func NewMemoryUsage(
1149 m metric.Meter,
1150 opt ...metric.Int64CounterOption,
1151 ) (MemoryUsage, error) {
1152 // Check if the meter is nil.
1153 if m == nil {
1154 return MemoryUsage{noop.Int64Counter{}}, nil
1155 }
1156
1157 if len(opt) == 0 {
1158 opt = newMemoryUsageOpts
1159 } else {
1160 opt = append(opt, newMemoryUsageOpts...)
1161 }
1162
1163 i, err := m.Int64Counter(
1164 "container.memory.usage",
1165 opt...,
1166 )
1167 if err != nil {
1168 return MemoryUsage{noop.Int64Counter{}}, err
1169 }
1170 return MemoryUsage{i}, nil
1171 }
1172
1173 // Inst returns the underlying metric instrument.
1174 func (m MemoryUsage) Inst() metric.Int64Counter {
1175 return m.Int64Counter
1176 }
1177
1178 // Name returns the semantic convention name of the instrument.
1179 func (MemoryUsage) Name() string {
1180 return "container.memory.usage"
1181 }
1182
1183 // Unit returns the semantic convention unit of the instrument
1184 func (MemoryUsage) Unit() string {
1185 return "By"
1186 }
1187
1188 // Description returns the semantic convention description of the instrument
1189 func (MemoryUsage) Description() string {
1190 return "Memory usage of the container."
1191 }
1192
1193 // Add adds incr to the existing count for attrs.
1194 //
1195 // Memory usage of the container.
1196 func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1197 if len(attrs) == 0 {
1198 m.Int64Counter.Add(ctx, incr)
1199 return
1200 }
1201
1202 o := addOptPool.Get().(*[]metric.AddOption)
1203 defer func() {
1204 *o = (*o)[:0]
1205 addOptPool.Put(o)
1206 }()
1207
1208 *o = append(*o, metric.WithAttributes(attrs...))
1209 m.Int64Counter.Add(ctx, incr, *o...)
1210 }
1211
1212 // AddSet adds incr to the existing count for set.
1213 //
1214 // Memory usage of the container.
1215 func (m MemoryUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1216 if set.Len() == 0 {
1217 m.Int64Counter.Add(ctx, incr)
1218 return
1219 }
1220
1221 o := addOptPool.Get().(*[]metric.AddOption)
1222 defer func() {
1223 *o = (*o)[:0]
1224 addOptPool.Put(o)
1225 }()
1226
1227 *o = append(*o, metric.WithAttributeSet(set))
1228 m.Int64Counter.Add(ctx, incr, *o...)
1229 }
1230
1231 // MemoryWorkingSet is an instrument used to record metric values conforming to
1232 // the "container.memory.working_set" semantic conventions. It represents the
1233 // container memory working set.
1234 type MemoryWorkingSet struct {
1235 metric.Int64UpDownCounter
1236 }
1237
1238 var newMemoryWorkingSetOpts = []metric.Int64UpDownCounterOption{
1239 metric.WithDescription("Container memory working set."),
1240 metric.WithUnit("By"),
1241 }
1242
1243 // NewMemoryWorkingSet returns a new MemoryWorkingSet instrument.
1244 func NewMemoryWorkingSet(
1245 m metric.Meter,
1246 opt ...metric.Int64UpDownCounterOption,
1247 ) (MemoryWorkingSet, error) {
1248 // Check if the meter is nil.
1249 if m == nil {
1250 return MemoryWorkingSet{noop.Int64UpDownCounter{}}, nil
1251 }
1252
1253 if len(opt) == 0 {
1254 opt = newMemoryWorkingSetOpts
1255 } else {
1256 opt = append(opt, newMemoryWorkingSetOpts...)
1257 }
1258
1259 i, err := m.Int64UpDownCounter(
1260 "container.memory.working_set",
1261 opt...,
1262 )
1263 if err != nil {
1264 return MemoryWorkingSet{noop.Int64UpDownCounter{}}, err
1265 }
1266 return MemoryWorkingSet{i}, nil
1267 }
1268
1269 // Inst returns the underlying metric instrument.
1270 func (m MemoryWorkingSet) Inst() metric.Int64UpDownCounter {
1271 return m.Int64UpDownCounter
1272 }
1273
1274 // Name returns the semantic convention name of the instrument.
1275 func (MemoryWorkingSet) Name() string {
1276 return "container.memory.working_set"
1277 }
1278
1279 // Unit returns the semantic convention unit of the instrument
1280 func (MemoryWorkingSet) Unit() string {
1281 return "By"
1282 }
1283
1284 // Description returns the semantic convention description of the instrument
1285 func (MemoryWorkingSet) Description() string {
1286 return "Container memory working set."
1287 }
1288
1289 // Add adds incr to the existing count for attrs.
1290 //
1291 // In general, this metric can be derived from [cadvisor] and specifically the
1292 // `container_memory_working_set_bytes` metric.
1293 // In K8s, this metric is derived from the [MemoryStats.WorkingSetBytes] field of
1294 // the [PodStats.Memory] of the Kubelet's stats API.
1295 //
1296 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
1297 // [MemoryStats.WorkingSetBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
1298 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
1299 func (m MemoryWorkingSet) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1300 if len(attrs) == 0 {
1301 m.Int64UpDownCounter.Add(ctx, incr)
1302 return
1303 }
1304
1305 o := addOptPool.Get().(*[]metric.AddOption)
1306 defer func() {
1307 *o = (*o)[:0]
1308 addOptPool.Put(o)
1309 }()
1310
1311 *o = append(*o, metric.WithAttributes(attrs...))
1312 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1313 }
1314
1315 // AddSet adds incr to the existing count for set.
1316 //
1317 // In general, this metric can be derived from [cadvisor] and specifically the
1318 // `container_memory_working_set_bytes` metric.
1319 // In K8s, this metric is derived from the [MemoryStats.WorkingSetBytes] field of
1320 // the [PodStats.Memory] of the Kubelet's stats API.
1321 //
1322 // [cadvisor]: https://github.com/google/cadvisor/blob/v0.53.0/docs/storage/prometheus.md#prometheus-container-metrics
1323 // [MemoryStats.WorkingSetBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#MemoryStats
1324 // [PodStats.Memory]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#PodStats
1325 func (m MemoryWorkingSet) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1326 if set.Len() == 0 {
1327 m.Int64UpDownCounter.Add(ctx, incr)
1328 return
1329 }
1330
1331 o := addOptPool.Get().(*[]metric.AddOption)
1332 defer func() {
1333 *o = (*o)[:0]
1334 addOptPool.Put(o)
1335 }()
1336
1337 *o = append(*o, metric.WithAttributeSet(set))
1338 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1339 }
1340
1341 // NetworkIO is an instrument used to record metric values conforming to the
1342 // "container.network.io" semantic conventions. It represents the network bytes
1343 // for the container.
1344 type NetworkIO struct {
1345 metric.Int64Counter
1346 }
1347
1348 var newNetworkIOOpts = []metric.Int64CounterOption{
1349 metric.WithDescription("Network bytes for the container."),
1350 metric.WithUnit("By"),
1351 }
1352
1353 // NewNetworkIO returns a new NetworkIO instrument.
1354 func NewNetworkIO(
1355 m metric.Meter,
1356 opt ...metric.Int64CounterOption,
1357 ) (NetworkIO, error) {
1358 // Check if the meter is nil.
1359 if m == nil {
1360 return NetworkIO{noop.Int64Counter{}}, nil
1361 }
1362
1363 if len(opt) == 0 {
1364 opt = newNetworkIOOpts
1365 } else {
1366 opt = append(opt, newNetworkIOOpts...)
1367 }
1368
1369 i, err := m.Int64Counter(
1370 "container.network.io",
1371 opt...,
1372 )
1373 if err != nil {
1374 return NetworkIO{noop.Int64Counter{}}, err
1375 }
1376 return NetworkIO{i}, nil
1377 }
1378
1379 // Inst returns the underlying metric instrument.
1380 func (m NetworkIO) Inst() metric.Int64Counter {
1381 return m.Int64Counter
1382 }
1383
1384 // Name returns the semantic convention name of the instrument.
1385 func (NetworkIO) Name() string {
1386 return "container.network.io"
1387 }
1388
1389 // Unit returns the semantic convention unit of the instrument
1390 func (NetworkIO) Unit() string {
1391 return "By"
1392 }
1393
1394 // Description returns the semantic convention description of the instrument
1395 func (NetworkIO) Description() string {
1396 return "Network bytes for the container."
1397 }
1398
1399 // Add adds incr to the existing count for attrs.
1400 //
1401 // All additional attrs passed are included in the recorded value.
1402 //
1403 // The number of bytes sent/received on all network interfaces by the container.
1404 func (m NetworkIO) Add(
1405 ctx context.Context,
1406 incr int64,
1407 attrs ...attribute.KeyValue,
1408 ) {
1409 if len(attrs) == 0 {
1410 m.Int64Counter.Add(ctx, incr)
1411 return
1412 }
1413
1414 o := addOptPool.Get().(*[]metric.AddOption)
1415 defer func() {
1416 *o = (*o)[:0]
1417 addOptPool.Put(o)
1418 }()
1419
1420 *o = append(
1421 *o,
1422 metric.WithAttributes(
1423 attrs...,
1424 ),
1425 )
1426
1427 m.Int64Counter.Add(ctx, incr, *o...)
1428 }
1429
1430 // AddSet adds incr to the existing count for set.
1431 //
1432 // The number of bytes sent/received on all network interfaces by the container.
1433 func (m NetworkIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1434 if set.Len() == 0 {
1435 m.Int64Counter.Add(ctx, incr)
1436 return
1437 }
1438
1439 o := addOptPool.Get().(*[]metric.AddOption)
1440 defer func() {
1441 *o = (*o)[:0]
1442 addOptPool.Put(o)
1443 }()
1444
1445 *o = append(*o, metric.WithAttributeSet(set))
1446 m.Int64Counter.Add(ctx, incr, *o...)
1447 }
1448
1449 // AttrNetworkInterfaceName returns an optional attribute for the
1450 // "network.interface.name" semantic convention. It represents the network
1451 // interface name.
1452 func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
1453 return attribute.String("network.interface.name", val)
1454 }
1455
1456 // AttrNetworkIODirection returns an optional attribute for the
1457 // "network.io.direction" semantic convention. It represents the network IO
1458 // operation direction.
1459 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
1460 return attribute.String("network.io.direction", string(val))
1461 }
1462
1463 // Uptime is an instrument used to record metric values conforming to the
1464 // "container.uptime" semantic conventions. It represents the time the container
1465 // has been running.
1466 type Uptime struct {
1467 metric.Float64Gauge
1468 }
1469
1470 var newUptimeOpts = []metric.Float64GaugeOption{
1471 metric.WithDescription("The time the container has been running."),
1472 metric.WithUnit("s"),
1473 }
1474
1475 // NewUptime returns a new Uptime instrument.
1476 func NewUptime(
1477 m metric.Meter,
1478 opt ...metric.Float64GaugeOption,
1479 ) (Uptime, error) {
1480 // Check if the meter is nil.
1481 if m == nil {
1482 return Uptime{noop.Float64Gauge{}}, nil
1483 }
1484
1485 if len(opt) == 0 {
1486 opt = newUptimeOpts
1487 } else {
1488 opt = append(opt, newUptimeOpts...)
1489 }
1490
1491 i, err := m.Float64Gauge(
1492 "container.uptime",
1493 opt...,
1494 )
1495 if err != nil {
1496 return Uptime{noop.Float64Gauge{}}, err
1497 }
1498 return Uptime{i}, nil
1499 }
1500
1501 // Inst returns the underlying metric instrument.
1502 func (m Uptime) Inst() metric.Float64Gauge {
1503 return m.Float64Gauge
1504 }
1505
1506 // Name returns the semantic convention name of the instrument.
1507 func (Uptime) Name() string {
1508 return "container.uptime"
1509 }
1510
1511 // Unit returns the semantic convention unit of the instrument
1512 func (Uptime) Unit() string {
1513 return "s"
1514 }
1515
1516 // Description returns the semantic convention description of the instrument
1517 func (Uptime) Description() string {
1518 return "The time the container has been running."
1519 }
1520
1521 // Record records val to the current distribution for attrs.
1522 //
1523 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1524 // seconds as a floating point number with the highest precision available.
1525 // The actual accuracy would depend on the instrumentation and operating system.
1526 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
1527 if len(attrs) == 0 {
1528 m.Float64Gauge.Record(ctx, val)
1529 return
1530 }
1531
1532 o := recOptPool.Get().(*[]metric.RecordOption)
1533 defer func() {
1534 *o = (*o)[:0]
1535 recOptPool.Put(o)
1536 }()
1537
1538 *o = append(*o, metric.WithAttributes(attrs...))
1539 m.Float64Gauge.Record(ctx, val, *o...)
1540 }
1541
1542 // RecordSet records val to the current distribution for set.
1543 //
1544 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1545 // seconds as a floating point number with the highest precision available.
1546 // The actual accuracy would depend on the instrumentation and operating system.
1547 func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1548 if set.Len() == 0 {
1549 m.Float64Gauge.Record(ctx, val)
1550 return
1551 }
1552
1553 o := recOptPool.Get().(*[]metric.RecordOption)
1554 defer func() {
1555 *o = (*o)[:0]
1556 recOptPool.Put(o)
1557 }()
1558
1559 *o = append(*o, metric.WithAttributeSet(set))
1560 m.Float64Gauge.Record(ctx, val, *o...)
1561 }