Debian Codegraph @

semconv/v1.36.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 standardized value "user" of CPUModeAttr.
32 CPUModeUser CPUModeAttr = "user"
33 // CPUModeSystem is the standardized value "system" of CPUModeAttr.
34 CPUModeSystem CPUModeAttr = "system"
35 // CPUModeNice is the standardized value "nice" of CPUModeAttr.
36 CPUModeNice CPUModeAttr = "nice"
37 // CPUModeIdle is the standardized value "idle" of CPUModeAttr.
38 CPUModeIdle CPUModeAttr = "idle"
39 // CPUModeIOWait is the standardized value "iowait" of CPUModeAttr.
40 CPUModeIOWait CPUModeAttr = "iowait"
41 // CPUModeInterrupt is the standardized value "interrupt" of CPUModeAttr.
42 CPUModeInterrupt CPUModeAttr = "interrupt"
43 // CPUModeSteal is the standardized value "steal" of CPUModeAttr.
44 CPUModeSteal CPUModeAttr = "steal"
45 // CPUModeKernel is the standardized value "kernel" of CPUModeAttr.
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 // NewCPUTime returns a new CPUTime instrument.
82 func NewCPUTime(
83 m metric.Meter,
84 opt ...metric.Float64CounterOption,
85 ) (CPUTime, error) {
86 // Check if the meter is nil.
87 if m == nil {
88 return CPUTime{noop.Float64Counter{}}, nil
89 }
90
91 i, err := m.Float64Counter(
92 "container.cpu.time",
93 append([]metric.Float64CounterOption{
94 metric.WithDescription("Total CPU time consumed"),
95 metric.WithUnit("s"),
96 }, opt...)...,
97 )
98 if err != nil {
99 return CPUTime{noop.Float64Counter{}}, err
100 }
101 return CPUTime{i}, nil
102 }
103
104 // Inst returns the underlying metric instrument.
105 func (m CPUTime) Inst() metric.Float64Counter {
106 return m.Float64Counter
107 }
108
109 // Name returns the semantic convention name of the instrument.
110 func (CPUTime) Name() string {
111 return "container.cpu.time"
112 }
113
114 // Unit returns the semantic convention unit of the instrument
115 func (CPUTime) Unit() string {
116 return "s"
117 }
118
119 // Description returns the semantic convention description of the instrument
120 func (CPUTime) Description() string {
121 return "Total CPU time consumed"
122 }
123
124 // Add adds incr to the existing count for attrs.
125 //
126 // All additional attrs passed are included in the recorded value.
127 //
128 // Total CPU time consumed by the specific container on all available CPU cores
129 func (m CPUTime) Add(
130 ctx context.Context,
131 incr float64,
132 attrs ...attribute.KeyValue,
133 ) {
134 if len(attrs) == 0 {
135 m.Float64Counter.Add(ctx, incr)
136 return
137 }
138
139 o := addOptPool.Get().(*[]metric.AddOption)
140 defer func() {
141 *o = (*o)[:0]
142 addOptPool.Put(o)
143 }()
144
145 *o = append(
146 *o,
147 metric.WithAttributes(
148 attrs...,
149 ),
150 )
151
152 m.Float64Counter.Add(ctx, incr, *o...)
153 }
154
155 // AddSet adds incr to the existing count for set.
156 //
157 // Total CPU time consumed by the specific container on all available CPU cores
158 func (m CPUTime) AddSet(ctx context.Context, incr float64, set attribute.Set) {
159 if set.Len() == 0 {
160 m.Float64Counter.Add(ctx, incr)
161 return
162 }
163
164 o := addOptPool.Get().(*[]metric.AddOption)
165 defer func() {
166 *o = (*o)[:0]
167 addOptPool.Put(o)
168 }()
169
170 *o = append(*o, metric.WithAttributeSet(set))
171 m.Float64Counter.Add(ctx, incr, *o...)
172 }
173
174 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
175 // convention. It represents the CPU mode for this data point. A container's CPU
176 // metric SHOULD be characterized *either* by data points with no `mode` labels,
177 // *or only* data points with `mode` labels.
178 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
179 return attribute.String("cpu.mode", string(val))
180 }
181
182 // CPUUsage is an instrument used to record metric values conforming to the
183 // "container.cpu.usage" semantic conventions. It represents the container's CPU
184 // usage, measured in cpus. Range from 0 to the number of allocatable CPUs.
185 type CPUUsage struct {
186 metric.Int64Gauge
187 }
188
189 // NewCPUUsage returns a new CPUUsage instrument.
190 func NewCPUUsage(
191 m metric.Meter,
192 opt ...metric.Int64GaugeOption,
193 ) (CPUUsage, error) {
194 // Check if the meter is nil.
195 if m == nil {
196 return CPUUsage{noop.Int64Gauge{}}, nil
197 }
198
199 i, err := m.Int64Gauge(
200 "container.cpu.usage",
201 append([]metric.Int64GaugeOption{
202 metric.WithDescription("Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs"),
203 metric.WithUnit("{cpu}"),
204 }, opt...)...,
205 )
206 if err != nil {
207 return CPUUsage{noop.Int64Gauge{}}, err
208 }
209 return CPUUsage{i}, nil
210 }
211
212 // Inst returns the underlying metric instrument.
213 func (m CPUUsage) Inst() metric.Int64Gauge {
214 return m.Int64Gauge
215 }
216
217 // Name returns the semantic convention name of the instrument.
218 func (CPUUsage) Name() string {
219 return "container.cpu.usage"
220 }
221
222 // Unit returns the semantic convention unit of the instrument
223 func (CPUUsage) Unit() string {
224 return "{cpu}"
225 }
226
227 // Description returns the semantic convention description of the instrument
228 func (CPUUsage) Description() string {
229 return "Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs"
230 }
231
232 // Record records val to the current distribution for attrs.
233 //
234 // All additional attrs passed are included in the recorded value.
235 //
236 // CPU usage of the specific container on all available CPU cores, averaged over
237 // the sample window
238 func (m CPUUsage) Record(
239 ctx context.Context,
240 val int64,
241 attrs ...attribute.KeyValue,
242 ) {
243 if len(attrs) == 0 {
244 m.Int64Gauge.Record(ctx, val)
245 return
246 }
247
248 o := recOptPool.Get().(*[]metric.RecordOption)
249 defer func() {
250 *o = (*o)[:0]
251 recOptPool.Put(o)
252 }()
253
254 *o = append(
255 *o,
256 metric.WithAttributes(
257 attrs...,
258 ),
259 )
260
261 m.Int64Gauge.Record(ctx, val, *o...)
262 }
263
264 // RecordSet records val to the current distribution for set.
265 //
266 // CPU usage of the specific container on all available CPU cores, averaged over
267 // the sample window
268 func (m CPUUsage) RecordSet(ctx context.Context, val int64, set attribute.Set) {
269 if set.Len() == 0 {
270 m.Int64Gauge.Record(ctx, val)
271 return
272 }
273
274 o := recOptPool.Get().(*[]metric.RecordOption)
275 defer func() {
276 *o = (*o)[:0]
277 recOptPool.Put(o)
278 }()
279
280 *o = append(*o, metric.WithAttributeSet(set))
281 m.Int64Gauge.Record(ctx, val, *o...)
282 }
283
284 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
285 // convention. It represents the CPU mode for this data point. A container's CPU
286 // metric SHOULD be characterized *either* by data points with no `mode` labels,
287 // *or only* data points with `mode` labels.
288 func (CPUUsage) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
289 return attribute.String("cpu.mode", string(val))
290 }
291
292 // DiskIO is an instrument used to record metric values conforming to the
293 // "container.disk.io" semantic conventions. It represents the disk bytes for the
294 // container.
295 type DiskIO struct {
296 metric.Int64Counter
297 }
298
299 // NewDiskIO returns a new DiskIO instrument.
300 func NewDiskIO(
301 m metric.Meter,
302 opt ...metric.Int64CounterOption,
303 ) (DiskIO, error) {
304 // Check if the meter is nil.
305 if m == nil {
306 return DiskIO{noop.Int64Counter{}}, nil
307 }
308
309 i, err := m.Int64Counter(
310 "container.disk.io",
311 append([]metric.Int64CounterOption{
312 metric.WithDescription("Disk bytes for the container."),
313 metric.WithUnit("By"),
314 }, opt...)...,
315 )
316 if err != nil {
317 return DiskIO{noop.Int64Counter{}}, err
318 }
319 return DiskIO{i}, nil
320 }
321
322 // Inst returns the underlying metric instrument.
323 func (m DiskIO) Inst() metric.Int64Counter {
324 return m.Int64Counter
325 }
326
327 // Name returns the semantic convention name of the instrument.
328 func (DiskIO) Name() string {
329 return "container.disk.io"
330 }
331
332 // Unit returns the semantic convention unit of the instrument
333 func (DiskIO) Unit() string {
334 return "By"
335 }
336
337 // Description returns the semantic convention description of the instrument
338 func (DiskIO) Description() string {
339 return "Disk bytes for the container."
340 }
341
342 // Add adds incr to the existing count for attrs.
343 //
344 // All additional attrs passed are included in the recorded value.
345 //
346 // The total number of bytes read/written successfully (aggregated from all
347 // disks).
348 func (m DiskIO) Add(
349 ctx context.Context,
350 incr int64,
351 attrs ...attribute.KeyValue,
352 ) {
353 if len(attrs) == 0 {
354 m.Int64Counter.Add(ctx, incr)
355 return
356 }
357
358 o := addOptPool.Get().(*[]metric.AddOption)
359 defer func() {
360 *o = (*o)[:0]
361 addOptPool.Put(o)
362 }()
363
364 *o = append(
365 *o,
366 metric.WithAttributes(
367 attrs...,
368 ),
369 )
370
371 m.Int64Counter.Add(ctx, incr, *o...)
372 }
373
374 // AddSet adds incr to the existing count for set.
375 //
376 // The total number of bytes read/written successfully (aggregated from all
377 // disks).
378 func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
379 if set.Len() == 0 {
380 m.Int64Counter.Add(ctx, incr)
381 return
382 }
383
384 o := addOptPool.Get().(*[]metric.AddOption)
385 defer func() {
386 *o = (*o)[:0]
387 addOptPool.Put(o)
388 }()
389
390 *o = append(*o, metric.WithAttributeSet(set))
391 m.Int64Counter.Add(ctx, incr, *o...)
392 }
393
394 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
395 // semantic convention. It represents the disk IO operation direction.
396 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
397 return attribute.String("disk.io.direction", string(val))
398 }
399
400 // AttrSystemDevice returns an optional attribute for the "system.device"
401 // semantic convention. It represents the device identifier.
402 func (DiskIO) AttrSystemDevice(val string) attribute.KeyValue {
403 return attribute.String("system.device", val)
404 }
405
406 // MemoryUsage is an instrument used to record metric values conforming to the
407 // "container.memory.usage" semantic conventions. It represents the memory usage
408 // of the container.
409 type MemoryUsage struct {
410 metric.Int64Counter
411 }
412
413 // NewMemoryUsage returns a new MemoryUsage instrument.
414 func NewMemoryUsage(
415 m metric.Meter,
416 opt ...metric.Int64CounterOption,
417 ) (MemoryUsage, error) {
418 // Check if the meter is nil.
419 if m == nil {
420 return MemoryUsage{noop.Int64Counter{}}, nil
421 }
422
423 i, err := m.Int64Counter(
424 "container.memory.usage",
425 append([]metric.Int64CounterOption{
426 metric.WithDescription("Memory usage of the container."),
427 metric.WithUnit("By"),
428 }, opt...)...,
429 )
430 if err != nil {
431 return MemoryUsage{noop.Int64Counter{}}, err
432 }
433 return MemoryUsage{i}, nil
434 }
435
436 // Inst returns the underlying metric instrument.
437 func (m MemoryUsage) Inst() metric.Int64Counter {
438 return m.Int64Counter
439 }
440
441 // Name returns the semantic convention name of the instrument.
442 func (MemoryUsage) Name() string {
443 return "container.memory.usage"
444 }
445
446 // Unit returns the semantic convention unit of the instrument
447 func (MemoryUsage) Unit() string {
448 return "By"
449 }
450
451 // Description returns the semantic convention description of the instrument
452 func (MemoryUsage) Description() string {
453 return "Memory usage of the container."
454 }
455
456 // Add adds incr to the existing count for attrs.
457 //
458 // Memory usage of the container.
459 func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
460 if len(attrs) == 0 {
461 m.Int64Counter.Add(ctx, incr)
462 return
463 }
464
465 o := addOptPool.Get().(*[]metric.AddOption)
466 defer func() {
467 *o = (*o)[:0]
468 addOptPool.Put(o)
469 }()
470
471 *o = append(*o, metric.WithAttributes(attrs...))
472 m.Int64Counter.Add(ctx, incr, *o...)
473 }
474
475 // AddSet adds incr to the existing count for set.
476 //
477 // Memory usage of the container.
478 func (m MemoryUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
479 if set.Len() == 0 {
480 m.Int64Counter.Add(ctx, incr)
481 return
482 }
483
484 o := addOptPool.Get().(*[]metric.AddOption)
485 defer func() {
486 *o = (*o)[:0]
487 addOptPool.Put(o)
488 }()
489
490 *o = append(*o, metric.WithAttributeSet(set))
491 m.Int64Counter.Add(ctx, incr, *o...)
492 }
493
494 // NetworkIO is an instrument used to record metric values conforming to the
495 // "container.network.io" semantic conventions. It represents the network bytes
496 // for the container.
497 type NetworkIO struct {
498 metric.Int64Counter
499 }
500
501 // NewNetworkIO returns a new NetworkIO instrument.
502 func NewNetworkIO(
503 m metric.Meter,
504 opt ...metric.Int64CounterOption,
505 ) (NetworkIO, error) {
506 // Check if the meter is nil.
507 if m == nil {
508 return NetworkIO{noop.Int64Counter{}}, nil
509 }
510
511 i, err := m.Int64Counter(
512 "container.network.io",
513 append([]metric.Int64CounterOption{
514 metric.WithDescription("Network bytes for the container."),
515 metric.WithUnit("By"),
516 }, opt...)...,
517 )
518 if err != nil {
519 return NetworkIO{noop.Int64Counter{}}, err
520 }
521 return NetworkIO{i}, nil
522 }
523
524 // Inst returns the underlying metric instrument.
525 func (m NetworkIO) Inst() metric.Int64Counter {
526 return m.Int64Counter
527 }
528
529 // Name returns the semantic convention name of the instrument.
530 func (NetworkIO) Name() string {
531 return "container.network.io"
532 }
533
534 // Unit returns the semantic convention unit of the instrument
535 func (NetworkIO) Unit() string {
536 return "By"
537 }
538
539 // Description returns the semantic convention description of the instrument
540 func (NetworkIO) Description() string {
541 return "Network bytes for the container."
542 }
543
544 // Add adds incr to the existing count for attrs.
545 //
546 // All additional attrs passed are included in the recorded value.
547 //
548 // The number of bytes sent/received on all network interfaces by the container.
549 func (m NetworkIO) Add(
550 ctx context.Context,
551 incr int64,
552 attrs ...attribute.KeyValue,
553 ) {
554 if len(attrs) == 0 {
555 m.Int64Counter.Add(ctx, incr)
556 return
557 }
558
559 o := addOptPool.Get().(*[]metric.AddOption)
560 defer func() {
561 *o = (*o)[:0]
562 addOptPool.Put(o)
563 }()
564
565 *o = append(
566 *o,
567 metric.WithAttributes(
568 attrs...,
569 ),
570 )
571
572 m.Int64Counter.Add(ctx, incr, *o...)
573 }
574
575 // AddSet adds incr to the existing count for set.
576 //
577 // The number of bytes sent/received on all network interfaces by the container.
578 func (m NetworkIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
579 if set.Len() == 0 {
580 m.Int64Counter.Add(ctx, incr)
581 return
582 }
583
584 o := addOptPool.Get().(*[]metric.AddOption)
585 defer func() {
586 *o = (*o)[:0]
587 addOptPool.Put(o)
588 }()
589
590 *o = append(*o, metric.WithAttributeSet(set))
591 m.Int64Counter.Add(ctx, incr, *o...)
592 }
593
594 // AttrNetworkInterfaceName returns an optional attribute for the
595 // "network.interface.name" semantic convention. It represents the network
596 // interface name.
597 func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
598 return attribute.String("network.interface.name", val)
599 }
600
601 // AttrNetworkIODirection returns an optional attribute for the
602 // "network.io.direction" semantic convention. It represents the network IO
603 // operation direction.
604 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
605 return attribute.String("network.io.direction", string(val))
606 }
607
608 // Uptime is an instrument used to record metric values conforming to the
609 // "container.uptime" semantic conventions. It represents the time the container
610 // has been running.
611 type Uptime struct {
612 metric.Float64Gauge
613 }
614
615 // NewUptime returns a new Uptime instrument.
616 func NewUptime(
617 m metric.Meter,
618 opt ...metric.Float64GaugeOption,
619 ) (Uptime, error) {
620 // Check if the meter is nil.
621 if m == nil {
622 return Uptime{noop.Float64Gauge{}}, nil
623 }
624
625 i, err := m.Float64Gauge(
626 "container.uptime",
627 append([]metric.Float64GaugeOption{
628 metric.WithDescription("The time the container has been running"),
629 metric.WithUnit("s"),
630 }, opt...)...,
631 )
632 if err != nil {
633 return Uptime{noop.Float64Gauge{}}, err
634 }
635 return Uptime{i}, nil
636 }
637
638 // Inst returns the underlying metric instrument.
639 func (m Uptime) Inst() metric.Float64Gauge {
640 return m.Float64Gauge
641 }
642
643 // Name returns the semantic convention name of the instrument.
644 func (Uptime) Name() string {
645 return "container.uptime"
646 }
647
648 // Unit returns the semantic convention unit of the instrument
649 func (Uptime) Unit() string {
650 return "s"
651 }
652
653 // Description returns the semantic convention description of the instrument
654 func (Uptime) Description() string {
655 return "The time the container has been running"
656 }
657
658 // Record records val to the current distribution for attrs.
659 //
660 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
661 // seconds as a floating point number with the highest precision available.
662 // The actual accuracy would depend on the instrumentation and operating system.
663 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
664 if len(attrs) == 0 {
665 m.Float64Gauge.Record(ctx, val)
666 return
667 }
668
669 o := recOptPool.Get().(*[]metric.RecordOption)
670 defer func() {
671 *o = (*o)[:0]
672 recOptPool.Put(o)
673 }()
674
675 *o = append(*o, metric.WithAttributes(attrs...))
676 m.Float64Gauge.Record(ctx, val, *o...)
677 }
678
679 // RecordSet records val to the current distribution for set.
680 //
681 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
682 // seconds as a floating point number with the highest precision available.
683 // The actual accuracy would depend on the instrumentation and operating system.
684 func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
685 if set.Len() == 0 {
686 m.Float64Gauge.Record(ctx, val)
687 return
688 }
689
690 o := recOptPool.Get().(*[]metric.RecordOption)
691 defer func() {
692 *o = (*o)[:0]
693 recOptPool.Put(o)
694 }()
695
696 *o = append(*o, metric.WithAttributeSet(set))
697 m.Float64Gauge.Record(ctx, val, *o...)
698 }