Debian Codegraph @

semconv/v1.33.0/systemconv/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 systemconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "system" namespace.
8 package systemconv
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 // DiskIODirectionAttr is an attribute conforming to the disk.io.direction
25 // semantic conventions. It represents the disk IO operation direction.
26 type DiskIODirectionAttr string
27
28 var (
29 // DiskIODirectionRead is the none.
30 DiskIODirectionRead DiskIODirectionAttr = "read"
31 // DiskIODirectionWrite is the none.
32 DiskIODirectionWrite DiskIODirectionAttr = "write"
33 )
34
35 // LinuxMemorySlabStateAttr is an attribute conforming to the
36 // linux.memory.slab.state semantic conventions. It represents the Linux Slab
37 // memory state.
38 type LinuxMemorySlabStateAttr string
39
40 var (
41 // LinuxMemorySlabStateReclaimable is the none.
42 LinuxMemorySlabStateReclaimable LinuxMemorySlabStateAttr = "reclaimable"
43 // LinuxMemorySlabStateUnreclaimable is the none.
44 LinuxMemorySlabStateUnreclaimable LinuxMemorySlabStateAttr = "unreclaimable"
45 )
46
47 // NetworkConnectionStateAttr is an attribute conforming to the
48 // network.connection.state semantic conventions. It represents the state of
49 // network connection.
50 type NetworkConnectionStateAttr string
51
52 var (
53 // NetworkConnectionStateClosed is the none.
54 NetworkConnectionStateClosed NetworkConnectionStateAttr = "closed"
55 // NetworkConnectionStateCloseWait is the none.
56 NetworkConnectionStateCloseWait NetworkConnectionStateAttr = "close_wait"
57 // NetworkConnectionStateClosing is the none.
58 NetworkConnectionStateClosing NetworkConnectionStateAttr = "closing"
59 // NetworkConnectionStateEstablished is the none.
60 NetworkConnectionStateEstablished NetworkConnectionStateAttr = "established"
61 // NetworkConnectionStateFinWait1 is the none.
62 NetworkConnectionStateFinWait1 NetworkConnectionStateAttr = "fin_wait_1"
63 // NetworkConnectionStateFinWait2 is the none.
64 NetworkConnectionStateFinWait2 NetworkConnectionStateAttr = "fin_wait_2"
65 // NetworkConnectionStateLastAck is the none.
66 NetworkConnectionStateLastAck NetworkConnectionStateAttr = "last_ack"
67 // NetworkConnectionStateListen is the none.
68 NetworkConnectionStateListen NetworkConnectionStateAttr = "listen"
69 // NetworkConnectionStateSynReceived is the none.
70 NetworkConnectionStateSynReceived NetworkConnectionStateAttr = "syn_received"
71 // NetworkConnectionStateSynSent is the none.
72 NetworkConnectionStateSynSent NetworkConnectionStateAttr = "syn_sent"
73 // NetworkConnectionStateTimeWait is the none.
74 NetworkConnectionStateTimeWait NetworkConnectionStateAttr = "time_wait"
75 )
76
77 // NetworkIODirectionAttr is an attribute conforming to the network.io.direction
78 // semantic conventions. It represents the network IO operation direction.
79 type NetworkIODirectionAttr string
80
81 var (
82 // NetworkIODirectionTransmit is the none.
83 NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
84 // NetworkIODirectionReceive is the none.
85 NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
86 )
87
88 // NetworkTransportAttr is an attribute conforming to the network.transport
89 // semantic conventions. It represents the [OSI transport layer] or
90 // [inter-process communication method].
91 //
92 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
93 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
94 type NetworkTransportAttr string
95
96 var (
97 // NetworkTransportTCP is the TCP.
98 NetworkTransportTCP NetworkTransportAttr = "tcp"
99 // NetworkTransportUDP is the UDP.
100 NetworkTransportUDP NetworkTransportAttr = "udp"
101 // NetworkTransportPipe is the named or anonymous pipe.
102 NetworkTransportPipe NetworkTransportAttr = "pipe"
103 // NetworkTransportUnix is the unix domain socket.
104 NetworkTransportUnix NetworkTransportAttr = "unix"
105 // NetworkTransportQUIC is the QUIC.
106 NetworkTransportQUIC NetworkTransportAttr = "quic"
107 )
108
109 // FilesystemStateAttr is an attribute conforming to the system.filesystem.state
110 // semantic conventions. It represents the filesystem state.
111 type FilesystemStateAttr string
112
113 var (
114 // FilesystemStateUsed is the none.
115 FilesystemStateUsed FilesystemStateAttr = "used"
116 // FilesystemStateFree is the none.
117 FilesystemStateFree FilesystemStateAttr = "free"
118 // FilesystemStateReserved is the none.
119 FilesystemStateReserved FilesystemStateAttr = "reserved"
120 )
121
122 // FilesystemTypeAttr is an attribute conforming to the system.filesystem.type
123 // semantic conventions. It represents the filesystem type.
124 type FilesystemTypeAttr string
125
126 var (
127 // FilesystemTypeFat32 is the none.
128 FilesystemTypeFat32 FilesystemTypeAttr = "fat32"
129 // FilesystemTypeExfat is the none.
130 FilesystemTypeExfat FilesystemTypeAttr = "exfat"
131 // FilesystemTypeNtfs is the none.
132 FilesystemTypeNtfs FilesystemTypeAttr = "ntfs"
133 // FilesystemTypeRefs is the none.
134 FilesystemTypeRefs FilesystemTypeAttr = "refs"
135 // FilesystemTypeHfsplus is the none.
136 FilesystemTypeHfsplus FilesystemTypeAttr = "hfsplus"
137 // FilesystemTypeExt4 is the none.
138 FilesystemTypeExt4 FilesystemTypeAttr = "ext4"
139 )
140
141 // MemoryStateAttr is an attribute conforming to the system.memory.state semantic
142 // conventions. It represents the memory state.
143 type MemoryStateAttr string
144
145 var (
146 // MemoryStateUsed is the none.
147 MemoryStateUsed MemoryStateAttr = "used"
148 // MemoryStateFree is the none.
149 MemoryStateFree MemoryStateAttr = "free"
150 // MemoryStateBuffers is the none.
151 MemoryStateBuffers MemoryStateAttr = "buffers"
152 // MemoryStateCached is the none.
153 MemoryStateCached MemoryStateAttr = "cached"
154 )
155
156 // PagingDirectionAttr is an attribute conforming to the system.paging.direction
157 // semantic conventions. It represents the paging access direction.
158 type PagingDirectionAttr string
159
160 var (
161 // PagingDirectionIn is the none.
162 PagingDirectionIn PagingDirectionAttr = "in"
163 // PagingDirectionOut is the none.
164 PagingDirectionOut PagingDirectionAttr = "out"
165 )
166
167 // PagingStateAttr is an attribute conforming to the system.paging.state semantic
168 // conventions. It represents the memory paging state.
169 type PagingStateAttr string
170
171 var (
172 // PagingStateUsed is the none.
173 PagingStateUsed PagingStateAttr = "used"
174 // PagingStateFree is the none.
175 PagingStateFree PagingStateAttr = "free"
176 )
177
178 // PagingTypeAttr is an attribute conforming to the system.paging.type semantic
179 // conventions. It represents the memory paging type.
180 type PagingTypeAttr string
181
182 var (
183 // PagingTypeMajor is the none.
184 PagingTypeMajor PagingTypeAttr = "major"
185 // PagingTypeMinor is the none.
186 PagingTypeMinor PagingTypeAttr = "minor"
187 )
188
189 // ProcessStatusAttr is an attribute conforming to the system.process.status
190 // semantic conventions. It represents the process state, e.g.,
191 // [Linux Process State Codes].
192 //
193 // [Linux Process State Codes]: https://man7.org/linux/man-pages/man1/ps.1.html#PROCESS_STATE_CODES
194 type ProcessStatusAttr string
195
196 var (
197 // ProcessStatusRunning is the none.
198 ProcessStatusRunning ProcessStatusAttr = "running"
199 // ProcessStatusSleeping is the none.
200 ProcessStatusSleeping ProcessStatusAttr = "sleeping"
201 // ProcessStatusStopped is the none.
202 ProcessStatusStopped ProcessStatusAttr = "stopped"
203 // ProcessStatusDefunct is the none.
204 ProcessStatusDefunct ProcessStatusAttr = "defunct"
205 )
206
207 // CPULogicalCount is an instrument used to record metric values conforming to
208 // the "system.cpu.logical.count" semantic conventions. It represents the reports
209 // the number of logical (virtual) processor cores created by the operating
210 // system to manage multitasking.
211 type CPULogicalCount struct {
212 metric.Int64UpDownCounter
213 }
214
215 // NewCPULogicalCount returns a new CPULogicalCount instrument.
216 func NewCPULogicalCount(
217 m metric.Meter,
218 opt ...metric.Int64UpDownCounterOption,
219 ) (CPULogicalCount, error) {
220 // Check if the meter is nil.
221 if m == nil {
222 return CPULogicalCount{noop.Int64UpDownCounter{}}, nil
223 }
224
225 i, err := m.Int64UpDownCounter(
226 "system.cpu.logical.count",
227 append([]metric.Int64UpDownCounterOption{
228 metric.WithDescription("Reports the number of logical (virtual) processor cores created by the operating system to manage multitasking"),
229 metric.WithUnit("{cpu}"),
230 }, opt...)...,
231 )
232 if err != nil {
233 return CPULogicalCount{noop.Int64UpDownCounter{}}, err
234 }
235 return CPULogicalCount{i}, nil
236 }
237
238 // Inst returns the underlying metric instrument.
239 func (m CPULogicalCount) Inst() metric.Int64UpDownCounter {
240 return m.Int64UpDownCounter
241 }
242
243 // Name returns the semantic convention name of the instrument.
244 func (CPULogicalCount) Name() string {
245 return "system.cpu.logical.count"
246 }
247
248 // Unit returns the semantic convention unit of the instrument
249 func (CPULogicalCount) Unit() string {
250 return "{cpu}"
251 }
252
253 // Description returns the semantic convention description of the instrument
254 func (CPULogicalCount) Description() string {
255 return "Reports the number of logical (virtual) processor cores created by the operating system to manage multitasking"
256 }
257
258 // Add adds incr to the existing count.
259 //
260 // Calculated by multiplying the number of sockets by the number of cores per
261 // socket, and then by the number of threads per core
262 func (m CPULogicalCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
263 if len(attrs) == 0 {
264 m.Int64UpDownCounter.Add(ctx, incr)
265 return
266 }
267
268 o := addOptPool.Get().(*[]metric.AddOption)
269 defer func() {
270 *o = (*o)[:0]
271 addOptPool.Put(o)
272 }()
273
274 *o = append(*o, metric.WithAttributes(attrs...))
275 m.Int64UpDownCounter.Add(ctx, incr, *o...)
276 }
277
278 // CPUPhysicalCount is an instrument used to record metric values conforming to
279 // the "system.cpu.physical.count" semantic conventions. It represents the
280 // reports the number of actual physical processor cores on the hardware.
281 type CPUPhysicalCount struct {
282 metric.Int64UpDownCounter
283 }
284
285 // NewCPUPhysicalCount returns a new CPUPhysicalCount instrument.
286 func NewCPUPhysicalCount(
287 m metric.Meter,
288 opt ...metric.Int64UpDownCounterOption,
289 ) (CPUPhysicalCount, error) {
290 // Check if the meter is nil.
291 if m == nil {
292 return CPUPhysicalCount{noop.Int64UpDownCounter{}}, nil
293 }
294
295 i, err := m.Int64UpDownCounter(
296 "system.cpu.physical.count",
297 append([]metric.Int64UpDownCounterOption{
298 metric.WithDescription("Reports the number of actual physical processor cores on the hardware"),
299 metric.WithUnit("{cpu}"),
300 }, opt...)...,
301 )
302 if err != nil {
303 return CPUPhysicalCount{noop.Int64UpDownCounter{}}, err
304 }
305 return CPUPhysicalCount{i}, nil
306 }
307
308 // Inst returns the underlying metric instrument.
309 func (m CPUPhysicalCount) Inst() metric.Int64UpDownCounter {
310 return m.Int64UpDownCounter
311 }
312
313 // Name returns the semantic convention name of the instrument.
314 func (CPUPhysicalCount) Name() string {
315 return "system.cpu.physical.count"
316 }
317
318 // Unit returns the semantic convention unit of the instrument
319 func (CPUPhysicalCount) Unit() string {
320 return "{cpu}"
321 }
322
323 // Description returns the semantic convention description of the instrument
324 func (CPUPhysicalCount) Description() string {
325 return "Reports the number of actual physical processor cores on the hardware"
326 }
327
328 // Add adds incr to the existing count.
329 //
330 // Calculated by multiplying the number of sockets by the number of cores per
331 // socket
332 func (m CPUPhysicalCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
333 if len(attrs) == 0 {
334 m.Int64UpDownCounter.Add(ctx, incr)
335 return
336 }
337
338 o := addOptPool.Get().(*[]metric.AddOption)
339 defer func() {
340 *o = (*o)[:0]
341 addOptPool.Put(o)
342 }()
343
344 *o = append(*o, metric.WithAttributes(attrs...))
345 m.Int64UpDownCounter.Add(ctx, incr, *o...)
346 }
347
348 // DiskIO is an instrument used to record metric values conforming to the
349 // "system.disk.io" semantic conventions.
350 type DiskIO struct {
351 metric.Int64Counter
352 }
353
354 // NewDiskIO returns a new DiskIO instrument.
355 func NewDiskIO(
356 m metric.Meter,
357 opt ...metric.Int64CounterOption,
358 ) (DiskIO, error) {
359 // Check if the meter is nil.
360 if m == nil {
361 return DiskIO{noop.Int64Counter{}}, nil
362 }
363
364 i, err := m.Int64Counter(
365 "system.disk.io",
366 append([]metric.Int64CounterOption{
367 metric.WithDescription(""),
368 metric.WithUnit("By"),
369 }, opt...)...,
370 )
371 if err != nil {
372 return DiskIO{noop.Int64Counter{}}, err
373 }
374 return DiskIO{i}, nil
375 }
376
377 // Inst returns the underlying metric instrument.
378 func (m DiskIO) Inst() metric.Int64Counter {
379 return m.Int64Counter
380 }
381
382 // Name returns the semantic convention name of the instrument.
383 func (DiskIO) Name() string {
384 return "system.disk.io"
385 }
386
387 // Unit returns the semantic convention unit of the instrument
388 func (DiskIO) Unit() string {
389 return "By"
390 }
391
392 // Add adds incr to the existing count.
393 //
394 // All additional attrs passed are included in the recorded value.
395 func (m DiskIO) Add(
396 ctx context.Context,
397 incr int64,
398 attrs ...attribute.KeyValue,
399 ) {
400 o := addOptPool.Get().(*[]metric.AddOption)
401 defer func() {
402 *o = (*o)[:0]
403 addOptPool.Put(o)
404 }()
405
406 *o = append(
407 *o,
408 metric.WithAttributes(
409 attrs...,
410 ),
411 )
412
413 m.Int64Counter.Add(ctx, incr, *o...)
414 }
415
416 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
417 // semantic convention. It represents the disk IO operation direction.
418 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
419 return attribute.String("disk.io.direction", string(val))
420 }
421
422 // AttrDevice returns an optional attribute for the "system.device" semantic
423 // convention. It represents the device identifier.
424 func (DiskIO) AttrDevice(val string) attribute.KeyValue {
425 return attribute.String("system.device", val)
426 }
427
428 // DiskIOTime is an instrument used to record metric values conforming to the
429 // "system.disk.io_time" semantic conventions. It represents the time disk spent
430 // activated.
431 type DiskIOTime struct {
432 metric.Float64Counter
433 }
434
435 // NewDiskIOTime returns a new DiskIOTime instrument.
436 func NewDiskIOTime(
437 m metric.Meter,
438 opt ...metric.Float64CounterOption,
439 ) (DiskIOTime, error) {
440 // Check if the meter is nil.
441 if m == nil {
442 return DiskIOTime{noop.Float64Counter{}}, nil
443 }
444
445 i, err := m.Float64Counter(
446 "system.disk.io_time",
447 append([]metric.Float64CounterOption{
448 metric.WithDescription("Time disk spent activated"),
449 metric.WithUnit("s"),
450 }, opt...)...,
451 )
452 if err != nil {
453 return DiskIOTime{noop.Float64Counter{}}, err
454 }
455 return DiskIOTime{i}, nil
456 }
457
458 // Inst returns the underlying metric instrument.
459 func (m DiskIOTime) Inst() metric.Float64Counter {
460 return m.Float64Counter
461 }
462
463 // Name returns the semantic convention name of the instrument.
464 func (DiskIOTime) Name() string {
465 return "system.disk.io_time"
466 }
467
468 // Unit returns the semantic convention unit of the instrument
469 func (DiskIOTime) Unit() string {
470 return "s"
471 }
472
473 // Description returns the semantic convention description of the instrument
474 func (DiskIOTime) Description() string {
475 return "Time disk spent activated"
476 }
477
478 // Add adds incr to the existing count.
479 //
480 // All additional attrs passed are included in the recorded value.
481 //
482 // The real elapsed time ("wall clock") used in the I/O path (time from
483 // operations running in parallel are not counted). Measured as:
484 //
485 // - Linux: Field 13 from [procfs-diskstats]
486 // - Windows: The complement of
487 // ["Disk% Idle Time"]
488 // performance counter: `uptime * (100 - "Disk\% Idle Time") / 100`
489 //
490 //
491 // [procfs-diskstats]: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
492 // ["Disk% Idle Time"]: https://learn.microsoft.com/archive/blogs/askcore/windows-performance-monitor-disk-counters-explained#windows-performance-monitor-disk-counters-explained
493 func (m DiskIOTime) Add(
494 ctx context.Context,
495 incr float64,
496 attrs ...attribute.KeyValue,
497 ) {
498 o := addOptPool.Get().(*[]metric.AddOption)
499 defer func() {
500 *o = (*o)[:0]
501 addOptPool.Put(o)
502 }()
503
504 *o = append(
505 *o,
506 metric.WithAttributes(
507 attrs...,
508 ),
509 )
510
511 m.Float64Counter.Add(ctx, incr, *o...)
512 }
513
514 // AttrDevice returns an optional attribute for the "system.device" semantic
515 // convention. It represents the device identifier.
516 func (DiskIOTime) AttrDevice(val string) attribute.KeyValue {
517 return attribute.String("system.device", val)
518 }
519
520 // DiskLimit is an instrument used to record metric values conforming to the
521 // "system.disk.limit" semantic conventions. It represents the total storage
522 // capacity of the disk.
523 type DiskLimit struct {
524 metric.Int64UpDownCounter
525 }
526
527 // NewDiskLimit returns a new DiskLimit instrument.
528 func NewDiskLimit(
529 m metric.Meter,
530 opt ...metric.Int64UpDownCounterOption,
531 ) (DiskLimit, error) {
532 // Check if the meter is nil.
533 if m == nil {
534 return DiskLimit{noop.Int64UpDownCounter{}}, nil
535 }
536
537 i, err := m.Int64UpDownCounter(
538 "system.disk.limit",
539 append([]metric.Int64UpDownCounterOption{
540 metric.WithDescription("The total storage capacity of the disk"),
541 metric.WithUnit("By"),
542 }, opt...)...,
543 )
544 if err != nil {
545 return DiskLimit{noop.Int64UpDownCounter{}}, err
546 }
547 return DiskLimit{i}, nil
548 }
549
550 // Inst returns the underlying metric instrument.
551 func (m DiskLimit) Inst() metric.Int64UpDownCounter {
552 return m.Int64UpDownCounter
553 }
554
555 // Name returns the semantic convention name of the instrument.
556 func (DiskLimit) Name() string {
557 return "system.disk.limit"
558 }
559
560 // Unit returns the semantic convention unit of the instrument
561 func (DiskLimit) Unit() string {
562 return "By"
563 }
564
565 // Description returns the semantic convention description of the instrument
566 func (DiskLimit) Description() string {
567 return "The total storage capacity of the disk"
568 }
569
570 // Add adds incr to the existing count.
571 //
572 // All additional attrs passed are included in the recorded value.
573 func (m DiskLimit) Add(
574 ctx context.Context,
575 incr int64,
576 attrs ...attribute.KeyValue,
577 ) {
578 o := addOptPool.Get().(*[]metric.AddOption)
579 defer func() {
580 *o = (*o)[:0]
581 addOptPool.Put(o)
582 }()
583
584 *o = append(
585 *o,
586 metric.WithAttributes(
587 attrs...,
588 ),
589 )
590
591 m.Int64UpDownCounter.Add(ctx, incr, *o...)
592 }
593
594 // AttrDevice returns an optional attribute for the "system.device" semantic
595 // convention. It represents the device identifier.
596 func (DiskLimit) AttrDevice(val string) attribute.KeyValue {
597 return attribute.String("system.device", val)
598 }
599
600 // DiskMerged is an instrument used to record metric values conforming to the
601 // "system.disk.merged" semantic conventions.
602 type DiskMerged struct {
603 metric.Int64Counter
604 }
605
606 // NewDiskMerged returns a new DiskMerged instrument.
607 func NewDiskMerged(
608 m metric.Meter,
609 opt ...metric.Int64CounterOption,
610 ) (DiskMerged, error) {
611 // Check if the meter is nil.
612 if m == nil {
613 return DiskMerged{noop.Int64Counter{}}, nil
614 }
615
616 i, err := m.Int64Counter(
617 "system.disk.merged",
618 append([]metric.Int64CounterOption{
619 metric.WithDescription(""),
620 metric.WithUnit("{operation}"),
621 }, opt...)...,
622 )
623 if err != nil {
624 return DiskMerged{noop.Int64Counter{}}, err
625 }
626 return DiskMerged{i}, nil
627 }
628
629 // Inst returns the underlying metric instrument.
630 func (m DiskMerged) Inst() metric.Int64Counter {
631 return m.Int64Counter
632 }
633
634 // Name returns the semantic convention name of the instrument.
635 func (DiskMerged) Name() string {
636 return "system.disk.merged"
637 }
638
639 // Unit returns the semantic convention unit of the instrument
640 func (DiskMerged) Unit() string {
641 return "{operation}"
642 }
643
644 // Add adds incr to the existing count.
645 //
646 // All additional attrs passed are included in the recorded value.
647 func (m DiskMerged) Add(
648 ctx context.Context,
649 incr int64,
650 attrs ...attribute.KeyValue,
651 ) {
652 o := addOptPool.Get().(*[]metric.AddOption)
653 defer func() {
654 *o = (*o)[:0]
655 addOptPool.Put(o)
656 }()
657
658 *o = append(
659 *o,
660 metric.WithAttributes(
661 attrs...,
662 ),
663 )
664
665 m.Int64Counter.Add(ctx, incr, *o...)
666 }
667
668 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
669 // semantic convention. It represents the disk IO operation direction.
670 func (DiskMerged) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
671 return attribute.String("disk.io.direction", string(val))
672 }
673
674 // AttrDevice returns an optional attribute for the "system.device" semantic
675 // convention. It represents the device identifier.
676 func (DiskMerged) AttrDevice(val string) attribute.KeyValue {
677 return attribute.String("system.device", val)
678 }
679
680 // DiskOperationTime is an instrument used to record metric values conforming to
681 // the "system.disk.operation_time" semantic conventions. It represents the sum
682 // of the time each operation took to complete.
683 type DiskOperationTime struct {
684 metric.Float64Counter
685 }
686
687 // NewDiskOperationTime returns a new DiskOperationTime instrument.
688 func NewDiskOperationTime(
689 m metric.Meter,
690 opt ...metric.Float64CounterOption,
691 ) (DiskOperationTime, error) {
692 // Check if the meter is nil.
693 if m == nil {
694 return DiskOperationTime{noop.Float64Counter{}}, nil
695 }
696
697 i, err := m.Float64Counter(
698 "system.disk.operation_time",
699 append([]metric.Float64CounterOption{
700 metric.WithDescription("Sum of the time each operation took to complete"),
701 metric.WithUnit("s"),
702 }, opt...)...,
703 )
704 if err != nil {
705 return DiskOperationTime{noop.Float64Counter{}}, err
706 }
707 return DiskOperationTime{i}, nil
708 }
709
710 // Inst returns the underlying metric instrument.
711 func (m DiskOperationTime) Inst() metric.Float64Counter {
712 return m.Float64Counter
713 }
714
715 // Name returns the semantic convention name of the instrument.
716 func (DiskOperationTime) Name() string {
717 return "system.disk.operation_time"
718 }
719
720 // Unit returns the semantic convention unit of the instrument
721 func (DiskOperationTime) Unit() string {
722 return "s"
723 }
724
725 // Description returns the semantic convention description of the instrument
726 func (DiskOperationTime) Description() string {
727 return "Sum of the time each operation took to complete"
728 }
729
730 // Add adds incr to the existing count.
731 //
732 // All additional attrs passed are included in the recorded value.
733 //
734 // Because it is the sum of time each request took, parallel-issued requests each
735 // contribute to make the count grow. Measured as:
736 //
737 // - Linux: Fields 7 & 11 from [procfs-diskstats]
738 // - Windows: "Avg. Disk sec/Read" perf counter multiplied by "Disk Reads/sec"
739 // perf counter (similar for Writes)
740 //
741 //
742 // [procfs-diskstats]: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
743 func (m DiskOperationTime) Add(
744 ctx context.Context,
745 incr float64,
746 attrs ...attribute.KeyValue,
747 ) {
748 o := addOptPool.Get().(*[]metric.AddOption)
749 defer func() {
750 *o = (*o)[:0]
751 addOptPool.Put(o)
752 }()
753
754 *o = append(
755 *o,
756 metric.WithAttributes(
757 attrs...,
758 ),
759 )
760
761 m.Float64Counter.Add(ctx, incr, *o...)
762 }
763
764 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
765 // semantic convention. It represents the disk IO operation direction.
766 func (DiskOperationTime) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
767 return attribute.String("disk.io.direction", string(val))
768 }
769
770 // AttrDevice returns an optional attribute for the "system.device" semantic
771 // convention. It represents the device identifier.
772 func (DiskOperationTime) AttrDevice(val string) attribute.KeyValue {
773 return attribute.String("system.device", val)
774 }
775
776 // DiskOperations is an instrument used to record metric values conforming to the
777 // "system.disk.operations" semantic conventions.
778 type DiskOperations struct {
779 metric.Int64Counter
780 }
781
782 // NewDiskOperations returns a new DiskOperations instrument.
783 func NewDiskOperations(
784 m metric.Meter,
785 opt ...metric.Int64CounterOption,
786 ) (DiskOperations, error) {
787 // Check if the meter is nil.
788 if m == nil {
789 return DiskOperations{noop.Int64Counter{}}, nil
790 }
791
792 i, err := m.Int64Counter(
793 "system.disk.operations",
794 append([]metric.Int64CounterOption{
795 metric.WithDescription(""),
796 metric.WithUnit("{operation}"),
797 }, opt...)...,
798 )
799 if err != nil {
800 return DiskOperations{noop.Int64Counter{}}, err
801 }
802 return DiskOperations{i}, nil
803 }
804
805 // Inst returns the underlying metric instrument.
806 func (m DiskOperations) Inst() metric.Int64Counter {
807 return m.Int64Counter
808 }
809
810 // Name returns the semantic convention name of the instrument.
811 func (DiskOperations) Name() string {
812 return "system.disk.operations"
813 }
814
815 // Unit returns the semantic convention unit of the instrument
816 func (DiskOperations) Unit() string {
817 return "{operation}"
818 }
819
820 // Add adds incr to the existing count.
821 //
822 // All additional attrs passed are included in the recorded value.
823 func (m DiskOperations) Add(
824 ctx context.Context,
825 incr int64,
826 attrs ...attribute.KeyValue,
827 ) {
828 o := addOptPool.Get().(*[]metric.AddOption)
829 defer func() {
830 *o = (*o)[:0]
831 addOptPool.Put(o)
832 }()
833
834 *o = append(
835 *o,
836 metric.WithAttributes(
837 attrs...,
838 ),
839 )
840
841 m.Int64Counter.Add(ctx, incr, *o...)
842 }
843
844 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
845 // semantic convention. It represents the disk IO operation direction.
846 func (DiskOperations) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
847 return attribute.String("disk.io.direction", string(val))
848 }
849
850 // AttrDevice returns an optional attribute for the "system.device" semantic
851 // convention. It represents the device identifier.
852 func (DiskOperations) AttrDevice(val string) attribute.KeyValue {
853 return attribute.String("system.device", val)
854 }
855
856 // FilesystemLimit is an instrument used to record metric values conforming to
857 // the "system.filesystem.limit" semantic conventions. It represents the total
858 // storage capacity of the filesystem.
859 type FilesystemLimit struct {
860 metric.Int64UpDownCounter
861 }
862
863 // NewFilesystemLimit returns a new FilesystemLimit instrument.
864 func NewFilesystemLimit(
865 m metric.Meter,
866 opt ...metric.Int64UpDownCounterOption,
867 ) (FilesystemLimit, error) {
868 // Check if the meter is nil.
869 if m == nil {
870 return FilesystemLimit{noop.Int64UpDownCounter{}}, nil
871 }
872
873 i, err := m.Int64UpDownCounter(
874 "system.filesystem.limit",
875 append([]metric.Int64UpDownCounterOption{
876 metric.WithDescription("The total storage capacity of the filesystem"),
877 metric.WithUnit("By"),
878 }, opt...)...,
879 )
880 if err != nil {
881 return FilesystemLimit{noop.Int64UpDownCounter{}}, err
882 }
883 return FilesystemLimit{i}, nil
884 }
885
886 // Inst returns the underlying metric instrument.
887 func (m FilesystemLimit) Inst() metric.Int64UpDownCounter {
888 return m.Int64UpDownCounter
889 }
890
891 // Name returns the semantic convention name of the instrument.
892 func (FilesystemLimit) Name() string {
893 return "system.filesystem.limit"
894 }
895
896 // Unit returns the semantic convention unit of the instrument
897 func (FilesystemLimit) Unit() string {
898 return "By"
899 }
900
901 // Description returns the semantic convention description of the instrument
902 func (FilesystemLimit) Description() string {
903 return "The total storage capacity of the filesystem"
904 }
905
906 // Add adds incr to the existing count.
907 //
908 // All additional attrs passed are included in the recorded value.
909 func (m FilesystemLimit) Add(
910 ctx context.Context,
911 incr int64,
912 attrs ...attribute.KeyValue,
913 ) {
914 o := addOptPool.Get().(*[]metric.AddOption)
915 defer func() {
916 *o = (*o)[:0]
917 addOptPool.Put(o)
918 }()
919
920 *o = append(
921 *o,
922 metric.WithAttributes(
923 attrs...,
924 ),
925 )
926
927 m.Int64UpDownCounter.Add(ctx, incr, *o...)
928 }
929
930 // AttrDevice returns an optional attribute for the "system.device" semantic
931 // convention. It represents the identifier for the device where the filesystem
932 // resides.
933 func (FilesystemLimit) AttrDevice(val string) attribute.KeyValue {
934 return attribute.String("system.device", val)
935 }
936
937 // AttrFilesystemMode returns an optional attribute for the
938 // "system.filesystem.mode" semantic convention. It represents the filesystem
939 // mode.
940 func (FilesystemLimit) AttrFilesystemMode(val string) attribute.KeyValue {
941 return attribute.String("system.filesystem.mode", val)
942 }
943
944 // AttrFilesystemMountpoint returns an optional attribute for the
945 // "system.filesystem.mountpoint" semantic convention. It represents the
946 // filesystem mount path.
947 func (FilesystemLimit) AttrFilesystemMountpoint(val string) attribute.KeyValue {
948 return attribute.String("system.filesystem.mountpoint", val)
949 }
950
951 // AttrFilesystemType returns an optional attribute for the
952 // "system.filesystem.type" semantic convention. It represents the filesystem
953 // type.
954 func (FilesystemLimit) AttrFilesystemType(val FilesystemTypeAttr) attribute.KeyValue {
955 return attribute.String("system.filesystem.type", string(val))
956 }
957
958 // FilesystemUsage is an instrument used to record metric values conforming to
959 // the "system.filesystem.usage" semantic conventions. It represents the reports
960 // a filesystem's space usage across different states.
961 type FilesystemUsage struct {
962 metric.Int64UpDownCounter
963 }
964
965 // NewFilesystemUsage returns a new FilesystemUsage instrument.
966 func NewFilesystemUsage(
967 m metric.Meter,
968 opt ...metric.Int64UpDownCounterOption,
969 ) (FilesystemUsage, error) {
970 // Check if the meter is nil.
971 if m == nil {
972 return FilesystemUsage{noop.Int64UpDownCounter{}}, nil
973 }
974
975 i, err := m.Int64UpDownCounter(
976 "system.filesystem.usage",
977 append([]metric.Int64UpDownCounterOption{
978 metric.WithDescription("Reports a filesystem's space usage across different states."),
979 metric.WithUnit("By"),
980 }, opt...)...,
981 )
982 if err != nil {
983 return FilesystemUsage{noop.Int64UpDownCounter{}}, err
984 }
985 return FilesystemUsage{i}, nil
986 }
987
988 // Inst returns the underlying metric instrument.
989 func (m FilesystemUsage) Inst() metric.Int64UpDownCounter {
990 return m.Int64UpDownCounter
991 }
992
993 // Name returns the semantic convention name of the instrument.
994 func (FilesystemUsage) Name() string {
995 return "system.filesystem.usage"
996 }
997
998 // Unit returns the semantic convention unit of the instrument
999 func (FilesystemUsage) Unit() string {
1000 return "By"
1001 }
1002
1003 // Description returns the semantic convention description of the instrument
1004 func (FilesystemUsage) Description() string {
1005 return "Reports a filesystem's space usage across different states."
1006 }
1007
1008 // Add adds incr to the existing count.
1009 //
1010 // All additional attrs passed are included in the recorded value.
1011 //
1012 // The sum of all `system.filesystem.usage` values over the different
1013 // `system.filesystem.state` attributes
1014 // SHOULD equal the total storage capacity of the filesystem, that is
1015 // `system.filesystem.limit`.
1016 func (m FilesystemUsage) Add(
1017 ctx context.Context,
1018 incr int64,
1019 attrs ...attribute.KeyValue,
1020 ) {
1021 o := addOptPool.Get().(*[]metric.AddOption)
1022 defer func() {
1023 *o = (*o)[:0]
1024 addOptPool.Put(o)
1025 }()
1026
1027 *o = append(
1028 *o,
1029 metric.WithAttributes(
1030 attrs...,
1031 ),
1032 )
1033
1034 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1035 }
1036
1037 // AttrDevice returns an optional attribute for the "system.device" semantic
1038 // convention. It represents the identifier for the device where the filesystem
1039 // resides.
1040 func (FilesystemUsage) AttrDevice(val string) attribute.KeyValue {
1041 return attribute.String("system.device", val)
1042 }
1043
1044 // AttrFilesystemMode returns an optional attribute for the
1045 // "system.filesystem.mode" semantic convention. It represents the filesystem
1046 // mode.
1047 func (FilesystemUsage) AttrFilesystemMode(val string) attribute.KeyValue {
1048 return attribute.String("system.filesystem.mode", val)
1049 }
1050
1051 // AttrFilesystemMountpoint returns an optional attribute for the
1052 // "system.filesystem.mountpoint" semantic convention. It represents the
1053 // filesystem mount path.
1054 func (FilesystemUsage) AttrFilesystemMountpoint(val string) attribute.KeyValue {
1055 return attribute.String("system.filesystem.mountpoint", val)
1056 }
1057
1058 // AttrFilesystemState returns an optional attribute for the
1059 // "system.filesystem.state" semantic convention. It represents the filesystem
1060 // state.
1061 func (FilesystemUsage) AttrFilesystemState(val FilesystemStateAttr) attribute.KeyValue {
1062 return attribute.String("system.filesystem.state", string(val))
1063 }
1064
1065 // AttrFilesystemType returns an optional attribute for the
1066 // "system.filesystem.type" semantic convention. It represents the filesystem
1067 // type.
1068 func (FilesystemUsage) AttrFilesystemType(val FilesystemTypeAttr) attribute.KeyValue {
1069 return attribute.String("system.filesystem.type", string(val))
1070 }
1071
1072 // FilesystemUtilization is an instrument used to record metric values conforming
1073 // to the "system.filesystem.utilization" semantic conventions.
1074 type FilesystemUtilization struct {
1075 metric.Int64Gauge
1076 }
1077
1078 // NewFilesystemUtilization returns a new FilesystemUtilization instrument.
1079 func NewFilesystemUtilization(
1080 m metric.Meter,
1081 opt ...metric.Int64GaugeOption,
1082 ) (FilesystemUtilization, error) {
1083 // Check if the meter is nil.
1084 if m == nil {
1085 return FilesystemUtilization{noop.Int64Gauge{}}, nil
1086 }
1087
1088 i, err := m.Int64Gauge(
1089 "system.filesystem.utilization",
1090 append([]metric.Int64GaugeOption{
1091 metric.WithDescription(""),
1092 metric.WithUnit("1"),
1093 }, opt...)...,
1094 )
1095 if err != nil {
1096 return FilesystemUtilization{noop.Int64Gauge{}}, err
1097 }
1098 return FilesystemUtilization{i}, nil
1099 }
1100
1101 // Inst returns the underlying metric instrument.
1102 func (m FilesystemUtilization) Inst() metric.Int64Gauge {
1103 return m.Int64Gauge
1104 }
1105
1106 // Name returns the semantic convention name of the instrument.
1107 func (FilesystemUtilization) Name() string {
1108 return "system.filesystem.utilization"
1109 }
1110
1111 // Unit returns the semantic convention unit of the instrument
1112 func (FilesystemUtilization) Unit() string {
1113 return "1"
1114 }
1115
1116 // Record records val to the current distribution.
1117 //
1118 // All additional attrs passed are included in the recorded value.
1119 func (m FilesystemUtilization) Record(
1120 ctx context.Context,
1121 val int64,
1122 attrs ...attribute.KeyValue,
1123 ) {
1124 o := recOptPool.Get().(*[]metric.RecordOption)
1125 defer func() {
1126 *o = (*o)[:0]
1127 recOptPool.Put(o)
1128 }()
1129
1130 *o = append(
1131 *o,
1132 metric.WithAttributes(
1133 attrs...,
1134 ),
1135 )
1136
1137 m.Int64Gauge.Record(ctx, val, *o...)
1138 }
1139
1140 // AttrDevice returns an optional attribute for the "system.device" semantic
1141 // convention. It represents the identifier for the device where the filesystem
1142 // resides.
1143 func (FilesystemUtilization) AttrDevice(val string) attribute.KeyValue {
1144 return attribute.String("system.device", val)
1145 }
1146
1147 // AttrFilesystemMode returns an optional attribute for the
1148 // "system.filesystem.mode" semantic convention. It represents the filesystem
1149 // mode.
1150 func (FilesystemUtilization) AttrFilesystemMode(val string) attribute.KeyValue {
1151 return attribute.String("system.filesystem.mode", val)
1152 }
1153
1154 // AttrFilesystemMountpoint returns an optional attribute for the
1155 // "system.filesystem.mountpoint" semantic convention. It represents the
1156 // filesystem mount path.
1157 func (FilesystemUtilization) AttrFilesystemMountpoint(val string) attribute.KeyValue {
1158 return attribute.String("system.filesystem.mountpoint", val)
1159 }
1160
1161 // AttrFilesystemState returns an optional attribute for the
1162 // "system.filesystem.state" semantic convention. It represents the filesystem
1163 // state.
1164 func (FilesystemUtilization) AttrFilesystemState(val FilesystemStateAttr) attribute.KeyValue {
1165 return attribute.String("system.filesystem.state", string(val))
1166 }
1167
1168 // AttrFilesystemType returns an optional attribute for the
1169 // "system.filesystem.type" semantic convention. It represents the filesystem
1170 // type.
1171 func (FilesystemUtilization) AttrFilesystemType(val FilesystemTypeAttr) attribute.KeyValue {
1172 return attribute.String("system.filesystem.type", string(val))
1173 }
1174
1175 // LinuxMemoryAvailable is an instrument used to record metric values conforming
1176 // to the "system.linux.memory.available" semantic conventions. It represents an
1177 // estimate of how much memory is available for starting new applications,
1178 // without causing swapping.
1179 type LinuxMemoryAvailable struct {
1180 metric.Int64UpDownCounter
1181 }
1182
1183 // NewLinuxMemoryAvailable returns a new LinuxMemoryAvailable instrument.
1184 func NewLinuxMemoryAvailable(
1185 m metric.Meter,
1186 opt ...metric.Int64UpDownCounterOption,
1187 ) (LinuxMemoryAvailable, error) {
1188 // Check if the meter is nil.
1189 if m == nil {
1190 return LinuxMemoryAvailable{noop.Int64UpDownCounter{}}, nil
1191 }
1192
1193 i, err := m.Int64UpDownCounter(
1194 "system.linux.memory.available",
1195 append([]metric.Int64UpDownCounterOption{
1196 metric.WithDescription("An estimate of how much memory is available for starting new applications, without causing swapping"),
1197 metric.WithUnit("By"),
1198 }, opt...)...,
1199 )
1200 if err != nil {
1201 return LinuxMemoryAvailable{noop.Int64UpDownCounter{}}, err
1202 }
1203 return LinuxMemoryAvailable{i}, nil
1204 }
1205
1206 // Inst returns the underlying metric instrument.
1207 func (m LinuxMemoryAvailable) Inst() metric.Int64UpDownCounter {
1208 return m.Int64UpDownCounter
1209 }
1210
1211 // Name returns the semantic convention name of the instrument.
1212 func (LinuxMemoryAvailable) Name() string {
1213 return "system.linux.memory.available"
1214 }
1215
1216 // Unit returns the semantic convention unit of the instrument
1217 func (LinuxMemoryAvailable) Unit() string {
1218 return "By"
1219 }
1220
1221 // Description returns the semantic convention description of the instrument
1222 func (LinuxMemoryAvailable) Description() string {
1223 return "An estimate of how much memory is available for starting new applications, without causing swapping"
1224 }
1225
1226 // Add adds incr to the existing count.
1227 //
1228 // This is an alternative to `system.memory.usage` metric with `state=free`.
1229 // Linux starting from 3.14 exports "available" memory. It takes "free" memory as
1230 // a baseline, and then factors in kernel-specific values.
1231 // This is supposed to be more accurate than just "free" memory.
1232 // For reference, see the calculations [here].
1233 // See also `MemAvailable` in [/proc/meminfo].
1234 //
1235 // [here]: https://superuser.com/a/980821
1236 // [/proc/meminfo]: https://man7.org/linux/man-pages/man5/proc.5.html
1237 func (m LinuxMemoryAvailable) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1238 if len(attrs) == 0 {
1239 m.Int64UpDownCounter.Add(ctx, incr)
1240 return
1241 }
1242
1243 o := addOptPool.Get().(*[]metric.AddOption)
1244 defer func() {
1245 *o = (*o)[:0]
1246 addOptPool.Put(o)
1247 }()
1248
1249 *o = append(*o, metric.WithAttributes(attrs...))
1250 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1251 }
1252
1253 // LinuxMemorySlabUsage is an instrument used to record metric values conforming
1254 // to the "system.linux.memory.slab.usage" semantic conventions. It represents
1255 // the reports the memory used by the Linux kernel for managing caches of
1256 // frequently used objects.
1257 type LinuxMemorySlabUsage struct {
1258 metric.Int64UpDownCounter
1259 }
1260
1261 // NewLinuxMemorySlabUsage returns a new LinuxMemorySlabUsage instrument.
1262 func NewLinuxMemorySlabUsage(
1263 m metric.Meter,
1264 opt ...metric.Int64UpDownCounterOption,
1265 ) (LinuxMemorySlabUsage, error) {
1266 // Check if the meter is nil.
1267 if m == nil {
1268 return LinuxMemorySlabUsage{noop.Int64UpDownCounter{}}, nil
1269 }
1270
1271 i, err := m.Int64UpDownCounter(
1272 "system.linux.memory.slab.usage",
1273 append([]metric.Int64UpDownCounterOption{
1274 metric.WithDescription("Reports the memory used by the Linux kernel for managing caches of frequently used objects."),
1275 metric.WithUnit("By"),
1276 }, opt...)...,
1277 )
1278 if err != nil {
1279 return LinuxMemorySlabUsage{noop.Int64UpDownCounter{}}, err
1280 }
1281 return LinuxMemorySlabUsage{i}, nil
1282 }
1283
1284 // Inst returns the underlying metric instrument.
1285 func (m LinuxMemorySlabUsage) Inst() metric.Int64UpDownCounter {
1286 return m.Int64UpDownCounter
1287 }
1288
1289 // Name returns the semantic convention name of the instrument.
1290 func (LinuxMemorySlabUsage) Name() string {
1291 return "system.linux.memory.slab.usage"
1292 }
1293
1294 // Unit returns the semantic convention unit of the instrument
1295 func (LinuxMemorySlabUsage) Unit() string {
1296 return "By"
1297 }
1298
1299 // Description returns the semantic convention description of the instrument
1300 func (LinuxMemorySlabUsage) Description() string {
1301 return "Reports the memory used by the Linux kernel for managing caches of frequently used objects."
1302 }
1303
1304 // Add adds incr to the existing count.
1305 //
1306 // All additional attrs passed are included in the recorded value.
1307 //
1308 // The sum over the `reclaimable` and `unreclaimable` state values in
1309 // `linux.memory.slab.usage` SHOULD be equal to the total slab memory available
1310 // on the system.
1311 // Note that the total slab memory is not constant and may vary over time.
1312 // See also the [Slab allocator] and `Slab` in [/proc/meminfo].
1313 //
1314 // [Slab allocator]: https://blogs.oracle.com/linux/post/understanding-linux-kernel-memory-statistics
1315 // [/proc/meminfo]: https://man7.org/linux/man-pages/man5/proc.5.html
1316 func (m LinuxMemorySlabUsage) Add(
1317 ctx context.Context,
1318 incr int64,
1319 attrs ...attribute.KeyValue,
1320 ) {
1321 o := addOptPool.Get().(*[]metric.AddOption)
1322 defer func() {
1323 *o = (*o)[:0]
1324 addOptPool.Put(o)
1325 }()
1326
1327 *o = append(
1328 *o,
1329 metric.WithAttributes(
1330 attrs...,
1331 ),
1332 )
1333
1334 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1335 }
1336
1337 // AttrLinuxMemorySlabState returns an optional attribute for the
1338 // "linux.memory.slab.state" semantic convention. It represents the Linux Slab
1339 // memory state.
1340 func (LinuxMemorySlabUsage) AttrLinuxMemorySlabState(val LinuxMemorySlabStateAttr) attribute.KeyValue {
1341 return attribute.String("linux.memory.slab.state", string(val))
1342 }
1343
1344 // MemoryLimit is an instrument used to record metric values conforming to the
1345 // "system.memory.limit" semantic conventions. It represents the total memory
1346 // available in the system.
1347 type MemoryLimit struct {
1348 metric.Int64UpDownCounter
1349 }
1350
1351 // NewMemoryLimit returns a new MemoryLimit instrument.
1352 func NewMemoryLimit(
1353 m metric.Meter,
1354 opt ...metric.Int64UpDownCounterOption,
1355 ) (MemoryLimit, error) {
1356 // Check if the meter is nil.
1357 if m == nil {
1358 return MemoryLimit{noop.Int64UpDownCounter{}}, nil
1359 }
1360
1361 i, err := m.Int64UpDownCounter(
1362 "system.memory.limit",
1363 append([]metric.Int64UpDownCounterOption{
1364 metric.WithDescription("Total memory available in the system."),
1365 metric.WithUnit("By"),
1366 }, opt...)...,
1367 )
1368 if err != nil {
1369 return MemoryLimit{noop.Int64UpDownCounter{}}, err
1370 }
1371 return MemoryLimit{i}, nil
1372 }
1373
1374 // Inst returns the underlying metric instrument.
1375 func (m MemoryLimit) Inst() metric.Int64UpDownCounter {
1376 return m.Int64UpDownCounter
1377 }
1378
1379 // Name returns the semantic convention name of the instrument.
1380 func (MemoryLimit) Name() string {
1381 return "system.memory.limit"
1382 }
1383
1384 // Unit returns the semantic convention unit of the instrument
1385 func (MemoryLimit) Unit() string {
1386 return "By"
1387 }
1388
1389 // Description returns the semantic convention description of the instrument
1390 func (MemoryLimit) Description() string {
1391 return "Total memory available in the system."
1392 }
1393
1394 // Add adds incr to the existing count.
1395 //
1396 // Its value SHOULD equal the sum of `system.memory.state` over all states.
1397 func (m MemoryLimit) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1398 if len(attrs) == 0 {
1399 m.Int64UpDownCounter.Add(ctx, incr)
1400 return
1401 }
1402
1403 o := addOptPool.Get().(*[]metric.AddOption)
1404 defer func() {
1405 *o = (*o)[:0]
1406 addOptPool.Put(o)
1407 }()
1408
1409 *o = append(*o, metric.WithAttributes(attrs...))
1410 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1411 }
1412
1413 // MemoryShared is an instrument used to record metric values conforming to the
1414 // "system.memory.shared" semantic conventions. It represents the shared memory
1415 // used (mostly by tmpfs).
1416 type MemoryShared struct {
1417 metric.Int64UpDownCounter
1418 }
1419
1420 // NewMemoryShared returns a new MemoryShared instrument.
1421 func NewMemoryShared(
1422 m metric.Meter,
1423 opt ...metric.Int64UpDownCounterOption,
1424 ) (MemoryShared, error) {
1425 // Check if the meter is nil.
1426 if m == nil {
1427 return MemoryShared{noop.Int64UpDownCounter{}}, nil
1428 }
1429
1430 i, err := m.Int64UpDownCounter(
1431 "system.memory.shared",
1432 append([]metric.Int64UpDownCounterOption{
1433 metric.WithDescription("Shared memory used (mostly by tmpfs)."),
1434 metric.WithUnit("By"),
1435 }, opt...)...,
1436 )
1437 if err != nil {
1438 return MemoryShared{noop.Int64UpDownCounter{}}, err
1439 }
1440 return MemoryShared{i}, nil
1441 }
1442
1443 // Inst returns the underlying metric instrument.
1444 func (m MemoryShared) Inst() metric.Int64UpDownCounter {
1445 return m.Int64UpDownCounter
1446 }
1447
1448 // Name returns the semantic convention name of the instrument.
1449 func (MemoryShared) Name() string {
1450 return "system.memory.shared"
1451 }
1452
1453 // Unit returns the semantic convention unit of the instrument
1454 func (MemoryShared) Unit() string {
1455 return "By"
1456 }
1457
1458 // Description returns the semantic convention description of the instrument
1459 func (MemoryShared) Description() string {
1460 return "Shared memory used (mostly by tmpfs)."
1461 }
1462
1463 // Add adds incr to the existing count.
1464 //
1465 // Equivalent of `shared` from [`free` command] or
1466 // `Shmem` from [`/proc/meminfo`]"
1467 //
1468 // [`free` command]: https://man7.org/linux/man-pages/man1/free.1.html
1469 // [`/proc/meminfo`]: https://man7.org/linux/man-pages/man5/proc.5.html
1470 func (m MemoryShared) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1471 if len(attrs) == 0 {
1472 m.Int64UpDownCounter.Add(ctx, incr)
1473 return
1474 }
1475
1476 o := addOptPool.Get().(*[]metric.AddOption)
1477 defer func() {
1478 *o = (*o)[:0]
1479 addOptPool.Put(o)
1480 }()
1481
1482 *o = append(*o, metric.WithAttributes(attrs...))
1483 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1484 }
1485
1486 // MemoryUsage is an instrument used to record metric values conforming to the
1487 // "system.memory.usage" semantic conventions. It represents the reports memory
1488 // in use by state.
1489 type MemoryUsage struct {
1490 metric.Int64ObservableUpDownCounter
1491 }
1492
1493 // NewMemoryUsage returns a new MemoryUsage instrument.
1494 func NewMemoryUsage(
1495 m metric.Meter,
1496 opt ...metric.Int64ObservableUpDownCounterOption,
1497 ) (MemoryUsage, error) {
1498 // Check if the meter is nil.
1499 if m == nil {
1500 return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, nil
1501 }
1502
1503 i, err := m.Int64ObservableUpDownCounter(
1504 "system.memory.usage",
1505 append([]metric.Int64ObservableUpDownCounterOption{
1506 metric.WithDescription("Reports memory in use by state."),
1507 metric.WithUnit("By"),
1508 }, opt...)...,
1509 )
1510 if err != nil {
1511 return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, err
1512 }
1513 return MemoryUsage{i}, nil
1514 }
1515
1516 // Inst returns the underlying metric instrument.
1517 func (m MemoryUsage) Inst() metric.Int64ObservableUpDownCounter {
1518 return m.Int64ObservableUpDownCounter
1519 }
1520
1521 // Name returns the semantic convention name of the instrument.
1522 func (MemoryUsage) Name() string {
1523 return "system.memory.usage"
1524 }
1525
1526 // Unit returns the semantic convention unit of the instrument
1527 func (MemoryUsage) Unit() string {
1528 return "By"
1529 }
1530
1531 // Description returns the semantic convention description of the instrument
1532 func (MemoryUsage) Description() string {
1533 return "Reports memory in use by state."
1534 }
1535
1536 // AttrMemoryState returns an optional attribute for the "system.memory.state"
1537 // semantic convention. It represents the memory state.
1538 func (MemoryUsage) AttrMemoryState(val MemoryStateAttr) attribute.KeyValue {
1539 return attribute.String("system.memory.state", string(val))
1540 }
1541
1542 // MemoryUtilization is an instrument used to record metric values conforming to
1543 // the "system.memory.utilization" semantic conventions.
1544 type MemoryUtilization struct {
1545 metric.Float64ObservableGauge
1546 }
1547
1548 // NewMemoryUtilization returns a new MemoryUtilization instrument.
1549 func NewMemoryUtilization(
1550 m metric.Meter,
1551 opt ...metric.Float64ObservableGaugeOption,
1552 ) (MemoryUtilization, error) {
1553 // Check if the meter is nil.
1554 if m == nil {
1555 return MemoryUtilization{noop.Float64ObservableGauge{}}, nil
1556 }
1557
1558 i, err := m.Float64ObservableGauge(
1559 "system.memory.utilization",
1560 append([]metric.Float64ObservableGaugeOption{
1561 metric.WithDescription(""),
1562 metric.WithUnit("1"),
1563 }, opt...)...,
1564 )
1565 if err != nil {
1566 return MemoryUtilization{noop.Float64ObservableGauge{}}, err
1567 }
1568 return MemoryUtilization{i}, nil
1569 }
1570
1571 // Inst returns the underlying metric instrument.
1572 func (m MemoryUtilization) Inst() metric.Float64ObservableGauge {
1573 return m.Float64ObservableGauge
1574 }
1575
1576 // Name returns the semantic convention name of the instrument.
1577 func (MemoryUtilization) Name() string {
1578 return "system.memory.utilization"
1579 }
1580
1581 // Unit returns the semantic convention unit of the instrument
1582 func (MemoryUtilization) Unit() string {
1583 return "1"
1584 }
1585
1586 // AttrMemoryState returns an optional attribute for the "system.memory.state"
1587 // semantic convention. It represents the memory state.
1588 func (MemoryUtilization) AttrMemoryState(val MemoryStateAttr) attribute.KeyValue {
1589 return attribute.String("system.memory.state", string(val))
1590 }
1591
1592 // NetworkConnections is an instrument used to record metric values conforming to
1593 // the "system.network.connections" semantic conventions.
1594 type NetworkConnections struct {
1595 metric.Int64UpDownCounter
1596 }
1597
1598 // NewNetworkConnections returns a new NetworkConnections instrument.
1599 func NewNetworkConnections(
1600 m metric.Meter,
1601 opt ...metric.Int64UpDownCounterOption,
1602 ) (NetworkConnections, error) {
1603 // Check if the meter is nil.
1604 if m == nil {
1605 return NetworkConnections{noop.Int64UpDownCounter{}}, nil
1606 }
1607
1608 i, err := m.Int64UpDownCounter(
1609 "system.network.connections",
1610 append([]metric.Int64UpDownCounterOption{
1611 metric.WithDescription(""),
1612 metric.WithUnit("{connection}"),
1613 }, opt...)...,
1614 )
1615 if err != nil {
1616 return NetworkConnections{noop.Int64UpDownCounter{}}, err
1617 }
1618 return NetworkConnections{i}, nil
1619 }
1620
1621 // Inst returns the underlying metric instrument.
1622 func (m NetworkConnections) Inst() metric.Int64UpDownCounter {
1623 return m.Int64UpDownCounter
1624 }
1625
1626 // Name returns the semantic convention name of the instrument.
1627 func (NetworkConnections) Name() string {
1628 return "system.network.connections"
1629 }
1630
1631 // Unit returns the semantic convention unit of the instrument
1632 func (NetworkConnections) Unit() string {
1633 return "{connection}"
1634 }
1635
1636 // Add adds incr to the existing count.
1637 //
1638 // All additional attrs passed are included in the recorded value.
1639 func (m NetworkConnections) Add(
1640 ctx context.Context,
1641 incr int64,
1642 attrs ...attribute.KeyValue,
1643 ) {
1644 o := addOptPool.Get().(*[]metric.AddOption)
1645 defer func() {
1646 *o = (*o)[:0]
1647 addOptPool.Put(o)
1648 }()
1649
1650 *o = append(
1651 *o,
1652 metric.WithAttributes(
1653 attrs...,
1654 ),
1655 )
1656
1657 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1658 }
1659
1660 // AttrNetworkConnectionState returns an optional attribute for the
1661 // "network.connection.state" semantic convention. It represents the state of
1662 // network connection.
1663 func (NetworkConnections) AttrNetworkConnectionState(val NetworkConnectionStateAttr) attribute.KeyValue {
1664 return attribute.String("network.connection.state", string(val))
1665 }
1666
1667 // AttrNetworkInterfaceName returns an optional attribute for the
1668 // "network.interface.name" semantic convention. It represents the network
1669 // interface name.
1670 func (NetworkConnections) AttrNetworkInterfaceName(val string) attribute.KeyValue {
1671 return attribute.String("network.interface.name", val)
1672 }
1673
1674 // AttrNetworkTransport returns an optional attribute for the "network.transport"
1675 // semantic convention. It represents the [OSI transport layer] or
1676 // [inter-process communication method].
1677 //
1678 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
1679 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
1680 func (NetworkConnections) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
1681 return attribute.String("network.transport", string(val))
1682 }
1683
1684 // NetworkDropped is an instrument used to record metric values conforming to the
1685 // "system.network.dropped" semantic conventions. It represents the count of
1686 // packets that are dropped or discarded even though there was no error.
1687 type NetworkDropped struct {
1688 metric.Int64Counter
1689 }
1690
1691 // NewNetworkDropped returns a new NetworkDropped instrument.
1692 func NewNetworkDropped(
1693 m metric.Meter,
1694 opt ...metric.Int64CounterOption,
1695 ) (NetworkDropped, error) {
1696 // Check if the meter is nil.
1697 if m == nil {
1698 return NetworkDropped{noop.Int64Counter{}}, nil
1699 }
1700
1701 i, err := m.Int64Counter(
1702 "system.network.dropped",
1703 append([]metric.Int64CounterOption{
1704 metric.WithDescription("Count of packets that are dropped or discarded even though there was no error"),
1705 metric.WithUnit("{packet}"),
1706 }, opt...)...,
1707 )
1708 if err != nil {
1709 return NetworkDropped{noop.Int64Counter{}}, err
1710 }
1711 return NetworkDropped{i}, nil
1712 }
1713
1714 // Inst returns the underlying metric instrument.
1715 func (m NetworkDropped) Inst() metric.Int64Counter {
1716 return m.Int64Counter
1717 }
1718
1719 // Name returns the semantic convention name of the instrument.
1720 func (NetworkDropped) Name() string {
1721 return "system.network.dropped"
1722 }
1723
1724 // Unit returns the semantic convention unit of the instrument
1725 func (NetworkDropped) Unit() string {
1726 return "{packet}"
1727 }
1728
1729 // Description returns the semantic convention description of the instrument
1730 func (NetworkDropped) Description() string {
1731 return "Count of packets that are dropped or discarded even though there was no error"
1732 }
1733
1734 // Add adds incr to the existing count.
1735 //
1736 // All additional attrs passed are included in the recorded value.
1737 //
1738 // Measured as:
1739 //
1740 // - Linux: the `drop` column in `/proc/dev/net` ([source])
1741 // - Windows: [`InDiscards`/`OutDiscards`]
1742 // from [`GetIfEntry2`]
1743 //
1744 //
1745 // [source]: https://web.archive.org/web/20180321091318/http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html
1746 // [`InDiscards`/`OutDiscards`]: https://docs.microsoft.com/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
1747 // [`GetIfEntry2`]: https://docs.microsoft.com/windows/win32/api/netioapi/nf-netioapi-getifentry2
1748 func (m NetworkDropped) Add(
1749 ctx context.Context,
1750 incr int64,
1751 attrs ...attribute.KeyValue,
1752 ) {
1753 o := addOptPool.Get().(*[]metric.AddOption)
1754 defer func() {
1755 *o = (*o)[:0]
1756 addOptPool.Put(o)
1757 }()
1758
1759 *o = append(
1760 *o,
1761 metric.WithAttributes(
1762 attrs...,
1763 ),
1764 )
1765
1766 m.Int64Counter.Add(ctx, incr, *o...)
1767 }
1768
1769 // AttrNetworkInterfaceName returns an optional attribute for the
1770 // "network.interface.name" semantic convention. It represents the network
1771 // interface name.
1772 func (NetworkDropped) AttrNetworkInterfaceName(val string) attribute.KeyValue {
1773 return attribute.String("network.interface.name", val)
1774 }
1775
1776 // AttrNetworkIODirection returns an optional attribute for the
1777 // "network.io.direction" semantic convention. It represents the network IO
1778 // operation direction.
1779 func (NetworkDropped) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
1780 return attribute.String("network.io.direction", string(val))
1781 }
1782
1783 // NetworkErrors is an instrument used to record metric values conforming to the
1784 // "system.network.errors" semantic conventions. It represents the count of
1785 // network errors detected.
1786 type NetworkErrors struct {
1787 metric.Int64Counter
1788 }
1789
1790 // NewNetworkErrors returns a new NetworkErrors instrument.
1791 func NewNetworkErrors(
1792 m metric.Meter,
1793 opt ...metric.Int64CounterOption,
1794 ) (NetworkErrors, error) {
1795 // Check if the meter is nil.
1796 if m == nil {
1797 return NetworkErrors{noop.Int64Counter{}}, nil
1798 }
1799
1800 i, err := m.Int64Counter(
1801 "system.network.errors",
1802 append([]metric.Int64CounterOption{
1803 metric.WithDescription("Count of network errors detected"),
1804 metric.WithUnit("{error}"),
1805 }, opt...)...,
1806 )
1807 if err != nil {
1808 return NetworkErrors{noop.Int64Counter{}}, err
1809 }
1810 return NetworkErrors{i}, nil
1811 }
1812
1813 // Inst returns the underlying metric instrument.
1814 func (m NetworkErrors) Inst() metric.Int64Counter {
1815 return m.Int64Counter
1816 }
1817
1818 // Name returns the semantic convention name of the instrument.
1819 func (NetworkErrors) Name() string {
1820 return "system.network.errors"
1821 }
1822
1823 // Unit returns the semantic convention unit of the instrument
1824 func (NetworkErrors) Unit() string {
1825 return "{error}"
1826 }
1827
1828 // Description returns the semantic convention description of the instrument
1829 func (NetworkErrors) Description() string {
1830 return "Count of network errors detected"
1831 }
1832
1833 // Add adds incr to the existing count.
1834 //
1835 // All additional attrs passed are included in the recorded value.
1836 //
1837 // Measured as:
1838 //
1839 // - Linux: the `errs` column in `/proc/dev/net` ([source]).
1840 // - Windows: [`InErrors`/`OutErrors`]
1841 // from [`GetIfEntry2`].
1842 //
1843 //
1844 // [source]: https://web.archive.org/web/20180321091318/http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html
1845 // [`InErrors`/`OutErrors`]: https://docs.microsoft.com/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
1846 // [`GetIfEntry2`]: https://docs.microsoft.com/windows/win32/api/netioapi/nf-netioapi-getifentry2
1847 func (m NetworkErrors) Add(
1848 ctx context.Context,
1849 incr int64,
1850 attrs ...attribute.KeyValue,
1851 ) {
1852 o := addOptPool.Get().(*[]metric.AddOption)
1853 defer func() {
1854 *o = (*o)[:0]
1855 addOptPool.Put(o)
1856 }()
1857
1858 *o = append(
1859 *o,
1860 metric.WithAttributes(
1861 attrs...,
1862 ),
1863 )
1864
1865 m.Int64Counter.Add(ctx, incr, *o...)
1866 }
1867
1868 // AttrNetworkInterfaceName returns an optional attribute for the
1869 // "network.interface.name" semantic convention. It represents the network
1870 // interface name.
1871 func (NetworkErrors) AttrNetworkInterfaceName(val string) attribute.KeyValue {
1872 return attribute.String("network.interface.name", val)
1873 }
1874
1875 // AttrNetworkIODirection returns an optional attribute for the
1876 // "network.io.direction" semantic convention. It represents the network IO
1877 // operation direction.
1878 func (NetworkErrors) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
1879 return attribute.String("network.io.direction", string(val))
1880 }
1881
1882 // NetworkIO is an instrument used to record metric values conforming to the
1883 // "system.network.io" semantic conventions.
1884 type NetworkIO struct {
1885 metric.Int64ObservableCounter
1886 }
1887
1888 // NewNetworkIO returns a new NetworkIO instrument.
1889 func NewNetworkIO(
1890 m metric.Meter,
1891 opt ...metric.Int64ObservableCounterOption,
1892 ) (NetworkIO, error) {
1893 // Check if the meter is nil.
1894 if m == nil {
1895 return NetworkIO{noop.Int64ObservableCounter{}}, nil
1896 }
1897
1898 i, err := m.Int64ObservableCounter(
1899 "system.network.io",
1900 append([]metric.Int64ObservableCounterOption{
1901 metric.WithDescription(""),
1902 metric.WithUnit("By"),
1903 }, opt...)...,
1904 )
1905 if err != nil {
1906 return NetworkIO{noop.Int64ObservableCounter{}}, err
1907 }
1908 return NetworkIO{i}, nil
1909 }
1910
1911 // Inst returns the underlying metric instrument.
1912 func (m NetworkIO) Inst() metric.Int64ObservableCounter {
1913 return m.Int64ObservableCounter
1914 }
1915
1916 // Name returns the semantic convention name of the instrument.
1917 func (NetworkIO) Name() string {
1918 return "system.network.io"
1919 }
1920
1921 // Unit returns the semantic convention unit of the instrument
1922 func (NetworkIO) Unit() string {
1923 return "By"
1924 }
1925
1926 // AttrNetworkInterfaceName returns an optional attribute for the
1927 // "network.interface.name" semantic convention. It represents the network
1928 // interface name.
1929 func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
1930 return attribute.String("network.interface.name", val)
1931 }
1932
1933 // AttrNetworkIODirection returns an optional attribute for the
1934 // "network.io.direction" semantic convention. It represents the network IO
1935 // operation direction.
1936 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
1937 return attribute.String("network.io.direction", string(val))
1938 }
1939
1940 // NetworkPackets is an instrument used to record metric values conforming to the
1941 // "system.network.packets" semantic conventions.
1942 type NetworkPackets struct {
1943 metric.Int64Counter
1944 }
1945
1946 // NewNetworkPackets returns a new NetworkPackets instrument.
1947 func NewNetworkPackets(
1948 m metric.Meter,
1949 opt ...metric.Int64CounterOption,
1950 ) (NetworkPackets, error) {
1951 // Check if the meter is nil.
1952 if m == nil {
1953 return NetworkPackets{noop.Int64Counter{}}, nil
1954 }
1955
1956 i, err := m.Int64Counter(
1957 "system.network.packets",
1958 append([]metric.Int64CounterOption{
1959 metric.WithDescription(""),
1960 metric.WithUnit("{packet}"),
1961 }, opt...)...,
1962 )
1963 if err != nil {
1964 return NetworkPackets{noop.Int64Counter{}}, err
1965 }
1966 return NetworkPackets{i}, nil
1967 }
1968
1969 // Inst returns the underlying metric instrument.
1970 func (m NetworkPackets) Inst() metric.Int64Counter {
1971 return m.Int64Counter
1972 }
1973
1974 // Name returns the semantic convention name of the instrument.
1975 func (NetworkPackets) Name() string {
1976 return "system.network.packets"
1977 }
1978
1979 // Unit returns the semantic convention unit of the instrument
1980 func (NetworkPackets) Unit() string {
1981 return "{packet}"
1982 }
1983
1984 // Add adds incr to the existing count.
1985 //
1986 // All additional attrs passed are included in the recorded value.
1987 func (m NetworkPackets) Add(
1988 ctx context.Context,
1989 incr int64,
1990 attrs ...attribute.KeyValue,
1991 ) {
1992 o := addOptPool.Get().(*[]metric.AddOption)
1993 defer func() {
1994 *o = (*o)[:0]
1995 addOptPool.Put(o)
1996 }()
1997
1998 *o = append(
1999 *o,
2000 metric.WithAttributes(
2001 attrs...,
2002 ),
2003 )
2004
2005 m.Int64Counter.Add(ctx, incr, *o...)
2006 }
2007
2008 // AttrNetworkIODirection returns an optional attribute for the
2009 // "network.io.direction" semantic convention. It represents the network IO
2010 // operation direction.
2011 func (NetworkPackets) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
2012 return attribute.String("network.io.direction", string(val))
2013 }
2014
2015 // AttrDevice returns an optional attribute for the "system.device" semantic
2016 // convention. It represents the device identifier.
2017 func (NetworkPackets) AttrDevice(val string) attribute.KeyValue {
2018 return attribute.String("system.device", val)
2019 }
2020
2021 // PagingFaults is an instrument used to record metric values conforming to the
2022 // "system.paging.faults" semantic conventions.
2023 type PagingFaults struct {
2024 metric.Int64Counter
2025 }
2026
2027 // NewPagingFaults returns a new PagingFaults instrument.
2028 func NewPagingFaults(
2029 m metric.Meter,
2030 opt ...metric.Int64CounterOption,
2031 ) (PagingFaults, error) {
2032 // Check if the meter is nil.
2033 if m == nil {
2034 return PagingFaults{noop.Int64Counter{}}, nil
2035 }
2036
2037 i, err := m.Int64Counter(
2038 "system.paging.faults",
2039 append([]metric.Int64CounterOption{
2040 metric.WithDescription(""),
2041 metric.WithUnit("{fault}"),
2042 }, opt...)...,
2043 )
2044 if err != nil {
2045 return PagingFaults{noop.Int64Counter{}}, err
2046 }
2047 return PagingFaults{i}, nil
2048 }
2049
2050 // Inst returns the underlying metric instrument.
2051 func (m PagingFaults) Inst() metric.Int64Counter {
2052 return m.Int64Counter
2053 }
2054
2055 // Name returns the semantic convention name of the instrument.
2056 func (PagingFaults) Name() string {
2057 return "system.paging.faults"
2058 }
2059
2060 // Unit returns the semantic convention unit of the instrument
2061 func (PagingFaults) Unit() string {
2062 return "{fault}"
2063 }
2064
2065 // Add adds incr to the existing count.
2066 //
2067 // All additional attrs passed are included in the recorded value.
2068 func (m PagingFaults) Add(
2069 ctx context.Context,
2070 incr int64,
2071 attrs ...attribute.KeyValue,
2072 ) {
2073 o := addOptPool.Get().(*[]metric.AddOption)
2074 defer func() {
2075 *o = (*o)[:0]
2076 addOptPool.Put(o)
2077 }()
2078
2079 *o = append(
2080 *o,
2081 metric.WithAttributes(
2082 attrs...,
2083 ),
2084 )
2085
2086 m.Int64Counter.Add(ctx, incr, *o...)
2087 }
2088
2089 // AttrPagingType returns an optional attribute for the "system.paging.type"
2090 // semantic convention. It represents the memory paging type.
2091 func (PagingFaults) AttrPagingType(val PagingTypeAttr) attribute.KeyValue {
2092 return attribute.String("system.paging.type", string(val))
2093 }
2094
2095 // PagingOperations is an instrument used to record metric values conforming to
2096 // the "system.paging.operations" semantic conventions.
2097 type PagingOperations struct {
2098 metric.Int64Counter
2099 }
2100
2101 // NewPagingOperations returns a new PagingOperations instrument.
2102 func NewPagingOperations(
2103 m metric.Meter,
2104 opt ...metric.Int64CounterOption,
2105 ) (PagingOperations, error) {
2106 // Check if the meter is nil.
2107 if m == nil {
2108 return PagingOperations{noop.Int64Counter{}}, nil
2109 }
2110
2111 i, err := m.Int64Counter(
2112 "system.paging.operations",
2113 append([]metric.Int64CounterOption{
2114 metric.WithDescription(""),
2115 metric.WithUnit("{operation}"),
2116 }, opt...)...,
2117 )
2118 if err != nil {
2119 return PagingOperations{noop.Int64Counter{}}, err
2120 }
2121 return PagingOperations{i}, nil
2122 }
2123
2124 // Inst returns the underlying metric instrument.
2125 func (m PagingOperations) Inst() metric.Int64Counter {
2126 return m.Int64Counter
2127 }
2128
2129 // Name returns the semantic convention name of the instrument.
2130 func (PagingOperations) Name() string {
2131 return "system.paging.operations"
2132 }
2133
2134 // Unit returns the semantic convention unit of the instrument
2135 func (PagingOperations) Unit() string {
2136 return "{operation}"
2137 }
2138
2139 // Add adds incr to the existing count.
2140 //
2141 // All additional attrs passed are included in the recorded value.
2142 func (m PagingOperations) Add(
2143 ctx context.Context,
2144 incr int64,
2145 attrs ...attribute.KeyValue,
2146 ) {
2147 o := addOptPool.Get().(*[]metric.AddOption)
2148 defer func() {
2149 *o = (*o)[:0]
2150 addOptPool.Put(o)
2151 }()
2152
2153 *o = append(
2154 *o,
2155 metric.WithAttributes(
2156 attrs...,
2157 ),
2158 )
2159
2160 m.Int64Counter.Add(ctx, incr, *o...)
2161 }
2162
2163 // AttrPagingDirection returns an optional attribute for the
2164 // "system.paging.direction" semantic convention. It represents the paging access
2165 // direction.
2166 func (PagingOperations) AttrPagingDirection(val PagingDirectionAttr) attribute.KeyValue {
2167 return attribute.String("system.paging.direction", string(val))
2168 }
2169
2170 // AttrPagingType returns an optional attribute for the "system.paging.type"
2171 // semantic convention. It represents the memory paging type.
2172 func (PagingOperations) AttrPagingType(val PagingTypeAttr) attribute.KeyValue {
2173 return attribute.String("system.paging.type", string(val))
2174 }
2175
2176 // PagingUsage is an instrument used to record metric values conforming to the
2177 // "system.paging.usage" semantic conventions. It represents the unix swap or
2178 // windows pagefile usage.
2179 type PagingUsage struct {
2180 metric.Int64UpDownCounter
2181 }
2182
2183 // NewPagingUsage returns a new PagingUsage instrument.
2184 func NewPagingUsage(
2185 m metric.Meter,
2186 opt ...metric.Int64UpDownCounterOption,
2187 ) (PagingUsage, error) {
2188 // Check if the meter is nil.
2189 if m == nil {
2190 return PagingUsage{noop.Int64UpDownCounter{}}, nil
2191 }
2192
2193 i, err := m.Int64UpDownCounter(
2194 "system.paging.usage",
2195 append([]metric.Int64UpDownCounterOption{
2196 metric.WithDescription("Unix swap or windows pagefile usage"),
2197 metric.WithUnit("By"),
2198 }, opt...)...,
2199 )
2200 if err != nil {
2201 return PagingUsage{noop.Int64UpDownCounter{}}, err
2202 }
2203 return PagingUsage{i}, nil
2204 }
2205
2206 // Inst returns the underlying metric instrument.
2207 func (m PagingUsage) Inst() metric.Int64UpDownCounter {
2208 return m.Int64UpDownCounter
2209 }
2210
2211 // Name returns the semantic convention name of the instrument.
2212 func (PagingUsage) Name() string {
2213 return "system.paging.usage"
2214 }
2215
2216 // Unit returns the semantic convention unit of the instrument
2217 func (PagingUsage) Unit() string {
2218 return "By"
2219 }
2220
2221 // Description returns the semantic convention description of the instrument
2222 func (PagingUsage) Description() string {
2223 return "Unix swap or windows pagefile usage"
2224 }
2225
2226 // Add adds incr to the existing count.
2227 //
2228 // All additional attrs passed are included in the recorded value.
2229 func (m PagingUsage) Add(
2230 ctx context.Context,
2231 incr int64,
2232 attrs ...attribute.KeyValue,
2233 ) {
2234 o := addOptPool.Get().(*[]metric.AddOption)
2235 defer func() {
2236 *o = (*o)[:0]
2237 addOptPool.Put(o)
2238 }()
2239
2240 *o = append(
2241 *o,
2242 metric.WithAttributes(
2243 attrs...,
2244 ),
2245 )
2246
2247 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2248 }
2249
2250 // AttrDevice returns an optional attribute for the "system.device" semantic
2251 // convention. It represents the unique identifier for the device responsible for
2252 // managing paging operations.
2253 func (PagingUsage) AttrDevice(val string) attribute.KeyValue {
2254 return attribute.String("system.device", val)
2255 }
2256
2257 // AttrPagingState returns an optional attribute for the "system.paging.state"
2258 // semantic convention. It represents the memory paging state.
2259 func (PagingUsage) AttrPagingState(val PagingStateAttr) attribute.KeyValue {
2260 return attribute.String("system.paging.state", string(val))
2261 }
2262
2263 // PagingUtilization is an instrument used to record metric values conforming to
2264 // the "system.paging.utilization" semantic conventions.
2265 type PagingUtilization struct {
2266 metric.Int64Gauge
2267 }
2268
2269 // NewPagingUtilization returns a new PagingUtilization instrument.
2270 func NewPagingUtilization(
2271 m metric.Meter,
2272 opt ...metric.Int64GaugeOption,
2273 ) (PagingUtilization, error) {
2274 // Check if the meter is nil.
2275 if m == nil {
2276 return PagingUtilization{noop.Int64Gauge{}}, nil
2277 }
2278
2279 i, err := m.Int64Gauge(
2280 "system.paging.utilization",
2281 append([]metric.Int64GaugeOption{
2282 metric.WithDescription(""),
2283 metric.WithUnit("1"),
2284 }, opt...)...,
2285 )
2286 if err != nil {
2287 return PagingUtilization{noop.Int64Gauge{}}, err
2288 }
2289 return PagingUtilization{i}, nil
2290 }
2291
2292 // Inst returns the underlying metric instrument.
2293 func (m PagingUtilization) Inst() metric.Int64Gauge {
2294 return m.Int64Gauge
2295 }
2296
2297 // Name returns the semantic convention name of the instrument.
2298 func (PagingUtilization) Name() string {
2299 return "system.paging.utilization"
2300 }
2301
2302 // Unit returns the semantic convention unit of the instrument
2303 func (PagingUtilization) Unit() string {
2304 return "1"
2305 }
2306
2307 // Record records val to the current distribution.
2308 //
2309 // All additional attrs passed are included in the recorded value.
2310 func (m PagingUtilization) Record(
2311 ctx context.Context,
2312 val int64,
2313 attrs ...attribute.KeyValue,
2314 ) {
2315 o := recOptPool.Get().(*[]metric.RecordOption)
2316 defer func() {
2317 *o = (*o)[:0]
2318 recOptPool.Put(o)
2319 }()
2320
2321 *o = append(
2322 *o,
2323 metric.WithAttributes(
2324 attrs...,
2325 ),
2326 )
2327
2328 m.Int64Gauge.Record(ctx, val, *o...)
2329 }
2330
2331 // AttrDevice returns an optional attribute for the "system.device" semantic
2332 // convention. It represents the unique identifier for the device responsible for
2333 // managing paging operations.
2334 func (PagingUtilization) AttrDevice(val string) attribute.KeyValue {
2335 return attribute.String("system.device", val)
2336 }
2337
2338 // AttrPagingState returns an optional attribute for the "system.paging.state"
2339 // semantic convention. It represents the memory paging state.
2340 func (PagingUtilization) AttrPagingState(val PagingStateAttr) attribute.KeyValue {
2341 return attribute.String("system.paging.state", string(val))
2342 }
2343
2344 // ProcessCount is an instrument used to record metric values conforming to the
2345 // "system.process.count" semantic conventions. It represents the total number of
2346 // processes in each state.
2347 type ProcessCount struct {
2348 metric.Int64UpDownCounter
2349 }
2350
2351 // NewProcessCount returns a new ProcessCount instrument.
2352 func NewProcessCount(
2353 m metric.Meter,
2354 opt ...metric.Int64UpDownCounterOption,
2355 ) (ProcessCount, error) {
2356 // Check if the meter is nil.
2357 if m == nil {
2358 return ProcessCount{noop.Int64UpDownCounter{}}, nil
2359 }
2360
2361 i, err := m.Int64UpDownCounter(
2362 "system.process.count",
2363 append([]metric.Int64UpDownCounterOption{
2364 metric.WithDescription("Total number of processes in each state"),
2365 metric.WithUnit("{process}"),
2366 }, opt...)...,
2367 )
2368 if err != nil {
2369 return ProcessCount{noop.Int64UpDownCounter{}}, err
2370 }
2371 return ProcessCount{i}, nil
2372 }
2373
2374 // Inst returns the underlying metric instrument.
2375 func (m ProcessCount) Inst() metric.Int64UpDownCounter {
2376 return m.Int64UpDownCounter
2377 }
2378
2379 // Name returns the semantic convention name of the instrument.
2380 func (ProcessCount) Name() string {
2381 return "system.process.count"
2382 }
2383
2384 // Unit returns the semantic convention unit of the instrument
2385 func (ProcessCount) Unit() string {
2386 return "{process}"
2387 }
2388
2389 // Description returns the semantic convention description of the instrument
2390 func (ProcessCount) Description() string {
2391 return "Total number of processes in each state"
2392 }
2393
2394 // Add adds incr to the existing count.
2395 //
2396 // All additional attrs passed are included in the recorded value.
2397 func (m ProcessCount) Add(
2398 ctx context.Context,
2399 incr int64,
2400 attrs ...attribute.KeyValue,
2401 ) {
2402 o := addOptPool.Get().(*[]metric.AddOption)
2403 defer func() {
2404 *o = (*o)[:0]
2405 addOptPool.Put(o)
2406 }()
2407
2408 *o = append(
2409 *o,
2410 metric.WithAttributes(
2411 attrs...,
2412 ),
2413 )
2414
2415 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2416 }
2417
2418 // AttrProcessStatus returns an optional attribute for the
2419 // "system.process.status" semantic convention. It represents the process state,
2420 // e.g., [Linux Process State Codes].
2421 //
2422 // [Linux Process State Codes]: https://man7.org/linux/man-pages/man1/ps.1.html#PROCESS_STATE_CODES
2423 func (ProcessCount) AttrProcessStatus(val ProcessStatusAttr) attribute.KeyValue {
2424 return attribute.String("system.process.status", string(val))
2425 }
2426
2427 // ProcessCreated is an instrument used to record metric values conforming to the
2428 // "system.process.created" semantic conventions. It represents the total number
2429 // of processes created over uptime of the host.
2430 type ProcessCreated struct {
2431 metric.Int64Counter
2432 }
2433
2434 // NewProcessCreated returns a new ProcessCreated instrument.
2435 func NewProcessCreated(
2436 m metric.Meter,
2437 opt ...metric.Int64CounterOption,
2438 ) (ProcessCreated, error) {
2439 // Check if the meter is nil.
2440 if m == nil {
2441 return ProcessCreated{noop.Int64Counter{}}, nil
2442 }
2443
2444 i, err := m.Int64Counter(
2445 "system.process.created",
2446 append([]metric.Int64CounterOption{
2447 metric.WithDescription("Total number of processes created over uptime of the host"),
2448 metric.WithUnit("{process}"),
2449 }, opt...)...,
2450 )
2451 if err != nil {
2452 return ProcessCreated{noop.Int64Counter{}}, err
2453 }
2454 return ProcessCreated{i}, nil
2455 }
2456
2457 // Inst returns the underlying metric instrument.
2458 func (m ProcessCreated) Inst() metric.Int64Counter {
2459 return m.Int64Counter
2460 }
2461
2462 // Name returns the semantic convention name of the instrument.
2463 func (ProcessCreated) Name() string {
2464 return "system.process.created"
2465 }
2466
2467 // Unit returns the semantic convention unit of the instrument
2468 func (ProcessCreated) Unit() string {
2469 return "{process}"
2470 }
2471
2472 // Description returns the semantic convention description of the instrument
2473 func (ProcessCreated) Description() string {
2474 return "Total number of processes created over uptime of the host"
2475 }
2476
2477 // Add adds incr to the existing count.
2478 func (m ProcessCreated) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
2479 if len(attrs) == 0 {
2480 m.Int64Counter.Add(ctx, incr)
2481 return
2482 }
2483
2484 o := addOptPool.Get().(*[]metric.AddOption)
2485 defer func() {
2486 *o = (*o)[:0]
2487 addOptPool.Put(o)
2488 }()
2489
2490 *o = append(*o, metric.WithAttributes(attrs...))
2491 m.Int64Counter.Add(ctx, incr, *o...)
2492 }
2493
2494 // Uptime is an instrument used to record metric values conforming to the
2495 // "system.uptime" semantic conventions. It represents the time the system has
2496 // been running.
2497 type Uptime struct {
2498 metric.Float64Gauge
2499 }
2500
2501 // NewUptime returns a new Uptime instrument.
2502 func NewUptime(
2503 m metric.Meter,
2504 opt ...metric.Float64GaugeOption,
2505 ) (Uptime, error) {
2506 // Check if the meter is nil.
2507 if m == nil {
2508 return Uptime{noop.Float64Gauge{}}, nil
2509 }
2510
2511 i, err := m.Float64Gauge(
2512 "system.uptime",
2513 append([]metric.Float64GaugeOption{
2514 metric.WithDescription("The time the system has been running"),
2515 metric.WithUnit("s"),
2516 }, opt...)...,
2517 )
2518 if err != nil {
2519 return Uptime{noop.Float64Gauge{}}, err
2520 }
2521 return Uptime{i}, nil
2522 }
2523
2524 // Inst returns the underlying metric instrument.
2525 func (m Uptime) Inst() metric.Float64Gauge {
2526 return m.Float64Gauge
2527 }
2528
2529 // Name returns the semantic convention name of the instrument.
2530 func (Uptime) Name() string {
2531 return "system.uptime"
2532 }
2533
2534 // Unit returns the semantic convention unit of the instrument
2535 func (Uptime) Unit() string {
2536 return "s"
2537 }
2538
2539 // Description returns the semantic convention description of the instrument
2540 func (Uptime) Description() string {
2541 return "The time the system has been running"
2542 }
2543
2544 // Record records val to the current distribution.
2545 //
2546 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
2547 // seconds as a floating point number with the highest precision available.
2548 // The actual accuracy would depend on the instrumentation and operating system.
2549 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
2550 if len(attrs) == 0 {
2551 m.Float64Gauge.Record(ctx, val)
2552 }
2553
2554 o := recOptPool.Get().(*[]metric.RecordOption)
2555 defer func() {
2556 *o = (*o)[:0]
2557 recOptPool.Put(o)
2558 }()
2559
2560 *o = append(*o, metric.WithAttributes(attrs...))
2561 m.Float64Gauge.Record(ctx, val, *o...)
2562 }