Debian Codegraph @

semconv/v1.33.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 none.
32 CPUModeUser CPUModeAttr = "user"
33 // CPUModeSystem is the none.
34 CPUModeSystem CPUModeAttr = "system"
35 // CPUModeNice is the none.
36 CPUModeNice CPUModeAttr = "nice"
37 // CPUModeIdle is the none.
38 CPUModeIdle CPUModeAttr = "idle"
39 // CPUModeIOWait is the none.
40 CPUModeIOWait CPUModeAttr = "iowait"
41 // CPUModeInterrupt is the none.
42 CPUModeInterrupt CPUModeAttr = "interrupt"
43 // CPUModeSteal is the none.
44 CPUModeSteal CPUModeAttr = "steal"
45 // CPUModeKernel is the none.
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 none.
55 DiskIODirectionRead DiskIODirectionAttr = "read"
56 // DiskIODirectionWrite is the none.
57 DiskIODirectionWrite DiskIODirectionAttr = "write"
58 )
59
60 // NetworkIODirectionAttr is an attribute conforming to the network.io.direction
61 // semantic conventions. It represents the network IO operation direction.
62 type NetworkIODirectionAttr string
63
64 var (
65 // NetworkIODirectionTransmit is the none.
66 NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
67 // NetworkIODirectionReceive is the none.
68 NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
69 )
70
71 // CPUTime is an instrument used to record metric values conforming to the
72 // "container.cpu.time" semantic conventions. It represents the total CPU time
73 // consumed.
74 type CPUTime struct {
75 metric.Float64Counter
76 }
77
78 // NewCPUTime returns a new CPUTime instrument.
79 func NewCPUTime(
80 m metric.Meter,
81 opt ...metric.Float64CounterOption,
82 ) (CPUTime, error) {
83 // Check if the meter is nil.
84 if m == nil {
85 return CPUTime{noop.Float64Counter{}}, nil
86 }
87
88 i, err := m.Float64Counter(
89 "container.cpu.time",
90 append([]metric.Float64CounterOption{
91 metric.WithDescription("Total CPU time consumed"),
92 metric.WithUnit("s"),
93 }, opt...)...,
94 )
95 if err != nil {
96 return CPUTime{noop.Float64Counter{}}, err
97 }
98 return CPUTime{i}, nil
99 }
100
101 // Inst returns the underlying metric instrument.
102 func (m CPUTime) Inst() metric.Float64Counter {
103 return m.Float64Counter
104 }
105
106 // Name returns the semantic convention name of the instrument.
107 func (CPUTime) Name() string {
108 return "container.cpu.time"
109 }
110
111 // Unit returns the semantic convention unit of the instrument
112 func (CPUTime) Unit() string {
113 return "s"
114 }
115
116 // Description returns the semantic convention description of the instrument
117 func (CPUTime) Description() string {
118 return "Total CPU time consumed"
119 }
120
121 // Add adds incr to the existing count.
122 //
123 // All additional attrs passed are included in the recorded value.
124 //
125 // Total CPU time consumed by the specific container on all available CPU cores
126 func (m CPUTime) Add(
127 ctx context.Context,
128 incr float64,
129 attrs ...attribute.KeyValue,
130 ) {
131 o := addOptPool.Get().(*[]metric.AddOption)
132 defer func() {
133 *o = (*o)[:0]
134 addOptPool.Put(o)
135 }()
136
137 *o = append(
138 *o,
139 metric.WithAttributes(
140 attrs...,
141 ),
142 )
143
144 m.Float64Counter.Add(ctx, incr, *o...)
145 }
146
147 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
148 // convention. It represents the CPU mode for this data point. A container's CPU
149 // metric SHOULD be characterized *either* by data points with no `mode` labels,
150 // *or only* data points with `mode` labels.
151 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
152 return attribute.String("cpu.mode", string(val))
153 }
154
155 // CPUUsage is an instrument used to record metric values conforming to the
156 // "container.cpu.usage" semantic conventions. It represents the container's CPU
157 // usage, measured in cpus. Range from 0 to the number of allocatable CPUs.
158 type CPUUsage struct {
159 metric.Int64Gauge
160 }
161
162 // NewCPUUsage returns a new CPUUsage instrument.
163 func NewCPUUsage(
164 m metric.Meter,
165 opt ...metric.Int64GaugeOption,
166 ) (CPUUsage, error) {
167 // Check if the meter is nil.
168 if m == nil {
169 return CPUUsage{noop.Int64Gauge{}}, nil
170 }
171
172 i, err := m.Int64Gauge(
173 "container.cpu.usage",
174 append([]metric.Int64GaugeOption{
175 metric.WithDescription("Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs"),
176 metric.WithUnit("{cpu}"),
177 }, opt...)...,
178 )
179 if err != nil {
180 return CPUUsage{noop.Int64Gauge{}}, err
181 }
182 return CPUUsage{i}, nil
183 }
184
185 // Inst returns the underlying metric instrument.
186 func (m CPUUsage) Inst() metric.Int64Gauge {
187 return m.Int64Gauge
188 }
189
190 // Name returns the semantic convention name of the instrument.
191 func (CPUUsage) Name() string {
192 return "container.cpu.usage"
193 }
194
195 // Unit returns the semantic convention unit of the instrument
196 func (CPUUsage) Unit() string {
197 return "{cpu}"
198 }
199
200 // Description returns the semantic convention description of the instrument
201 func (CPUUsage) Description() string {
202 return "Container's CPU usage, measured in cpus. Range from 0 to the number of allocatable CPUs"
203 }
204
205 // Record records val to the current distribution.
206 //
207 // All additional attrs passed are included in the recorded value.
208 //
209 // CPU usage of the specific container on all available CPU cores, averaged over
210 // the sample window
211 func (m CPUUsage) Record(
212 ctx context.Context,
213 val int64,
214 attrs ...attribute.KeyValue,
215 ) {
216 o := recOptPool.Get().(*[]metric.RecordOption)
217 defer func() {
218 *o = (*o)[:0]
219 recOptPool.Put(o)
220 }()
221
222 *o = append(
223 *o,
224 metric.WithAttributes(
225 attrs...,
226 ),
227 )
228
229 m.Int64Gauge.Record(ctx, val, *o...)
230 }
231
232 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
233 // convention. It represents the CPU mode for this data point. A container's CPU
234 // metric SHOULD be characterized *either* by data points with no `mode` labels,
235 // *or only* data points with `mode` labels.
236 func (CPUUsage) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
237 return attribute.String("cpu.mode", string(val))
238 }
239
240 // DiskIO is an instrument used to record metric values conforming to the
241 // "container.disk.io" semantic conventions. It represents the disk bytes for the
242 // container.
243 type DiskIO struct {
244 metric.Int64Counter
245 }
246
247 // NewDiskIO returns a new DiskIO instrument.
248 func NewDiskIO(
249 m metric.Meter,
250 opt ...metric.Int64CounterOption,
251 ) (DiskIO, error) {
252 // Check if the meter is nil.
253 if m == nil {
254 return DiskIO{noop.Int64Counter{}}, nil
255 }
256
257 i, err := m.Int64Counter(
258 "container.disk.io",
259 append([]metric.Int64CounterOption{
260 metric.WithDescription("Disk bytes for the container."),
261 metric.WithUnit("By"),
262 }, opt...)...,
263 )
264 if err != nil {
265 return DiskIO{noop.Int64Counter{}}, err
266 }
267 return DiskIO{i}, nil
268 }
269
270 // Inst returns the underlying metric instrument.
271 func (m DiskIO) Inst() metric.Int64Counter {
272 return m.Int64Counter
273 }
274
275 // Name returns the semantic convention name of the instrument.
276 func (DiskIO) Name() string {
277 return "container.disk.io"
278 }
279
280 // Unit returns the semantic convention unit of the instrument
281 func (DiskIO) Unit() string {
282 return "By"
283 }
284
285 // Description returns the semantic convention description of the instrument
286 func (DiskIO) Description() string {
287 return "Disk bytes for the container."
288 }
289
290 // Add adds incr to the existing count.
291 //
292 // All additional attrs passed are included in the recorded value.
293 //
294 // The total number of bytes read/written successfully (aggregated from all
295 // disks).
296 func (m DiskIO) Add(
297 ctx context.Context,
298 incr int64,
299 attrs ...attribute.KeyValue,
300 ) {
301 o := addOptPool.Get().(*[]metric.AddOption)
302 defer func() {
303 *o = (*o)[:0]
304 addOptPool.Put(o)
305 }()
306
307 *o = append(
308 *o,
309 metric.WithAttributes(
310 attrs...,
311 ),
312 )
313
314 m.Int64Counter.Add(ctx, incr, *o...)
315 }
316
317 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
318 // semantic convention. It represents the disk IO operation direction.
319 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
320 return attribute.String("disk.io.direction", string(val))
321 }
322
323 // AttrSystemDevice returns an optional attribute for the "system.device"
324 // semantic convention. It represents the device identifier.
325 func (DiskIO) AttrSystemDevice(val string) attribute.KeyValue {
326 return attribute.String("system.device", val)
327 }
328
329 // MemoryUsage is an instrument used to record metric values conforming to the
330 // "container.memory.usage" semantic conventions. It represents the memory usage
331 // of the container.
332 type MemoryUsage struct {
333 metric.Int64Counter
334 }
335
336 // NewMemoryUsage returns a new MemoryUsage instrument.
337 func NewMemoryUsage(
338 m metric.Meter,
339 opt ...metric.Int64CounterOption,
340 ) (MemoryUsage, error) {
341 // Check if the meter is nil.
342 if m == nil {
343 return MemoryUsage{noop.Int64Counter{}}, nil
344 }
345
346 i, err := m.Int64Counter(
347 "container.memory.usage",
348 append([]metric.Int64CounterOption{
349 metric.WithDescription("Memory usage of the container."),
350 metric.WithUnit("By"),
351 }, opt...)...,
352 )
353 if err != nil {
354 return MemoryUsage{noop.Int64Counter{}}, err
355 }
356 return MemoryUsage{i}, nil
357 }
358
359 // Inst returns the underlying metric instrument.
360 func (m MemoryUsage) Inst() metric.Int64Counter {
361 return m.Int64Counter
362 }
363
364 // Name returns the semantic convention name of the instrument.
365 func (MemoryUsage) Name() string {
366 return "container.memory.usage"
367 }
368
369 // Unit returns the semantic convention unit of the instrument
370 func (MemoryUsage) Unit() string {
371 return "By"
372 }
373
374 // Description returns the semantic convention description of the instrument
375 func (MemoryUsage) Description() string {
376 return "Memory usage of the container."
377 }
378
379 // Add adds incr to the existing count.
380 //
381 // Memory usage of the container.
382 func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
383 if len(attrs) == 0 {
384 m.Int64Counter.Add(ctx, incr)
385 return
386 }
387
388 o := addOptPool.Get().(*[]metric.AddOption)
389 defer func() {
390 *o = (*o)[:0]
391 addOptPool.Put(o)
392 }()
393
394 *o = append(*o, metric.WithAttributes(attrs...))
395 m.Int64Counter.Add(ctx, incr, *o...)
396 }
397
398 // NetworkIO is an instrument used to record metric values conforming to the
399 // "container.network.io" semantic conventions. It represents the network bytes
400 // for the container.
401 type NetworkIO struct {
402 metric.Int64Counter
403 }
404
405 // NewNetworkIO returns a new NetworkIO instrument.
406 func NewNetworkIO(
407 m metric.Meter,
408 opt ...metric.Int64CounterOption,
409 ) (NetworkIO, error) {
410 // Check if the meter is nil.
411 if m == nil {
412 return NetworkIO{noop.Int64Counter{}}, nil
413 }
414
415 i, err := m.Int64Counter(
416 "container.network.io",
417 append([]metric.Int64CounterOption{
418 metric.WithDescription("Network bytes for the container."),
419 metric.WithUnit("By"),
420 }, opt...)...,
421 )
422 if err != nil {
423 return NetworkIO{noop.Int64Counter{}}, err
424 }
425 return NetworkIO{i}, nil
426 }
427
428 // Inst returns the underlying metric instrument.
429 func (m NetworkIO) Inst() metric.Int64Counter {
430 return m.Int64Counter
431 }
432
433 // Name returns the semantic convention name of the instrument.
434 func (NetworkIO) Name() string {
435 return "container.network.io"
436 }
437
438 // Unit returns the semantic convention unit of the instrument
439 func (NetworkIO) Unit() string {
440 return "By"
441 }
442
443 // Description returns the semantic convention description of the instrument
444 func (NetworkIO) Description() string {
445 return "Network bytes for the container."
446 }
447
448 // Add adds incr to the existing count.
449 //
450 // All additional attrs passed are included in the recorded value.
451 //
452 // The number of bytes sent/received on all network interfaces by the container.
453 func (m NetworkIO) Add(
454 ctx context.Context,
455 incr int64,
456 attrs ...attribute.KeyValue,
457 ) {
458 o := addOptPool.Get().(*[]metric.AddOption)
459 defer func() {
460 *o = (*o)[:0]
461 addOptPool.Put(o)
462 }()
463
464 *o = append(
465 *o,
466 metric.WithAttributes(
467 attrs...,
468 ),
469 )
470
471 m.Int64Counter.Add(ctx, incr, *o...)
472 }
473
474 // AttrNetworkInterfaceName returns an optional attribute for the
475 // "network.interface.name" semantic convention. It represents the network
476 // interface name.
477 func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
478 return attribute.String("network.interface.name", val)
479 }
480
481 // AttrNetworkIODirection returns an optional attribute for the
482 // "network.io.direction" semantic convention. It represents the network IO
483 // operation direction.
484 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
485 return attribute.String("network.io.direction", string(val))
486 }
487
488 // Uptime is an instrument used to record metric values conforming to the
489 // "container.uptime" semantic conventions. It represents the time the container
490 // has been running.
491 type Uptime struct {
492 metric.Float64Gauge
493 }
494
495 // NewUptime returns a new Uptime instrument.
496 func NewUptime(
497 m metric.Meter,
498 opt ...metric.Float64GaugeOption,
499 ) (Uptime, error) {
500 // Check if the meter is nil.
501 if m == nil {
502 return Uptime{noop.Float64Gauge{}}, nil
503 }
504
505 i, err := m.Float64Gauge(
506 "container.uptime",
507 append([]metric.Float64GaugeOption{
508 metric.WithDescription("The time the container has been running"),
509 metric.WithUnit("s"),
510 }, opt...)...,
511 )
512 if err != nil {
513 return Uptime{noop.Float64Gauge{}}, err
514 }
515 return Uptime{i}, nil
516 }
517
518 // Inst returns the underlying metric instrument.
519 func (m Uptime) Inst() metric.Float64Gauge {
520 return m.Float64Gauge
521 }
522
523 // Name returns the semantic convention name of the instrument.
524 func (Uptime) Name() string {
525 return "container.uptime"
526 }
527
528 // Unit returns the semantic convention unit of the instrument
529 func (Uptime) Unit() string {
530 return "s"
531 }
532
533 // Description returns the semantic convention description of the instrument
534 func (Uptime) Description() string {
535 return "The time the container has been running"
536 }
537
538 // Record records val to the current distribution.
539 //
540 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
541 // seconds as a floating point number with the highest precision available.
542 // The actual accuracy would depend on the instrumentation and operating system.
543 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
544 if len(attrs) == 0 {
545 m.Float64Gauge.Record(ctx, val)
546 }
547
548 o := recOptPool.Get().(*[]metric.RecordOption)
549 defer func() {
550 *o = (*o)[:0]
551 recOptPool.Put(o)
552 }()
553
554 *o = append(*o, metric.WithAttributes(attrs...))
555 m.Float64Gauge.Record(ctx, val, *o...)
556 }