Debian Codegraph @

semconv/v1.37.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 // CPUTime is an instrument used to record metric values conforming to the
75 // "container.cpu.time" semantic conventions. It represents the total CPU time
76 // consumed.
77 type CPUTime struct {
78 metric.Float64Counter
79 }
80
81 var newCPUTimeOpts = []metric.Float64CounterOption{
82 metric.WithDescription("Total CPU time consumed."),
83 metric.WithUnit("s"),
84 }
85
86 // NewCPUTime returns a new CPUTime instrument.
87 func NewCPUTime(
88 m metric.Meter,
89 opt ...metric.Float64CounterOption,
90 ) (CPUTime, error) {
91 // Check if the meter is nil.
92 if m == nil {
93 return CPUTime{noop.Float64Counter{}}, nil
94 }
95
96 if len(opt) == 0 {
97 opt = newCPUTimeOpts
98 } else {
99 opt = append(opt, newCPUTimeOpts...)
100 }
101
102 i, err := m.Float64Counter(
103 "container.cpu.time",
104 opt...,
105 )
106 if err != nil {
107 return CPUTime{noop.Float64Counter{}}, err
108 }
109 return CPUTime{i}, nil
110 }
111
112 // Inst returns the underlying metric instrument.
113 func (m CPUTime) Inst() metric.Float64Counter {
114 return m.Float64Counter
115 }
116
117 // Name returns the semantic convention name of the instrument.
118 func (CPUTime) Name() string {
119 return "container.cpu.time"
120 }
121
122 // Unit returns the semantic convention unit of the instrument
123 func (CPUTime) Unit() string {
124 return "s"
125 }
126
127 // Description returns the semantic convention description of the instrument
128 func (CPUTime) Description() string {
129 return "Total CPU time consumed."
130 }
131
132 // Add adds incr to the existing count for attrs.
133 //
134 // All additional attrs passed are included in the recorded value.
135 //
136 // Total CPU time consumed by the specific container on all available CPU cores
137 func (m CPUTime) Add(
138 ctx context.Context,
139 incr float64,
140 attrs ...attribute.KeyValue,
141 ) {
142 if len(attrs) == 0 {
143 m.Float64Counter.Add(ctx, incr)
144 return
145 }
146
147 o := addOptPool.Get().(*[]metric.AddOption)
148 defer func() {
149 *o = (*o)[:0]
150 addOptPool.Put(o)
151 }()
152
153 *o = append(
154 *o,
155 metric.WithAttributes(
156 attrs...,
157 ),
158 )
159
160 m.Float64Counter.Add(ctx, incr, *o...)
161 }
162
163 // AddSet adds incr to the existing count for set.
164 //
165 // Total CPU time consumed by the specific container on all available CPU cores
166 func (m CPUTime) AddSet(ctx context.Context, incr float64, set attribute.Set) {
167 if set.Len() == 0 {
168 m.Float64Counter.Add(ctx, incr)
169 return
170 }
171
172 o := addOptPool.Get().(*[]metric.AddOption)
173 defer func() {
174 *o = (*o)[:0]
175 addOptPool.Put(o)
176 }()
177
178 *o = append(*o, metric.WithAttributeSet(set))
179 m.Float64Counter.Add(ctx, incr, *o...)
180 }
181
182 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
183 // convention. It represents the CPU mode for this data point. A container's CPU
184 // metric SHOULD be characterized *either* by data points with no `mode` labels,
185 // *or only* data points with `mode` labels.
186 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
187 return attribute.String("cpu.mode", string(val))
188 }
189
190 // CPUUsage is an instrument used to record metric values conforming to the
191 // "container.cpu.usage" semantic conventions. It represents the container's CPU
192 // usage, measured in cpus. Range from 0 to the number of allocatable CPUs.
193 type CPUUsage struct {
194 metric.Int64Gauge
195 }
196
197 var newCPUUsageOpts = []metric.Int64GaugeOption{
198 metric.WithDescription("Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs."),
199 metric.WithUnit("{cpu}"),
200 }
201
202 // NewCPUUsage returns a new CPUUsage instrument.
203 func NewCPUUsage(
204 m metric.Meter,
205 opt ...metric.Int64GaugeOption,
206 ) (CPUUsage, error) {
207 // Check if the meter is nil.
208 if m == nil {
209 return CPUUsage{noop.Int64Gauge{}}, nil
210 }
211
212 if len(opt) == 0 {
213 opt = newCPUUsageOpts
214 } else {
215 opt = append(opt, newCPUUsageOpts...)
216 }
217
218 i, err := m.Int64Gauge(
219 "container.cpu.usage",
220 opt...,
221 )
222 if err != nil {
223 return CPUUsage{noop.Int64Gauge{}}, err
224 }
225 return CPUUsage{i}, nil
226 }
227
228 // Inst returns the underlying metric instrument.
229 func (m CPUUsage) Inst() metric.Int64Gauge {
230 return m.Int64Gauge
231 }
232
233 // Name returns the semantic convention name of the instrument.
234 func (CPUUsage) Name() string {
235 return "container.cpu.usage"
236 }
237
238 // Unit returns the semantic convention unit of the instrument
239 func (CPUUsage) Unit() string {
240 return "{cpu}"
241 }
242
243 // Description returns the semantic convention description of the instrument
244 func (CPUUsage) Description() string {
245 return "Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs."
246 }
247
248 // Record records val to the current distribution for attrs.
249 //
250 // All additional attrs passed are included in the recorded value.
251 //
252 // CPU usage of the specific container on all available CPU cores, averaged over
253 // the sample window
254 func (m CPUUsage) Record(
255 ctx context.Context,
256 val int64,
257 attrs ...attribute.KeyValue,
258 ) {
259 if len(attrs) == 0 {
260 m.Int64Gauge.Record(ctx, val)
261 return
262 }
263
264 o := recOptPool.Get().(*[]metric.RecordOption)
265 defer func() {
266 *o = (*o)[:0]
267 recOptPool.Put(o)
268 }()
269
270 *o = append(
271 *o,
272 metric.WithAttributes(
273 attrs...,
274 ),
275 )
276
277 m.Int64Gauge.Record(ctx, val, *o...)
278 }
279
280 // RecordSet records val to the current distribution for set.
281 //
282 // CPU usage of the specific container on all available CPU cores, averaged over
283 // the sample window
284 func (m CPUUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) {
285 if set.Len() == 0 {
286 m.Int64Gauge.Record(ctx, val)
287 return
288 }
289
290 o := recOptPool.Get().(*[]metric.RecordOption)
291 defer func() {
292 *o = (*o)[:0]
293 recOptPool.Put(o)
294 }()
295
296 *o = append(*o, metric.WithAttributeSet(set))
297 m.Int64Gauge.Record(ctx, val, *o...)
298 }
299
300 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
301 // convention. It represents the CPU mode for this data point. A container's CPU
302 // metric SHOULD be characterized *either* by data points with no `mode` labels,
303 // *or only* data points with `mode` labels.
304 func (CPUUsage) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
305 return attribute.String("cpu.mode", string(val))
306 }
307
308 // DiskIO is an instrument used to record metric values conforming to the
309 // "container.disk.io" semantic conventions. It represents the disk bytes for the
310 // container.
311 type DiskIO struct {
312 metric.Int64Counter
313 }
314
315 var newDiskIOOpts = []metric.Int64CounterOption{
316 metric.WithDescription("Disk bytes for the container."),
317 metric.WithUnit("By"),
318 }
319
320 // NewDiskIO returns a new DiskIO instrument.
321 func NewDiskIO(
322 m metric.Meter,
323 opt ...metric.Int64CounterOption,
324 ) (DiskIO, error) {
325 // Check if the meter is nil.
326 if m == nil {
327 return DiskIO{noop.Int64Counter{}}, nil
328 }
329
330 if len(opt) == 0 {
331 opt = newDiskIOOpts
332 } else {
333 opt = append(opt, newDiskIOOpts...)
334 }
335
336 i, err := m.Int64Counter(
337 "container.disk.io",
338 opt...,
339 )
340 if err != nil {
341 return DiskIO{noop.Int64Counter{}}, err
342 }
343 return DiskIO{i}, nil
344 }
345
346 // Inst returns the underlying metric instrument.
347 func (m DiskIO) Inst() metric.Int64Counter {
348 return m.Int64Counter
349 }
350
351 // Name returns the semantic convention name of the instrument.
352 func (DiskIO) Name() string {
353 return "container.disk.io"
354 }
355
356 // Unit returns the semantic convention unit of the instrument
357 func (DiskIO) Unit() string {
358 return "By"
359 }
360
361 // Description returns the semantic convention description of the instrument
362 func (DiskIO) Description() string {
363 return "Disk bytes for the container."
364 }
365
366 // Add adds incr to the existing count for attrs.
367 //
368 // All additional attrs passed are included in the recorded value.
369 //
370 // The total number of bytes read/written successfully (aggregated from all
371 // disks).
372 func (m DiskIO) Add(
373 ctx context.Context,
374 incr int64,
375 attrs ...attribute.KeyValue,
376 ) {
377 if len(attrs) == 0 {
378 m.Int64Counter.Add(ctx, incr)
379 return
380 }
381
382 o := addOptPool.Get().(*[]metric.AddOption)
383 defer func() {
384 *o = (*o)[:0]
385 addOptPool.Put(o)
386 }()
387
388 *o = append(
389 *o,
390 metric.WithAttributes(
391 attrs...,
392 ),
393 )
394
395 m.Int64Counter.Add(ctx, incr, *o...)
396 }
397
398 // AddSet adds incr to the existing count for set.
399 //
400 // The total number of bytes read/written successfully (aggregated from all
401 // disks).
402 func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
403 if set.Len() == 0 {
404 m.Int64Counter.Add(ctx, incr)
405 return
406 }
407
408 o := addOptPool.Get().(*[]metric.AddOption)
409 defer func() {
410 *o = (*o)[:0]
411 addOptPool.Put(o)
412 }()
413
414 *o = append(*o, metric.WithAttributeSet(set))
415 m.Int64Counter.Add(ctx, incr, *o...)
416 }
417
418 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
419 // semantic convention. It represents the disk IO operation direction.
420 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
421 return attribute.String("disk.io.direction", string(val))
422 }
423
424 // AttrSystemDevice returns an optional attribute for the "system.device"
425 // semantic convention. It represents the device identifier.
426 func (DiskIO) AttrSystemDevice(val string) attribute.KeyValue {
427 return attribute.String("system.device", val)
428 }
429
430 // FilesystemAvailable is an instrument used to record metric values conforming
431 // to the "container.filesystem.available" semantic conventions. It represents
432 // the container filesystem available bytes.
433 type FilesystemAvailable struct {
434 metric.Int64UpDownCounter
435 }
436
437 var newFilesystemAvailableOpts = []metric.Int64UpDownCounterOption{
438 metric.WithDescription("Container filesystem available bytes."),
439 metric.WithUnit("By"),
440 }
441
442 // NewFilesystemAvailable returns a new FilesystemAvailable instrument.
443 func NewFilesystemAvailable(
444 m metric.Meter,
445 opt ...metric.Int64UpDownCounterOption,
446 ) (FilesystemAvailable, error) {
447 // Check if the meter is nil.
448 if m == nil {
449 return FilesystemAvailable{noop.Int64UpDownCounter{}}, nil
450 }
451
452 if len(opt) == 0 {
453 opt = newFilesystemAvailableOpts
454 } else {
455 opt = append(opt, newFilesystemAvailableOpts...)
456 }
457
458 i, err := m.Int64UpDownCounter(
459 "container.filesystem.available",
460 opt...,
461 )
462 if err != nil {
463 return FilesystemAvailable{noop.Int64UpDownCounter{}}, err
464 }
465 return FilesystemAvailable{i}, nil
466 }
467
468 // Inst returns the underlying metric instrument.
469 func (m FilesystemAvailable) Inst() metric.Int64UpDownCounter {
470 return m.Int64UpDownCounter
471 }
472
473 // Name returns the semantic convention name of the instrument.
474 func (FilesystemAvailable) Name() string {
475 return "container.filesystem.available"
476 }
477
478 // Unit returns the semantic convention unit of the instrument
479 func (FilesystemAvailable) Unit() string {
480 return "By"
481 }
482
483 // Description returns the semantic convention description of the instrument
484 func (FilesystemAvailable) Description() string {
485 return "Container filesystem available bytes."
486 }
487
488 // Add adds incr to the existing count for attrs.
489 //
490 // In K8s, this metric is derived from the
491 // [FsStats.AvailableBytes] field
492 // of the [ContainerStats.Rootfs]
493 // of the Kubelet's stats API.
494 //
495 // [FsStats.AvailableBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
496 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
497 func (m FilesystemAvailable) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
498 if len(attrs) == 0 {
499 m.Int64UpDownCounter.Add(ctx, incr)
500 return
501 }
502
503 o := addOptPool.Get().(*[]metric.AddOption)
504 defer func() {
505 *o = (*o)[:0]
506 addOptPool.Put(o)
507 }()
508
509 *o = append(*o, metric.WithAttributes(attrs...))
510 m.Int64UpDownCounter.Add(ctx, incr, *o...)
511 }
512
513 // AddSet adds incr to the existing count for set.
514 //
515 // In K8s, this metric is derived from the
516 // [FsStats.AvailableBytes] field
517 // of the [ContainerStats.Rootfs]
518 // of the Kubelet's stats API.
519 //
520 // [FsStats.AvailableBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
521 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
522 func (m FilesystemAvailable) AddSet(ctx context.Context, incr int64, set attribute.Set) {
523 if set.Len() == 0 {
524 m.Int64UpDownCounter.Add(ctx, incr)
525 return
526 }
527
528 o := addOptPool.Get().(*[]metric.AddOption)
529 defer func() {
530 *o = (*o)[:0]
531 addOptPool.Put(o)
532 }()
533
534 *o = append(*o, metric.WithAttributeSet(set))
535 m.Int64UpDownCounter.Add(ctx, incr, *o...)
536 }
537
538 // FilesystemCapacity is an instrument used to record metric values conforming to
539 // the "container.filesystem.capacity" semantic conventions. It represents the
540 // container filesystem capacity.
541 type FilesystemCapacity struct {
542 metric.Int64UpDownCounter
543 }
544
545 var newFilesystemCapacityOpts = []metric.Int64UpDownCounterOption{
546 metric.WithDescription("Container filesystem capacity."),
547 metric.WithUnit("By"),
548 }
549
550 // NewFilesystemCapacity returns a new FilesystemCapacity instrument.
551 func NewFilesystemCapacity(
552 m metric.Meter,
553 opt ...metric.Int64UpDownCounterOption,
554 ) (FilesystemCapacity, error) {
555 // Check if the meter is nil.
556 if m == nil {
557 return FilesystemCapacity{noop.Int64UpDownCounter{}}, nil
558 }
559
560 if len(opt) == 0 {
561 opt = newFilesystemCapacityOpts
562 } else {
563 opt = append(opt, newFilesystemCapacityOpts...)
564 }
565
566 i, err := m.Int64UpDownCounter(
567 "container.filesystem.capacity",
568 opt...,
569 )
570 if err != nil {
571 return FilesystemCapacity{noop.Int64UpDownCounter{}}, err
572 }
573 return FilesystemCapacity{i}, nil
574 }
575
576 // Inst returns the underlying metric instrument.
577 func (m FilesystemCapacity) Inst() metric.Int64UpDownCounter {
578 return m.Int64UpDownCounter
579 }
580
581 // Name returns the semantic convention name of the instrument.
582 func (FilesystemCapacity) Name() string {
583 return "container.filesystem.capacity"
584 }
585
586 // Unit returns the semantic convention unit of the instrument
587 func (FilesystemCapacity) Unit() string {
588 return "By"
589 }
590
591 // Description returns the semantic convention description of the instrument
592 func (FilesystemCapacity) Description() string {
593 return "Container filesystem capacity."
594 }
595
596 // Add adds incr to the existing count for attrs.
597 //
598 // In K8s, this metric is derived from the
599 // [FsStats.CapacityBytes] field
600 // of the [ContainerStats.Rootfs]
601 // of the Kubelet's stats API.
602 //
603 // [FsStats.CapacityBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
604 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
605 func (m FilesystemCapacity) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
606 if len(attrs) == 0 {
607 m.Int64UpDownCounter.Add(ctx, incr)
608 return
609 }
610
611 o := addOptPool.Get().(*[]metric.AddOption)
612 defer func() {
613 *o = (*o)[:0]
614 addOptPool.Put(o)
615 }()
616
617 *o = append(*o, metric.WithAttributes(attrs...))
618 m.Int64UpDownCounter.Add(ctx, incr, *o...)
619 }
620
621 // AddSet adds incr to the existing count for set.
622 //
623 // In K8s, this metric is derived from the
624 // [FsStats.CapacityBytes] field
625 // of the [ContainerStats.Rootfs]
626 // of the Kubelet's stats API.
627 //
628 // [FsStats.CapacityBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
629 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
630 func (m FilesystemCapacity) AddSet(ctx context.Context, incr int64, set attribute.Set) {
631 if set.Len() == 0 {
632 m.Int64UpDownCounter.Add(ctx, incr)
633 return
634 }
635
636 o := addOptPool.Get().(*[]metric.AddOption)
637 defer func() {
638 *o = (*o)[:0]
639 addOptPool.Put(o)
640 }()
641
642 *o = append(*o, metric.WithAttributeSet(set))
643 m.Int64UpDownCounter.Add(ctx, incr, *o...)
644 }
645
646 // FilesystemUsage is an instrument used to record metric values conforming to
647 // the "container.filesystem.usage" semantic conventions. It represents the
648 // container filesystem usage.
649 type FilesystemUsage struct {
650 metric.Int64UpDownCounter
651 }
652
653 var newFilesystemUsageOpts = []metric.Int64UpDownCounterOption{
654 metric.WithDescription("Container filesystem usage."),
655 metric.WithUnit("By"),
656 }
657
658 // NewFilesystemUsage returns a new FilesystemUsage instrument.
659 func NewFilesystemUsage(
660 m metric.Meter,
661 opt ...metric.Int64UpDownCounterOption,
662 ) (FilesystemUsage, error) {
663 // Check if the meter is nil.
664 if m == nil {
665 return FilesystemUsage{noop.Int64UpDownCounter{}}, nil
666 }
667
668 if len(opt) == 0 {
669 opt = newFilesystemUsageOpts
670 } else {
671 opt = append(opt, newFilesystemUsageOpts...)
672 }
673
674 i, err := m.Int64UpDownCounter(
675 "container.filesystem.usage",
676 opt...,
677 )
678 if err != nil {
679 return FilesystemUsage{noop.Int64UpDownCounter{}}, err
680 }
681 return FilesystemUsage{i}, nil
682 }
683
684 // Inst returns the underlying metric instrument.
685 func (m FilesystemUsage) Inst() metric.Int64UpDownCounter {
686 return m.Int64UpDownCounter
687 }
688
689 // Name returns the semantic convention name of the instrument.
690 func (FilesystemUsage) Name() string {
691 return "container.filesystem.usage"
692 }
693
694 // Unit returns the semantic convention unit of the instrument
695 func (FilesystemUsage) Unit() string {
696 return "By"
697 }
698
699 // Description returns the semantic convention description of the instrument
700 func (FilesystemUsage) Description() string {
701 return "Container filesystem usage."
702 }
703
704 // Add adds incr to the existing count for attrs.
705 //
706 // This may not equal capacity - available.
707 //
708 // In K8s, this metric is derived from the
709 // [FsStats.UsedBytes] field
710 // of the [ContainerStats.Rootfs]
711 // of the Kubelet's stats API.
712 //
713 // [FsStats.UsedBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
714 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
715 func (m FilesystemUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
716 if len(attrs) == 0 {
717 m.Int64UpDownCounter.Add(ctx, incr)
718 return
719 }
720
721 o := addOptPool.Get().(*[]metric.AddOption)
722 defer func() {
723 *o = (*o)[:0]
724 addOptPool.Put(o)
725 }()
726
727 *o = append(*o, metric.WithAttributes(attrs...))
728 m.Int64UpDownCounter.Add(ctx, incr, *o...)
729 }
730
731 // AddSet adds incr to the existing count for set.
732 //
733 // This may not equal capacity - available.
734 //
735 // In K8s, this metric is derived from the
736 // [FsStats.UsedBytes] field
737 // of the [ContainerStats.Rootfs]
738 // of the Kubelet's stats API.
739 //
740 // [FsStats.UsedBytes]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#FsStats
741 // [ContainerStats.Rootfs]: https://pkg.go.dev/k8s.io/[email protected]/pkg/apis/stats/v1alpha1#ContainerStats
742 func (m FilesystemUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
743 if set.Len() == 0 {
744 m.Int64UpDownCounter.Add(ctx, incr)
745 return
746 }
747
748 o := addOptPool.Get().(*[]metric.AddOption)
749 defer func() {
750 *o = (*o)[:0]
751 addOptPool.Put(o)
752 }()
753
754 *o = append(*o, metric.WithAttributeSet(set))
755 m.Int64UpDownCounter.Add(ctx, incr, *o...)
756 }
757
758 // MemoryUsage is an instrument used to record metric values conforming to the
759 // "container.memory.usage" semantic conventions. It represents the memory usage
760 // of the container.
761 type MemoryUsage struct {
762 metric.Int64Counter
763 }
764
765 var newMemoryUsageOpts = []metric.Int64CounterOption{
766 metric.WithDescription("Memory usage of the container."),
767 metric.WithUnit("By"),
768 }
769
770 // NewMemoryUsage returns a new MemoryUsage instrument.
771 func NewMemoryUsage(
772 m metric.Meter,
773 opt ...metric.Int64CounterOption,
774 ) (MemoryUsage, error) {
775 // Check if the meter is nil.
776 if m == nil {
777 return MemoryUsage{noop.Int64Counter{}}, nil
778 }
779
780 if len(opt) == 0 {
781 opt = newMemoryUsageOpts
782 } else {
783 opt = append(opt, newMemoryUsageOpts...)
784 }
785
786 i, err := m.Int64Counter(
787 "container.memory.usage",
788 opt...,
789 )
790 if err != nil {
791 return MemoryUsage{noop.Int64Counter{}}, err
792 }
793 return MemoryUsage{i}, nil
794 }
795
796 // Inst returns the underlying metric instrument.
797 func (m MemoryUsage) Inst() metric.Int64Counter {
798 return m.Int64Counter
799 }
800
801 // Name returns the semantic convention name of the instrument.
802 func (MemoryUsage) Name() string {
803 return "container.memory.usage"
804 }
805
806 // Unit returns the semantic convention unit of the instrument
807 func (MemoryUsage) Unit() string {
808 return "By"
809 }
810
811 // Description returns the semantic convention description of the instrument
812 func (MemoryUsage) Description() string {
813 return "Memory usage of the container."
814 }
815
816 // Add adds incr to the existing count for attrs.
817 //
818 // Memory usage of the container.
819 func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
820 if len(attrs) == 0 {
821 m.Int64Counter.Add(ctx, incr)
822 return
823 }
824
825 o := addOptPool.Get().(*[]metric.AddOption)
826 defer func() {
827 *o = (*o)[:0]
828 addOptPool.Put(o)
829 }()
830
831 *o = append(*o, metric.WithAttributes(attrs...))
832 m.Int64Counter.Add(ctx, incr, *o...)
833 }
834
835 // AddSet adds incr to the existing count for set.
836 //
837 // Memory usage of the container.
838 func (m MemoryUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
839 if set.Len() == 0 {
840 m.Int64Counter.Add(ctx, incr)
841 return
842 }
843
844 o := addOptPool.Get().(*[]metric.AddOption)
845 defer func() {
846 *o = (*o)[:0]
847 addOptPool.Put(o)
848 }()
849
850 *o = append(*o, metric.WithAttributeSet(set))
851 m.Int64Counter.Add(ctx, incr, *o...)
852 }
853
854 // NetworkIO is an instrument used to record metric values conforming to the
855 // "container.network.io" semantic conventions. It represents the network bytes
856 // for the container.
857 type NetworkIO struct {
858 metric.Int64Counter
859 }
860
861 var newNetworkIOOpts = []metric.Int64CounterOption{
862 metric.WithDescription("Network bytes for the container."),
863 metric.WithUnit("By"),
864 }
865
866 // NewNetworkIO returns a new NetworkIO instrument.
867 func NewNetworkIO(
868 m metric.Meter,
869 opt ...metric.Int64CounterOption,
870 ) (NetworkIO, error) {
871 // Check if the meter is nil.
872 if m == nil {
873 return NetworkIO{noop.Int64Counter{}}, nil
874 }
875
876 if len(opt) == 0 {
877 opt = newNetworkIOOpts
878 } else {
879 opt = append(opt, newNetworkIOOpts...)
880 }
881
882 i, err := m.Int64Counter(
883 "container.network.io",
884 opt...,
885 )
886 if err != nil {
887 return NetworkIO{noop.Int64Counter{}}, err
888 }
889 return NetworkIO{i}, nil
890 }
891
892 // Inst returns the underlying metric instrument.
893 func (m NetworkIO) Inst() metric.Int64Counter {
894 return m.Int64Counter
895 }
896
897 // Name returns the semantic convention name of the instrument.
898 func (NetworkIO) Name() string {
899 return "container.network.io"
900 }
901
902 // Unit returns the semantic convention unit of the instrument
903 func (NetworkIO) Unit() string {
904 return "By"
905 }
906
907 // Description returns the semantic convention description of the instrument
908 func (NetworkIO) Description() string {
909 return "Network bytes for the container."
910 }
911
912 // Add adds incr to the existing count for attrs.
913 //
914 // All additional attrs passed are included in the recorded value.
915 //
916 // The number of bytes sent/received on all network interfaces by the container.
917 func (m NetworkIO) Add(
918 ctx context.Context,
919 incr int64,
920 attrs ...attribute.KeyValue,
921 ) {
922 if len(attrs) == 0 {
923 m.Int64Counter.Add(ctx, incr)
924 return
925 }
926
927 o := addOptPool.Get().(*[]metric.AddOption)
928 defer func() {
929 *o = (*o)[:0]
930 addOptPool.Put(o)
931 }()
932
933 *o = append(
934 *o,
935 metric.WithAttributes(
936 attrs...,
937 ),
938 )
939
940 m.Int64Counter.Add(ctx, incr, *o...)
941 }
942
943 // AddSet adds incr to the existing count for set.
944 //
945 // The number of bytes sent/received on all network interfaces by the container.
946 func (m NetworkIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
947 if set.Len() == 0 {
948 m.Int64Counter.Add(ctx, incr)
949 return
950 }
951
952 o := addOptPool.Get().(*[]metric.AddOption)
953 defer func() {
954 *o = (*o)[:0]
955 addOptPool.Put(o)
956 }()
957
958 *o = append(*o, metric.WithAttributeSet(set))
959 m.Int64Counter.Add(ctx, incr, *o...)
960 }
961
962 // AttrNetworkInterfaceName returns an optional attribute for the
963 // "network.interface.name" semantic convention. It represents the network
964 // interface name.
965 func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
966 return attribute.String("network.interface.name", val)
967 }
968
969 // AttrNetworkIODirection returns an optional attribute for the
970 // "network.io.direction" semantic convention. It represents the network IO
971 // operation direction.
972 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
973 return attribute.String("network.io.direction", string(val))
974 }
975
976 // Uptime is an instrument used to record metric values conforming to the
977 // "container.uptime" semantic conventions. It represents the time the container
978 // has been running.
979 type Uptime struct {
980 metric.Float64Gauge
981 }
982
983 var newUptimeOpts = []metric.Float64GaugeOption{
984 metric.WithDescription("The time the container has been running."),
985 metric.WithUnit("s"),
986 }
987
988 // NewUptime returns a new Uptime instrument.
989 func NewUptime(
990 m metric.Meter,
991 opt ...metric.Float64GaugeOption,
992 ) (Uptime, error) {
993 // Check if the meter is nil.
994 if m == nil {
995 return Uptime{noop.Float64Gauge{}}, nil
996 }
997
998 if len(opt) == 0 {
999 opt = newUptimeOpts
1000 } else {
1001 opt = append(opt, newUptimeOpts...)
1002 }
1003
1004 i, err := m.Float64Gauge(
1005 "container.uptime",
1006 opt...,
1007 )
1008 if err != nil {
1009 return Uptime{noop.Float64Gauge{}}, err
1010 }
1011 return Uptime{i}, nil
1012 }
1013
1014 // Inst returns the underlying metric instrument.
1015 func (m Uptime) Inst() metric.Float64Gauge {
1016 return m.Float64Gauge
1017 }
1018
1019 // Name returns the semantic convention name of the instrument.
1020 func (Uptime) Name() string {
1021 return "container.uptime"
1022 }
1023
1024 // Unit returns the semantic convention unit of the instrument
1025 func (Uptime) Unit() string {
1026 return "s"
1027 }
1028
1029 // Description returns the semantic convention description of the instrument
1030 func (Uptime) Description() string {
1031 return "The time the container has been running."
1032 }
1033
1034 // Record records val to the current distribution for attrs.
1035 //
1036 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1037 // seconds as a floating point number with the highest precision available.
1038 // The actual accuracy would depend on the instrumentation and operating system.
1039 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
1040 if len(attrs) == 0 {
1041 m.Float64Gauge.Record(ctx, val)
1042 return
1043 }
1044
1045 o := recOptPool.Get().(*[]metric.RecordOption)
1046 defer func() {
1047 *o = (*o)[:0]
1048 recOptPool.Put(o)
1049 }()
1050
1051 *o = append(*o, metric.WithAttributes(attrs...))
1052 m.Float64Gauge.Record(ctx, val, *o...)
1053 }
1054
1055 // RecordSet records val to the current distribution for set.
1056 //
1057 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1058 // seconds as a floating point number with the highest precision available.
1059 // The actual accuracy would depend on the instrumentation and operating system.
1060 func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1061 if set.Len() == 0 {
1062 m.Float64Gauge.Record(ctx, val)
1063 return
1064 }
1065
1066 o := recOptPool.Get().(*[]metric.RecordOption)
1067 defer func() {
1068 *o = (*o)[:0]
1069 recOptPool.Put(o)
1070 }()
1071
1072 *o = append(*o, metric.WithAttributeSet(set))
1073 m.Float64Gauge.Record(ctx, val, *o...)
1074 }