Debian Codegraph @

semconv/v1.39.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 // CPUModeAttr is an attribute conforming to the cpu.mode semantic conventions.
25 // It represents the mode of the CPU.
26 type CPUModeAttr string
27
28 var (
29 // CPUModeUser is the user.
30 CPUModeUser CPUModeAttr = "user"
31 // CPUModeSystem is the system.
32 CPUModeSystem CPUModeAttr = "system"
33 // CPUModeNice is the nice.
34 CPUModeNice CPUModeAttr = "nice"
35 // CPUModeIdle is the idle.
36 CPUModeIdle CPUModeAttr = "idle"
37 // CPUModeIOWait is the IO Wait.
38 CPUModeIOWait CPUModeAttr = "iowait"
39 // CPUModeInterrupt is the interrupt.
40 CPUModeInterrupt CPUModeAttr = "interrupt"
41 // CPUModeSteal is the steal.
42 CPUModeSteal CPUModeAttr = "steal"
43 // CPUModeKernel is the kernel.
44 CPUModeKernel CPUModeAttr = "kernel"
45 )
46
47 // DiskIODirectionAttr is an attribute conforming to the disk.io.direction
48 // semantic conventions. It represents the disk IO operation direction.
49 type DiskIODirectionAttr string
50
51 var (
52 // DiskIODirectionRead is the standardized value "read" of DiskIODirectionAttr.
53 DiskIODirectionRead DiskIODirectionAttr = "read"
54 // DiskIODirectionWrite is the standardized value "write" of
55 // DiskIODirectionAttr.
56 DiskIODirectionWrite DiskIODirectionAttr = "write"
57 )
58
59 // NetworkConnectionStateAttr is an attribute conforming to the
60 // network.connection.state semantic conventions. It represents the state of
61 // network connection.
62 type NetworkConnectionStateAttr string
63
64 var (
65 // NetworkConnectionStateClosed is the standardized value "closed" of
66 // NetworkConnectionStateAttr.
67 NetworkConnectionStateClosed NetworkConnectionStateAttr = "closed"
68 // NetworkConnectionStateCloseWait is the standardized value "close_wait" of
69 // NetworkConnectionStateAttr.
70 NetworkConnectionStateCloseWait NetworkConnectionStateAttr = "close_wait"
71 // NetworkConnectionStateClosing is the standardized value "closing" of
72 // NetworkConnectionStateAttr.
73 NetworkConnectionStateClosing NetworkConnectionStateAttr = "closing"
74 // NetworkConnectionStateEstablished is the standardized value "established" of
75 // NetworkConnectionStateAttr.
76 NetworkConnectionStateEstablished NetworkConnectionStateAttr = "established"
77 // NetworkConnectionStateFinWait1 is the standardized value "fin_wait_1" of
78 // NetworkConnectionStateAttr.
79 NetworkConnectionStateFinWait1 NetworkConnectionStateAttr = "fin_wait_1"
80 // NetworkConnectionStateFinWait2 is the standardized value "fin_wait_2" of
81 // NetworkConnectionStateAttr.
82 NetworkConnectionStateFinWait2 NetworkConnectionStateAttr = "fin_wait_2"
83 // NetworkConnectionStateLastAck is the standardized value "last_ack" of
84 // NetworkConnectionStateAttr.
85 NetworkConnectionStateLastAck NetworkConnectionStateAttr = "last_ack"
86 // NetworkConnectionStateListen is the standardized value "listen" of
87 // NetworkConnectionStateAttr.
88 NetworkConnectionStateListen NetworkConnectionStateAttr = "listen"
89 // NetworkConnectionStateSynReceived is the standardized value "syn_received" of
90 // NetworkConnectionStateAttr.
91 NetworkConnectionStateSynReceived NetworkConnectionStateAttr = "syn_received"
92 // NetworkConnectionStateSynSent is the standardized value "syn_sent" of
93 // NetworkConnectionStateAttr.
94 NetworkConnectionStateSynSent NetworkConnectionStateAttr = "syn_sent"
95 // NetworkConnectionStateTimeWait is the standardized value "time_wait" of
96 // NetworkConnectionStateAttr.
97 NetworkConnectionStateTimeWait NetworkConnectionStateAttr = "time_wait"
98 )
99
100 // NetworkIODirectionAttr is an attribute conforming to the network.io.direction
101 // semantic conventions. It represents the network IO operation direction.
102 type NetworkIODirectionAttr string
103
104 var (
105 // NetworkIODirectionTransmit is the standardized value "transmit" of
106 // NetworkIODirectionAttr.
107 NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
108 // NetworkIODirectionReceive is the standardized value "receive" of
109 // NetworkIODirectionAttr.
110 NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
111 )
112
113 // NetworkTransportAttr is an attribute conforming to the network.transport
114 // semantic conventions. It represents the [OSI transport layer] or
115 // [inter-process communication method].
116 //
117 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
118 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
119 type NetworkTransportAttr string
120
121 var (
122 // NetworkTransportTCP is the TCP.
123 NetworkTransportTCP NetworkTransportAttr = "tcp"
124 // NetworkTransportUDP is the UDP.
125 NetworkTransportUDP NetworkTransportAttr = "udp"
126 // NetworkTransportPipe is the named or anonymous pipe.
127 NetworkTransportPipe NetworkTransportAttr = "pipe"
128 // NetworkTransportUnix is the unix domain socket.
129 NetworkTransportUnix NetworkTransportAttr = "unix"
130 // NetworkTransportQUIC is the QUIC.
131 NetworkTransportQUIC NetworkTransportAttr = "quic"
132 )
133
134 // ProcessStateAttr is an attribute conforming to the process.state semantic
135 // conventions. It represents the process state, e.g.,
136 // [Linux Process State Codes].
137 //
138 // [Linux Process State Codes]: https://man7.org/linux/man-pages/man1/ps.1.html#PROCESS_STATE_CODES
139 type ProcessStateAttr string
140
141 var (
142 // ProcessStateRunning is the standardized value "running" of ProcessStateAttr.
143 ProcessStateRunning ProcessStateAttr = "running"
144 // ProcessStateSleeping is the standardized value "sleeping" of
145 // ProcessStateAttr.
146 ProcessStateSleeping ProcessStateAttr = "sleeping"
147 // ProcessStateStopped is the standardized value "stopped" of ProcessStateAttr.
148 ProcessStateStopped ProcessStateAttr = "stopped"
149 // ProcessStateDefunct is the standardized value "defunct" of ProcessStateAttr.
150 ProcessStateDefunct ProcessStateAttr = "defunct"
151 )
152
153 // FilesystemStateAttr is an attribute conforming to the system.filesystem.state
154 // semantic conventions. It represents the filesystem state.
155 type FilesystemStateAttr string
156
157 var (
158 // FilesystemStateUsed is the standardized value "used" of FilesystemStateAttr.
159 FilesystemStateUsed FilesystemStateAttr = "used"
160 // FilesystemStateFree is the standardized value "free" of FilesystemStateAttr.
161 FilesystemStateFree FilesystemStateAttr = "free"
162 // FilesystemStateReserved is the standardized value "reserved" of
163 // FilesystemStateAttr.
164 FilesystemStateReserved FilesystemStateAttr = "reserved"
165 )
166
167 // FilesystemTypeAttr is an attribute conforming to the system.filesystem.type
168 // semantic conventions. It represents the filesystem type.
169 type FilesystemTypeAttr string
170
171 var (
172 // FilesystemTypeFat32 is the standardized value "fat32" of FilesystemTypeAttr.
173 FilesystemTypeFat32 FilesystemTypeAttr = "fat32"
174 // FilesystemTypeExfat is the standardized value "exfat" of FilesystemTypeAttr.
175 FilesystemTypeExfat FilesystemTypeAttr = "exfat"
176 // FilesystemTypeNtfs is the standardized value "ntfs" of FilesystemTypeAttr.
177 FilesystemTypeNtfs FilesystemTypeAttr = "ntfs"
178 // FilesystemTypeRefs is the standardized value "refs" of FilesystemTypeAttr.
179 FilesystemTypeRefs FilesystemTypeAttr = "refs"
180 // FilesystemTypeHfsplus is the standardized value "hfsplus" of
181 // FilesystemTypeAttr.
182 FilesystemTypeHfsplus FilesystemTypeAttr = "hfsplus"
183 // FilesystemTypeExt4 is the standardized value "ext4" of FilesystemTypeAttr.
184 FilesystemTypeExt4 FilesystemTypeAttr = "ext4"
185 )
186
187 // MemoryLinuxSlabStateAttr is an attribute conforming to the
188 // system.memory.linux.slab.state semantic conventions. It represents the Linux
189 // Slab memory state.
190 type MemoryLinuxSlabStateAttr string
191
192 var (
193 // MemoryLinuxSlabStateReclaimable is the standardized value "reclaimable" of
194 // MemoryLinuxSlabStateAttr.
195 MemoryLinuxSlabStateReclaimable MemoryLinuxSlabStateAttr = "reclaimable"
196 // MemoryLinuxSlabStateUnreclaimable is the standardized value "unreclaimable"
197 // of MemoryLinuxSlabStateAttr.
198 MemoryLinuxSlabStateUnreclaimable MemoryLinuxSlabStateAttr = "unreclaimable"
199 )
200
201 // MemoryStateAttr is an attribute conforming to the system.memory.state semantic
202 // conventions. It represents the memory state.
203 type MemoryStateAttr string
204
205 var (
206 // MemoryStateUsed is the actual used virtual memory in bytes.
207 MemoryStateUsed MemoryStateAttr = "used"
208 // MemoryStateFree is the standardized value "free" of MemoryStateAttr.
209 MemoryStateFree MemoryStateAttr = "free"
210 // MemoryStateBuffers is the standardized value "buffers" of MemoryStateAttr.
211 MemoryStateBuffers MemoryStateAttr = "buffers"
212 // MemoryStateCached is the standardized value "cached" of MemoryStateAttr.
213 MemoryStateCached MemoryStateAttr = "cached"
214 )
215
216 // PagingDirectionAttr is an attribute conforming to the system.paging.direction
217 // semantic conventions. It represents the paging access direction.
218 type PagingDirectionAttr string
219
220 var (
221 // PagingDirectionIn is the standardized value "in" of PagingDirectionAttr.
222 PagingDirectionIn PagingDirectionAttr = "in"
223 // PagingDirectionOut is the standardized value "out" of PagingDirectionAttr.
224 PagingDirectionOut PagingDirectionAttr = "out"
225 )
226
227 // PagingFaultTypeAttr is an attribute conforming to the system.paging.fault.type
228 // semantic conventions. It represents the paging fault type.
229 type PagingFaultTypeAttr string
230
231 var (
232 // PagingFaultTypeMajor is the standardized value "major" of
233 // PagingFaultTypeAttr.
234 PagingFaultTypeMajor PagingFaultTypeAttr = "major"
235 // PagingFaultTypeMinor is the standardized value "minor" of
236 // PagingFaultTypeAttr.
237 PagingFaultTypeMinor PagingFaultTypeAttr = "minor"
238 )
239
240 // PagingStateAttr is an attribute conforming to the system.paging.state semantic
241 // conventions. It represents the memory paging state.
242 type PagingStateAttr string
243
244 var (
245 // PagingStateUsed is the standardized value "used" of PagingStateAttr.
246 PagingStateUsed PagingStateAttr = "used"
247 // PagingStateFree is the standardized value "free" of PagingStateAttr.
248 PagingStateFree PagingStateAttr = "free"
249 )
250
251 // CPUFrequency is an instrument used to record metric values conforming to the
252 // "system.cpu.frequency" semantic conventions. It represents the operating
253 // frequency of the logical CPU in Hertz.
254 type CPUFrequency struct {
255 metric.Int64Gauge
256 }
257
258 var newCPUFrequencyOpts = []metric.Int64GaugeOption{
259 metric.WithDescription("Operating frequency of the logical CPU in Hertz."),
260 metric.WithUnit("Hz"),
261 }
262
263 // NewCPUFrequency returns a new CPUFrequency instrument.
264 func NewCPUFrequency(
265 m metric.Meter,
266 opt ...metric.Int64GaugeOption,
267 ) (CPUFrequency, error) {
268 // Check if the meter is nil.
269 if m == nil {
270 return CPUFrequency{noop.Int64Gauge{}}, nil
271 }
272
273 if len(opt) == 0 {
274 opt = newCPUFrequencyOpts
275 } else {
276 opt = append(opt, newCPUFrequencyOpts...)
277 }
278
279 i, err := m.Int64Gauge(
280 "system.cpu.frequency",
281 opt...,
282 )
283 if err != nil {
284 return CPUFrequency{noop.Int64Gauge{}}, err
285 }
286 return CPUFrequency{i}, nil
287 }
288
289 // Inst returns the underlying metric instrument.
290 func (m CPUFrequency) Inst() metric.Int64Gauge {
291 return m.Int64Gauge
292 }
293
294 // Name returns the semantic convention name of the instrument.
295 func (CPUFrequency) Name() string {
296 return "system.cpu.frequency"
297 }
298
299 // Unit returns the semantic convention unit of the instrument
300 func (CPUFrequency) Unit() string {
301 return "Hz"
302 }
303
304 // Description returns the semantic convention description of the instrument
305 func (CPUFrequency) Description() string {
306 return "Operating frequency of the logical CPU in Hertz."
307 }
308
309 // Record records val to the current distribution for attrs.
310 //
311 // All additional attrs passed are included in the recorded value.
312 func (m CPUFrequency) Record(
313 ctx context.Context,
314 val int64,
315 attrs ...attribute.KeyValue,
316 ) {
317 if len(attrs) == 0 {
318 m.Int64Gauge.Record(ctx, val)
319 return
320 }
321
322 o := recOptPool.Get().(*[]metric.RecordOption)
323 defer func() {
324 *o = (*o)[:0]
325 recOptPool.Put(o)
326 }()
327
328 *o = append(
329 *o,
330 metric.WithAttributes(
331 attrs...,
332 ),
333 )
334
335 m.Int64Gauge.Record(ctx, val, *o...)
336 }
337
338 // RecordSet records val to the current distribution for set.
339 func (m CPUFrequency) RecordSet(ctx context.Context, val int64, set attribute.Set) {
340 if set.Len() == 0 {
341 m.Int64Gauge.Record(ctx, val)
342 return
343 }
344
345 o := recOptPool.Get().(*[]metric.RecordOption)
346 defer func() {
347 *o = (*o)[:0]
348 recOptPool.Put(o)
349 }()
350
351 *o = append(*o, metric.WithAttributeSet(set))
352 m.Int64Gauge.Record(ctx, val, *o...)
353 }
354
355 // AttrCPULogicalNumber returns an optional attribute for the
356 // "cpu.logical_number" semantic convention. It represents the logical CPU number
357 // [0..n-1].
358 func (CPUFrequency) AttrCPULogicalNumber(val int) attribute.KeyValue {
359 return attribute.Int("cpu.logical_number", val)
360 }
361
362 // CPULogicalCount is an instrument used to record metric values conforming to
363 // the "system.cpu.logical.count" semantic conventions. It represents the reports
364 // the number of logical (virtual) processor cores created by the operating
365 // system to manage multitasking.
366 type CPULogicalCount struct {
367 metric.Int64UpDownCounter
368 }
369
370 var newCPULogicalCountOpts = []metric.Int64UpDownCounterOption{
371 metric.WithDescription("Reports the number of logical (virtual) processor cores created by the operating system to manage multitasking."),
372 metric.WithUnit("{cpu}"),
373 }
374
375 // NewCPULogicalCount returns a new CPULogicalCount instrument.
376 func NewCPULogicalCount(
377 m metric.Meter,
378 opt ...metric.Int64UpDownCounterOption,
379 ) (CPULogicalCount, error) {
380 // Check if the meter is nil.
381 if m == nil {
382 return CPULogicalCount{noop.Int64UpDownCounter{}}, nil
383 }
384
385 if len(opt) == 0 {
386 opt = newCPULogicalCountOpts
387 } else {
388 opt = append(opt, newCPULogicalCountOpts...)
389 }
390
391 i, err := m.Int64UpDownCounter(
392 "system.cpu.logical.count",
393 opt...,
394 )
395 if err != nil {
396 return CPULogicalCount{noop.Int64UpDownCounter{}}, err
397 }
398 return CPULogicalCount{i}, nil
399 }
400
401 // Inst returns the underlying metric instrument.
402 func (m CPULogicalCount) Inst() metric.Int64UpDownCounter {
403 return m.Int64UpDownCounter
404 }
405
406 // Name returns the semantic convention name of the instrument.
407 func (CPULogicalCount) Name() string {
408 return "system.cpu.logical.count"
409 }
410
411 // Unit returns the semantic convention unit of the instrument
412 func (CPULogicalCount) Unit() string {
413 return "{cpu}"
414 }
415
416 // Description returns the semantic convention description of the instrument
417 func (CPULogicalCount) Description() string {
418 return "Reports the number of logical (virtual) processor cores created by the operating system to manage multitasking."
419 }
420
421 // Add adds incr to the existing count for attrs.
422 //
423 // Calculated by multiplying the number of sockets by the number of cores per
424 // socket, and then by the number of threads per core
425 func (m CPULogicalCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
426 if len(attrs) == 0 {
427 m.Int64UpDownCounter.Add(ctx, incr)
428 return
429 }
430
431 o := addOptPool.Get().(*[]metric.AddOption)
432 defer func() {
433 *o = (*o)[:0]
434 addOptPool.Put(o)
435 }()
436
437 *o = append(*o, metric.WithAttributes(attrs...))
438 m.Int64UpDownCounter.Add(ctx, incr, *o...)
439 }
440
441 // AddSet adds incr to the existing count for set.
442 //
443 // Calculated by multiplying the number of sockets by the number of cores per
444 // socket, and then by the number of threads per core
445 func (m CPULogicalCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
446 if set.Len() == 0 {
447 m.Int64UpDownCounter.Add(ctx, incr)
448 return
449 }
450
451 o := addOptPool.Get().(*[]metric.AddOption)
452 defer func() {
453 *o = (*o)[:0]
454 addOptPool.Put(o)
455 }()
456
457 *o = append(*o, metric.WithAttributeSet(set))
458 m.Int64UpDownCounter.Add(ctx, incr, *o...)
459 }
460
461 // CPUPhysicalCount is an instrument used to record metric values conforming to
462 // the "system.cpu.physical.count" semantic conventions. It represents the
463 // reports the number of actual physical processor cores on the hardware.
464 type CPUPhysicalCount struct {
465 metric.Int64UpDownCounter
466 }
467
468 var newCPUPhysicalCountOpts = []metric.Int64UpDownCounterOption{
469 metric.WithDescription("Reports the number of actual physical processor cores on the hardware."),
470 metric.WithUnit("{cpu}"),
471 }
472
473 // NewCPUPhysicalCount returns a new CPUPhysicalCount instrument.
474 func NewCPUPhysicalCount(
475 m metric.Meter,
476 opt ...metric.Int64UpDownCounterOption,
477 ) (CPUPhysicalCount, error) {
478 // Check if the meter is nil.
479 if m == nil {
480 return CPUPhysicalCount{noop.Int64UpDownCounter{}}, nil
481 }
482
483 if len(opt) == 0 {
484 opt = newCPUPhysicalCountOpts
485 } else {
486 opt = append(opt, newCPUPhysicalCountOpts...)
487 }
488
489 i, err := m.Int64UpDownCounter(
490 "system.cpu.physical.count",
491 opt...,
492 )
493 if err != nil {
494 return CPUPhysicalCount{noop.Int64UpDownCounter{}}, err
495 }
496 return CPUPhysicalCount{i}, nil
497 }
498
499 // Inst returns the underlying metric instrument.
500 func (m CPUPhysicalCount) Inst() metric.Int64UpDownCounter {
501 return m.Int64UpDownCounter
502 }
503
504 // Name returns the semantic convention name of the instrument.
505 func (CPUPhysicalCount) Name() string {
506 return "system.cpu.physical.count"
507 }
508
509 // Unit returns the semantic convention unit of the instrument
510 func (CPUPhysicalCount) Unit() string {
511 return "{cpu}"
512 }
513
514 // Description returns the semantic convention description of the instrument
515 func (CPUPhysicalCount) Description() string {
516 return "Reports the number of actual physical processor cores on the hardware."
517 }
518
519 // Add adds incr to the existing count for attrs.
520 //
521 // Calculated by multiplying the number of sockets by the number of cores per
522 // socket
523 func (m CPUPhysicalCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
524 if len(attrs) == 0 {
525 m.Int64UpDownCounter.Add(ctx, incr)
526 return
527 }
528
529 o := addOptPool.Get().(*[]metric.AddOption)
530 defer func() {
531 *o = (*o)[:0]
532 addOptPool.Put(o)
533 }()
534
535 *o = append(*o, metric.WithAttributes(attrs...))
536 m.Int64UpDownCounter.Add(ctx, incr, *o...)
537 }
538
539 // AddSet adds incr to the existing count for set.
540 //
541 // Calculated by multiplying the number of sockets by the number of cores per
542 // socket
543 func (m CPUPhysicalCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
544 if set.Len() == 0 {
545 m.Int64UpDownCounter.Add(ctx, incr)
546 return
547 }
548
549 o := addOptPool.Get().(*[]metric.AddOption)
550 defer func() {
551 *o = (*o)[:0]
552 addOptPool.Put(o)
553 }()
554
555 *o = append(*o, metric.WithAttributeSet(set))
556 m.Int64UpDownCounter.Add(ctx, incr, *o...)
557 }
558
559 // CPUTime is an instrument used to record metric values conforming to the
560 // "system.cpu.time" semantic conventions. It represents the seconds each logical
561 // CPU spent on each mode.
562 type CPUTime struct {
563 metric.Float64ObservableCounter
564 }
565
566 var newCPUTimeOpts = []metric.Float64ObservableCounterOption{
567 metric.WithDescription("Seconds each logical CPU spent on each mode."),
568 metric.WithUnit("s"),
569 }
570
571 // NewCPUTime returns a new CPUTime instrument.
572 func NewCPUTime(
573 m metric.Meter,
574 opt ...metric.Float64ObservableCounterOption,
575 ) (CPUTime, error) {
576 // Check if the meter is nil.
577 if m == nil {
578 return CPUTime{noop.Float64ObservableCounter{}}, nil
579 }
580
581 if len(opt) == 0 {
582 opt = newCPUTimeOpts
583 } else {
584 opt = append(opt, newCPUTimeOpts...)
585 }
586
587 i, err := m.Float64ObservableCounter(
588 "system.cpu.time",
589 opt...,
590 )
591 if err != nil {
592 return CPUTime{noop.Float64ObservableCounter{}}, err
593 }
594 return CPUTime{i}, nil
595 }
596
597 // Inst returns the underlying metric instrument.
598 func (m CPUTime) Inst() metric.Float64ObservableCounter {
599 return m.Float64ObservableCounter
600 }
601
602 // Name returns the semantic convention name of the instrument.
603 func (CPUTime) Name() string {
604 return "system.cpu.time"
605 }
606
607 // Unit returns the semantic convention unit of the instrument
608 func (CPUTime) Unit() string {
609 return "s"
610 }
611
612 // Description returns the semantic convention description of the instrument
613 func (CPUTime) Description() string {
614 return "Seconds each logical CPU spent on each mode."
615 }
616
617 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
618 // convention. It represents the mode of the CPU.
619 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
620 return attribute.String("cpu.mode", string(val))
621 }
622
623 // AttrCPULogicalNumber returns an optional attribute for the
624 // "cpu.logical_number" semantic convention. It represents the logical CPU number
625 // [0..n-1].
626 func (CPUTime) AttrCPULogicalNumber(val int) attribute.KeyValue {
627 return attribute.Int("cpu.logical_number", val)
628 }
629
630 // CPUUtilization is an instrument used to record metric values conforming to the
631 // "system.cpu.utilization" semantic conventions. It represents the for each
632 // logical CPU, the utilization is calculated as the change in cumulative CPU
633 // time (cpu.time) over a measurement interval, divided by the elapsed time.
634 type CPUUtilization struct {
635 metric.Int64Gauge
636 }
637
638 var newCPUUtilizationOpts = []metric.Int64GaugeOption{
639 metric.WithDescription("For each logical CPU, the utilization is calculated as the change in cumulative CPU time (cpu.time) over a measurement interval, divided by the elapsed time."),
640 metric.WithUnit("1"),
641 }
642
643 // NewCPUUtilization returns a new CPUUtilization instrument.
644 func NewCPUUtilization(
645 m metric.Meter,
646 opt ...metric.Int64GaugeOption,
647 ) (CPUUtilization, error) {
648 // Check if the meter is nil.
649 if m == nil {
650 return CPUUtilization{noop.Int64Gauge{}}, nil
651 }
652
653 if len(opt) == 0 {
654 opt = newCPUUtilizationOpts
655 } else {
656 opt = append(opt, newCPUUtilizationOpts...)
657 }
658
659 i, err := m.Int64Gauge(
660 "system.cpu.utilization",
661 opt...,
662 )
663 if err != nil {
664 return CPUUtilization{noop.Int64Gauge{}}, err
665 }
666 return CPUUtilization{i}, nil
667 }
668
669 // Inst returns the underlying metric instrument.
670 func (m CPUUtilization) Inst() metric.Int64Gauge {
671 return m.Int64Gauge
672 }
673
674 // Name returns the semantic convention name of the instrument.
675 func (CPUUtilization) Name() string {
676 return "system.cpu.utilization"
677 }
678
679 // Unit returns the semantic convention unit of the instrument
680 func (CPUUtilization) Unit() string {
681 return "1"
682 }
683
684 // Description returns the semantic convention description of the instrument
685 func (CPUUtilization) Description() string {
686 return "For each logical CPU, the utilization is calculated as the change in cumulative CPU time (cpu.time) over a measurement interval, divided by the elapsed time."
687 }
688
689 // Record records val to the current distribution for attrs.
690 //
691 // All additional attrs passed are included in the recorded value.
692 func (m CPUUtilization) Record(
693 ctx context.Context,
694 val int64,
695 attrs ...attribute.KeyValue,
696 ) {
697 if len(attrs) == 0 {
698 m.Int64Gauge.Record(ctx, val)
699 return
700 }
701
702 o := recOptPool.Get().(*[]metric.RecordOption)
703 defer func() {
704 *o = (*o)[:0]
705 recOptPool.Put(o)
706 }()
707
708 *o = append(
709 *o,
710 metric.WithAttributes(
711 attrs...,
712 ),
713 )
714
715 m.Int64Gauge.Record(ctx, val, *o...)
716 }
717
718 // RecordSet records val to the current distribution for set.
719 func (m CPUUtilization) RecordSet(ctx context.Context, val int64, set attribute.Set) {
720 if set.Len() == 0 {
721 m.Int64Gauge.Record(ctx, val)
722 return
723 }
724
725 o := recOptPool.Get().(*[]metric.RecordOption)
726 defer func() {
727 *o = (*o)[:0]
728 recOptPool.Put(o)
729 }()
730
731 *o = append(*o, metric.WithAttributeSet(set))
732 m.Int64Gauge.Record(ctx, val, *o...)
733 }
734
735 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
736 // convention. It represents the mode of the CPU.
737 func (CPUUtilization) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
738 return attribute.String("cpu.mode", string(val))
739 }
740
741 // AttrCPULogicalNumber returns an optional attribute for the
742 // "cpu.logical_number" semantic convention. It represents the logical CPU number
743 // [0..n-1].
744 func (CPUUtilization) AttrCPULogicalNumber(val int) attribute.KeyValue {
745 return attribute.Int("cpu.logical_number", val)
746 }
747
748 // DiskIO is an instrument used to record metric values conforming to the
749 // "system.disk.io" semantic conventions. It represents the disk bytes
750 // transferred.
751 type DiskIO struct {
752 metric.Int64Counter
753 }
754
755 var newDiskIOOpts = []metric.Int64CounterOption{
756 metric.WithDescription("Disk bytes transferred."),
757 metric.WithUnit("By"),
758 }
759
760 // NewDiskIO returns a new DiskIO instrument.
761 func NewDiskIO(
762 m metric.Meter,
763 opt ...metric.Int64CounterOption,
764 ) (DiskIO, error) {
765 // Check if the meter is nil.
766 if m == nil {
767 return DiskIO{noop.Int64Counter{}}, nil
768 }
769
770 if len(opt) == 0 {
771 opt = newDiskIOOpts
772 } else {
773 opt = append(opt, newDiskIOOpts...)
774 }
775
776 i, err := m.Int64Counter(
777 "system.disk.io",
778 opt...,
779 )
780 if err != nil {
781 return DiskIO{noop.Int64Counter{}}, err
782 }
783 return DiskIO{i}, nil
784 }
785
786 // Inst returns the underlying metric instrument.
787 func (m DiskIO) Inst() metric.Int64Counter {
788 return m.Int64Counter
789 }
790
791 // Name returns the semantic convention name of the instrument.
792 func (DiskIO) Name() string {
793 return "system.disk.io"
794 }
795
796 // Unit returns the semantic convention unit of the instrument
797 func (DiskIO) Unit() string {
798 return "By"
799 }
800
801 // Description returns the semantic convention description of the instrument
802 func (DiskIO) Description() string {
803 return "Disk bytes transferred."
804 }
805
806 // Add adds incr to the existing count for attrs.
807 //
808 // All additional attrs passed are included in the recorded value.
809 func (m DiskIO) Add(
810 ctx context.Context,
811 incr int64,
812 attrs ...attribute.KeyValue,
813 ) {
814 if len(attrs) == 0 {
815 m.Int64Counter.Add(ctx, incr)
816 return
817 }
818
819 o := addOptPool.Get().(*[]metric.AddOption)
820 defer func() {
821 *o = (*o)[:0]
822 addOptPool.Put(o)
823 }()
824
825 *o = append(
826 *o,
827 metric.WithAttributes(
828 attrs...,
829 ),
830 )
831
832 m.Int64Counter.Add(ctx, incr, *o...)
833 }
834
835 // AddSet adds incr to the existing count for set.
836 func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
837 if set.Len() == 0 {
838 m.Int64Counter.Add(ctx, incr)
839 return
840 }
841
842 o := addOptPool.Get().(*[]metric.AddOption)
843 defer func() {
844 *o = (*o)[:0]
845 addOptPool.Put(o)
846 }()
847
848 *o = append(*o, metric.WithAttributeSet(set))
849 m.Int64Counter.Add(ctx, incr, *o...)
850 }
851
852 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
853 // semantic convention. It represents the disk IO operation direction.
854 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
855 return attribute.String("disk.io.direction", string(val))
856 }
857
858 // AttrDevice returns an optional attribute for the "system.device" semantic
859 // convention. It represents the device identifier.
860 func (DiskIO) AttrDevice(val string) attribute.KeyValue {
861 return attribute.String("system.device", val)
862 }
863
864 // DiskIOTime is an instrument used to record metric values conforming to the
865 // "system.disk.io_time" semantic conventions. It represents the time disk spent
866 // activated.
867 type DiskIOTime struct {
868 metric.Float64Counter
869 }
870
871 var newDiskIOTimeOpts = []metric.Float64CounterOption{
872 metric.WithDescription("Time disk spent activated."),
873 metric.WithUnit("s"),
874 }
875
876 // NewDiskIOTime returns a new DiskIOTime instrument.
877 func NewDiskIOTime(
878 m metric.Meter,
879 opt ...metric.Float64CounterOption,
880 ) (DiskIOTime, error) {
881 // Check if the meter is nil.
882 if m == nil {
883 return DiskIOTime{noop.Float64Counter{}}, nil
884 }
885
886 if len(opt) == 0 {
887 opt = newDiskIOTimeOpts
888 } else {
889 opt = append(opt, newDiskIOTimeOpts...)
890 }
891
892 i, err := m.Float64Counter(
893 "system.disk.io_time",
894 opt...,
895 )
896 if err != nil {
897 return DiskIOTime{noop.Float64Counter{}}, err
898 }
899 return DiskIOTime{i}, nil
900 }
901
902 // Inst returns the underlying metric instrument.
903 func (m DiskIOTime) Inst() metric.Float64Counter {
904 return m.Float64Counter
905 }
906
907 // Name returns the semantic convention name of the instrument.
908 func (DiskIOTime) Name() string {
909 return "system.disk.io_time"
910 }
911
912 // Unit returns the semantic convention unit of the instrument
913 func (DiskIOTime) Unit() string {
914 return "s"
915 }
916
917 // Description returns the semantic convention description of the instrument
918 func (DiskIOTime) Description() string {
919 return "Time disk spent activated."
920 }
921
922 // Add adds incr to the existing count for attrs.
923 //
924 // All additional attrs passed are included in the recorded value.
925 //
926 // The real elapsed time ("wall clock") used in the I/O path (time from
927 // operations running in parallel are not counted). Measured as:
928 //
929 // - Linux: Field 13 from [procfs-diskstats]
930 // - Windows: The complement of
931 // ["Disk% Idle Time"]
932 // performance counter: `uptime * (100 - "Disk\% Idle Time") / 100`
933 //
934 //
935 // [procfs-diskstats]: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
936 // ["Disk% Idle Time"]: https://learn.microsoft.com/archive/blogs/askcore/windows-performance-monitor-disk-counters-explained#windows-performance-monitor-disk-counters-explained
937 func (m DiskIOTime) Add(
938 ctx context.Context,
939 incr float64,
940 attrs ...attribute.KeyValue,
941 ) {
942 if len(attrs) == 0 {
943 m.Float64Counter.Add(ctx, incr)
944 return
945 }
946
947 o := addOptPool.Get().(*[]metric.AddOption)
948 defer func() {
949 *o = (*o)[:0]
950 addOptPool.Put(o)
951 }()
952
953 *o = append(
954 *o,
955 metric.WithAttributes(
956 attrs...,
957 ),
958 )
959
960 m.Float64Counter.Add(ctx, incr, *o...)
961 }
962
963 // AddSet adds incr to the existing count for set.
964 //
965 // The real elapsed time ("wall clock") used in the I/O path (time from
966 // operations running in parallel are not counted). Measured as:
967 //
968 // - Linux: Field 13 from [procfs-diskstats]
969 // - Windows: The complement of
970 // ["Disk% Idle Time"]
971 // performance counter: `uptime * (100 - "Disk\% Idle Time") / 100`
972 //
973 //
974 // [procfs-diskstats]: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
975 // ["Disk% Idle Time"]: https://learn.microsoft.com/archive/blogs/askcore/windows-performance-monitor-disk-counters-explained#windows-performance-monitor-disk-counters-explained
976 func (m DiskIOTime) AddSet(ctx context.Context, incr float64, set attribute.Set) {
977 if set.Len() == 0 {
978 m.Float64Counter.Add(ctx, incr)
979 return
980 }
981
982 o := addOptPool.Get().(*[]metric.AddOption)
983 defer func() {
984 *o = (*o)[:0]
985 addOptPool.Put(o)
986 }()
987
988 *o = append(*o, metric.WithAttributeSet(set))
989 m.Float64Counter.Add(ctx, incr, *o...)
990 }
991
992 // AttrDevice returns an optional attribute for the "system.device" semantic
993 // convention. It represents the device identifier.
994 func (DiskIOTime) AttrDevice(val string) attribute.KeyValue {
995 return attribute.String("system.device", val)
996 }
997
998 // DiskLimit is an instrument used to record metric values conforming to the
999 // "system.disk.limit" semantic conventions. It represents the total storage
1000 // capacity of the disk.
1001 type DiskLimit struct {
1002 metric.Int64UpDownCounter
1003 }
1004
1005 var newDiskLimitOpts = []metric.Int64UpDownCounterOption{
1006 metric.WithDescription("The total storage capacity of the disk."),
1007 metric.WithUnit("By"),
1008 }
1009
1010 // NewDiskLimit returns a new DiskLimit instrument.
1011 func NewDiskLimit(
1012 m metric.Meter,
1013 opt ...metric.Int64UpDownCounterOption,
1014 ) (DiskLimit, error) {
1015 // Check if the meter is nil.
1016 if m == nil {
1017 return DiskLimit{noop.Int64UpDownCounter{}}, nil
1018 }
1019
1020 if len(opt) == 0 {
1021 opt = newDiskLimitOpts
1022 } else {
1023 opt = append(opt, newDiskLimitOpts...)
1024 }
1025
1026 i, err := m.Int64UpDownCounter(
1027 "system.disk.limit",
1028 opt...,
1029 )
1030 if err != nil {
1031 return DiskLimit{noop.Int64UpDownCounter{}}, err
1032 }
1033 return DiskLimit{i}, nil
1034 }
1035
1036 // Inst returns the underlying metric instrument.
1037 func (m DiskLimit) Inst() metric.Int64UpDownCounter {
1038 return m.Int64UpDownCounter
1039 }
1040
1041 // Name returns the semantic convention name of the instrument.
1042 func (DiskLimit) Name() string {
1043 return "system.disk.limit"
1044 }
1045
1046 // Unit returns the semantic convention unit of the instrument
1047 func (DiskLimit) Unit() string {
1048 return "By"
1049 }
1050
1051 // Description returns the semantic convention description of the instrument
1052 func (DiskLimit) Description() string {
1053 return "The total storage capacity of the disk."
1054 }
1055
1056 // Add adds incr to the existing count for attrs.
1057 //
1058 // All additional attrs passed are included in the recorded value.
1059 func (m DiskLimit) Add(
1060 ctx context.Context,
1061 incr int64,
1062 attrs ...attribute.KeyValue,
1063 ) {
1064 if len(attrs) == 0 {
1065 m.Int64UpDownCounter.Add(ctx, incr)
1066 return
1067 }
1068
1069 o := addOptPool.Get().(*[]metric.AddOption)
1070 defer func() {
1071 *o = (*o)[:0]
1072 addOptPool.Put(o)
1073 }()
1074
1075 *o = append(
1076 *o,
1077 metric.WithAttributes(
1078 attrs...,
1079 ),
1080 )
1081
1082 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1083 }
1084
1085 // AddSet adds incr to the existing count for set.
1086 func (m DiskLimit) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1087 if set.Len() == 0 {
1088 m.Int64UpDownCounter.Add(ctx, incr)
1089 return
1090 }
1091
1092 o := addOptPool.Get().(*[]metric.AddOption)
1093 defer func() {
1094 *o = (*o)[:0]
1095 addOptPool.Put(o)
1096 }()
1097
1098 *o = append(*o, metric.WithAttributeSet(set))
1099 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1100 }
1101
1102 // AttrDevice returns an optional attribute for the "system.device" semantic
1103 // convention. It represents the device identifier.
1104 func (DiskLimit) AttrDevice(val string) attribute.KeyValue {
1105 return attribute.String("system.device", val)
1106 }
1107
1108 // DiskMerged is an instrument used to record metric values conforming to the
1109 // "system.disk.merged" semantic conventions. It represents the number of disk
1110 // reads/writes merged into single physical disk access operations.
1111 type DiskMerged struct {
1112 metric.Int64Counter
1113 }
1114
1115 var newDiskMergedOpts = []metric.Int64CounterOption{
1116 metric.WithDescription("The number of disk reads/writes merged into single physical disk access operations."),
1117 metric.WithUnit("{operation}"),
1118 }
1119
1120 // NewDiskMerged returns a new DiskMerged instrument.
1121 func NewDiskMerged(
1122 m metric.Meter,
1123 opt ...metric.Int64CounterOption,
1124 ) (DiskMerged, error) {
1125 // Check if the meter is nil.
1126 if m == nil {
1127 return DiskMerged{noop.Int64Counter{}}, nil
1128 }
1129
1130 if len(opt) == 0 {
1131 opt = newDiskMergedOpts
1132 } else {
1133 opt = append(opt, newDiskMergedOpts...)
1134 }
1135
1136 i, err := m.Int64Counter(
1137 "system.disk.merged",
1138 opt...,
1139 )
1140 if err != nil {
1141 return DiskMerged{noop.Int64Counter{}}, err
1142 }
1143 return DiskMerged{i}, nil
1144 }
1145
1146 // Inst returns the underlying metric instrument.
1147 func (m DiskMerged) Inst() metric.Int64Counter {
1148 return m.Int64Counter
1149 }
1150
1151 // Name returns the semantic convention name of the instrument.
1152 func (DiskMerged) Name() string {
1153 return "system.disk.merged"
1154 }
1155
1156 // Unit returns the semantic convention unit of the instrument
1157 func (DiskMerged) Unit() string {
1158 return "{operation}"
1159 }
1160
1161 // Description returns the semantic convention description of the instrument
1162 func (DiskMerged) Description() string {
1163 return "The number of disk reads/writes merged into single physical disk access operations."
1164 }
1165
1166 // Add adds incr to the existing count for attrs.
1167 //
1168 // All additional attrs passed are included in the recorded value.
1169 func (m DiskMerged) Add(
1170 ctx context.Context,
1171 incr int64,
1172 attrs ...attribute.KeyValue,
1173 ) {
1174 if len(attrs) == 0 {
1175 m.Int64Counter.Add(ctx, incr)
1176 return
1177 }
1178
1179 o := addOptPool.Get().(*[]metric.AddOption)
1180 defer func() {
1181 *o = (*o)[:0]
1182 addOptPool.Put(o)
1183 }()
1184
1185 *o = append(
1186 *o,
1187 metric.WithAttributes(
1188 attrs...,
1189 ),
1190 )
1191
1192 m.Int64Counter.Add(ctx, incr, *o...)
1193 }
1194
1195 // AddSet adds incr to the existing count for set.
1196 func (m DiskMerged) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1197 if set.Len() == 0 {
1198 m.Int64Counter.Add(ctx, incr)
1199 return
1200 }
1201
1202 o := addOptPool.Get().(*[]metric.AddOption)
1203 defer func() {
1204 *o = (*o)[:0]
1205 addOptPool.Put(o)
1206 }()
1207
1208 *o = append(*o, metric.WithAttributeSet(set))
1209 m.Int64Counter.Add(ctx, incr, *o...)
1210 }
1211
1212 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
1213 // semantic convention. It represents the disk IO operation direction.
1214 func (DiskMerged) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
1215 return attribute.String("disk.io.direction", string(val))
1216 }
1217
1218 // AttrDevice returns an optional attribute for the "system.device" semantic
1219 // convention. It represents the device identifier.
1220 func (DiskMerged) AttrDevice(val string) attribute.KeyValue {
1221 return attribute.String("system.device", val)
1222 }
1223
1224 // DiskOperationTime is an instrument used to record metric values conforming to
1225 // the "system.disk.operation_time" semantic conventions. It represents the sum
1226 // of the time each operation took to complete.
1227 type DiskOperationTime struct {
1228 metric.Float64Counter
1229 }
1230
1231 var newDiskOperationTimeOpts = []metric.Float64CounterOption{
1232 metric.WithDescription("Sum of the time each operation took to complete."),
1233 metric.WithUnit("s"),
1234 }
1235
1236 // NewDiskOperationTime returns a new DiskOperationTime instrument.
1237 func NewDiskOperationTime(
1238 m metric.Meter,
1239 opt ...metric.Float64CounterOption,
1240 ) (DiskOperationTime, error) {
1241 // Check if the meter is nil.
1242 if m == nil {
1243 return DiskOperationTime{noop.Float64Counter{}}, nil
1244 }
1245
1246 if len(opt) == 0 {
1247 opt = newDiskOperationTimeOpts
1248 } else {
1249 opt = append(opt, newDiskOperationTimeOpts...)
1250 }
1251
1252 i, err := m.Float64Counter(
1253 "system.disk.operation_time",
1254 opt...,
1255 )
1256 if err != nil {
1257 return DiskOperationTime{noop.Float64Counter{}}, err
1258 }
1259 return DiskOperationTime{i}, nil
1260 }
1261
1262 // Inst returns the underlying metric instrument.
1263 func (m DiskOperationTime) Inst() metric.Float64Counter {
1264 return m.Float64Counter
1265 }
1266
1267 // Name returns the semantic convention name of the instrument.
1268 func (DiskOperationTime) Name() string {
1269 return "system.disk.operation_time"
1270 }
1271
1272 // Unit returns the semantic convention unit of the instrument
1273 func (DiskOperationTime) Unit() string {
1274 return "s"
1275 }
1276
1277 // Description returns the semantic convention description of the instrument
1278 func (DiskOperationTime) Description() string {
1279 return "Sum of the time each operation took to complete."
1280 }
1281
1282 // Add adds incr to the existing count for attrs.
1283 //
1284 // All additional attrs passed are included in the recorded value.
1285 //
1286 // Because it is the sum of time each request took, parallel-issued requests each
1287 // contribute to make the count grow. Measured as:
1288 //
1289 // - Linux: Fields 7 & 11 from [procfs-diskstats]
1290 // - Windows: "Avg. Disk sec/Read" perf counter multiplied by "Disk Reads/sec"
1291 // perf counter (similar for Writes)
1292 //
1293 //
1294 // [procfs-diskstats]: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
1295 func (m DiskOperationTime) Add(
1296 ctx context.Context,
1297 incr float64,
1298 attrs ...attribute.KeyValue,
1299 ) {
1300 if len(attrs) == 0 {
1301 m.Float64Counter.Add(ctx, incr)
1302 return
1303 }
1304
1305 o := addOptPool.Get().(*[]metric.AddOption)
1306 defer func() {
1307 *o = (*o)[:0]
1308 addOptPool.Put(o)
1309 }()
1310
1311 *o = append(
1312 *o,
1313 metric.WithAttributes(
1314 attrs...,
1315 ),
1316 )
1317
1318 m.Float64Counter.Add(ctx, incr, *o...)
1319 }
1320
1321 // AddSet adds incr to the existing count for set.
1322 //
1323 // Because it is the sum of time each request took, parallel-issued requests each
1324 // contribute to make the count grow. Measured as:
1325 //
1326 // - Linux: Fields 7 & 11 from [procfs-diskstats]
1327 // - Windows: "Avg. Disk sec/Read" perf counter multiplied by "Disk Reads/sec"
1328 // perf counter (similar for Writes)
1329 //
1330 //
1331 // [procfs-diskstats]: https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats
1332 func (m DiskOperationTime) AddSet(ctx context.Context, incr float64, set attribute.Set) {
1333 if set.Len() == 0 {
1334 m.Float64Counter.Add(ctx, incr)
1335 return
1336 }
1337
1338 o := addOptPool.Get().(*[]metric.AddOption)
1339 defer func() {
1340 *o = (*o)[:0]
1341 addOptPool.Put(o)
1342 }()
1343
1344 *o = append(*o, metric.WithAttributeSet(set))
1345 m.Float64Counter.Add(ctx, incr, *o...)
1346 }
1347
1348 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
1349 // semantic convention. It represents the disk IO operation direction.
1350 func (DiskOperationTime) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
1351 return attribute.String("disk.io.direction", string(val))
1352 }
1353
1354 // AttrDevice returns an optional attribute for the "system.device" semantic
1355 // convention. It represents the device identifier.
1356 func (DiskOperationTime) AttrDevice(val string) attribute.KeyValue {
1357 return attribute.String("system.device", val)
1358 }
1359
1360 // DiskOperations is an instrument used to record metric values conforming to the
1361 // "system.disk.operations" semantic conventions. It represents the disk
1362 // operations count.
1363 type DiskOperations struct {
1364 metric.Int64Counter
1365 }
1366
1367 var newDiskOperationsOpts = []metric.Int64CounterOption{
1368 metric.WithDescription("Disk operations count."),
1369 metric.WithUnit("{operation}"),
1370 }
1371
1372 // NewDiskOperations returns a new DiskOperations instrument.
1373 func NewDiskOperations(
1374 m metric.Meter,
1375 opt ...metric.Int64CounterOption,
1376 ) (DiskOperations, error) {
1377 // Check if the meter is nil.
1378 if m == nil {
1379 return DiskOperations{noop.Int64Counter{}}, nil
1380 }
1381
1382 if len(opt) == 0 {
1383 opt = newDiskOperationsOpts
1384 } else {
1385 opt = append(opt, newDiskOperationsOpts...)
1386 }
1387
1388 i, err := m.Int64Counter(
1389 "system.disk.operations",
1390 opt...,
1391 )
1392 if err != nil {
1393 return DiskOperations{noop.Int64Counter{}}, err
1394 }
1395 return DiskOperations{i}, nil
1396 }
1397
1398 // Inst returns the underlying metric instrument.
1399 func (m DiskOperations) Inst() metric.Int64Counter {
1400 return m.Int64Counter
1401 }
1402
1403 // Name returns the semantic convention name of the instrument.
1404 func (DiskOperations) Name() string {
1405 return "system.disk.operations"
1406 }
1407
1408 // Unit returns the semantic convention unit of the instrument
1409 func (DiskOperations) Unit() string {
1410 return "{operation}"
1411 }
1412
1413 // Description returns the semantic convention description of the instrument
1414 func (DiskOperations) Description() string {
1415 return "Disk operations count."
1416 }
1417
1418 // Add adds incr to the existing count for attrs.
1419 //
1420 // All additional attrs passed are included in the recorded value.
1421 func (m DiskOperations) Add(
1422 ctx context.Context,
1423 incr int64,
1424 attrs ...attribute.KeyValue,
1425 ) {
1426 if len(attrs) == 0 {
1427 m.Int64Counter.Add(ctx, incr)
1428 return
1429 }
1430
1431 o := addOptPool.Get().(*[]metric.AddOption)
1432 defer func() {
1433 *o = (*o)[:0]
1434 addOptPool.Put(o)
1435 }()
1436
1437 *o = append(
1438 *o,
1439 metric.WithAttributes(
1440 attrs...,
1441 ),
1442 )
1443
1444 m.Int64Counter.Add(ctx, incr, *o...)
1445 }
1446
1447 // AddSet adds incr to the existing count for set.
1448 func (m DiskOperations) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1449 if set.Len() == 0 {
1450 m.Int64Counter.Add(ctx, incr)
1451 return
1452 }
1453
1454 o := addOptPool.Get().(*[]metric.AddOption)
1455 defer func() {
1456 *o = (*o)[:0]
1457 addOptPool.Put(o)
1458 }()
1459
1460 *o = append(*o, metric.WithAttributeSet(set))
1461 m.Int64Counter.Add(ctx, incr, *o...)
1462 }
1463
1464 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
1465 // semantic convention. It represents the disk IO operation direction.
1466 func (DiskOperations) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
1467 return attribute.String("disk.io.direction", string(val))
1468 }
1469
1470 // AttrDevice returns an optional attribute for the "system.device" semantic
1471 // convention. It represents the device identifier.
1472 func (DiskOperations) AttrDevice(val string) attribute.KeyValue {
1473 return attribute.String("system.device", val)
1474 }
1475
1476 // FilesystemLimit is an instrument used to record metric values conforming to
1477 // the "system.filesystem.limit" semantic conventions. It represents the total
1478 // storage capacity of the filesystem.
1479 type FilesystemLimit struct {
1480 metric.Int64UpDownCounter
1481 }
1482
1483 var newFilesystemLimitOpts = []metric.Int64UpDownCounterOption{
1484 metric.WithDescription("The total storage capacity of the filesystem."),
1485 metric.WithUnit("By"),
1486 }
1487
1488 // NewFilesystemLimit returns a new FilesystemLimit instrument.
1489 func NewFilesystemLimit(
1490 m metric.Meter,
1491 opt ...metric.Int64UpDownCounterOption,
1492 ) (FilesystemLimit, error) {
1493 // Check if the meter is nil.
1494 if m == nil {
1495 return FilesystemLimit{noop.Int64UpDownCounter{}}, nil
1496 }
1497
1498 if len(opt) == 0 {
1499 opt = newFilesystemLimitOpts
1500 } else {
1501 opt = append(opt, newFilesystemLimitOpts...)
1502 }
1503
1504 i, err := m.Int64UpDownCounter(
1505 "system.filesystem.limit",
1506 opt...,
1507 )
1508 if err != nil {
1509 return FilesystemLimit{noop.Int64UpDownCounter{}}, err
1510 }
1511 return FilesystemLimit{i}, nil
1512 }
1513
1514 // Inst returns the underlying metric instrument.
1515 func (m FilesystemLimit) Inst() metric.Int64UpDownCounter {
1516 return m.Int64UpDownCounter
1517 }
1518
1519 // Name returns the semantic convention name of the instrument.
1520 func (FilesystemLimit) Name() string {
1521 return "system.filesystem.limit"
1522 }
1523
1524 // Unit returns the semantic convention unit of the instrument
1525 func (FilesystemLimit) Unit() string {
1526 return "By"
1527 }
1528
1529 // Description returns the semantic convention description of the instrument
1530 func (FilesystemLimit) Description() string {
1531 return "The total storage capacity of the filesystem."
1532 }
1533
1534 // Add adds incr to the existing count for attrs.
1535 //
1536 // All additional attrs passed are included in the recorded value.
1537 func (m FilesystemLimit) Add(
1538 ctx context.Context,
1539 incr int64,
1540 attrs ...attribute.KeyValue,
1541 ) {
1542 if len(attrs) == 0 {
1543 m.Int64UpDownCounter.Add(ctx, incr)
1544 return
1545 }
1546
1547 o := addOptPool.Get().(*[]metric.AddOption)
1548 defer func() {
1549 *o = (*o)[:0]
1550 addOptPool.Put(o)
1551 }()
1552
1553 *o = append(
1554 *o,
1555 metric.WithAttributes(
1556 attrs...,
1557 ),
1558 )
1559
1560 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1561 }
1562
1563 // AddSet adds incr to the existing count for set.
1564 func (m FilesystemLimit) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1565 if set.Len() == 0 {
1566 m.Int64UpDownCounter.Add(ctx, incr)
1567 return
1568 }
1569
1570 o := addOptPool.Get().(*[]metric.AddOption)
1571 defer func() {
1572 *o = (*o)[:0]
1573 addOptPool.Put(o)
1574 }()
1575
1576 *o = append(*o, metric.WithAttributeSet(set))
1577 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1578 }
1579
1580 // AttrDevice returns an optional attribute for the "system.device" semantic
1581 // convention. It represents the identifier for the device where the filesystem
1582 // resides.
1583 func (FilesystemLimit) AttrDevice(val string) attribute.KeyValue {
1584 return attribute.String("system.device", val)
1585 }
1586
1587 // AttrFilesystemMode returns an optional attribute for the
1588 // "system.filesystem.mode" semantic convention. It represents the filesystem
1589 // mode.
1590 func (FilesystemLimit) AttrFilesystemMode(val string) attribute.KeyValue {
1591 return attribute.String("system.filesystem.mode", val)
1592 }
1593
1594 // AttrFilesystemMountpoint returns an optional attribute for the
1595 // "system.filesystem.mountpoint" semantic convention. It represents the
1596 // filesystem mount path.
1597 func (FilesystemLimit) AttrFilesystemMountpoint(val string) attribute.KeyValue {
1598 return attribute.String("system.filesystem.mountpoint", val)
1599 }
1600
1601 // AttrFilesystemType returns an optional attribute for the
1602 // "system.filesystem.type" semantic convention. It represents the filesystem
1603 // type.
1604 func (FilesystemLimit) AttrFilesystemType(val FilesystemTypeAttr) attribute.KeyValue {
1605 return attribute.String("system.filesystem.type", string(val))
1606 }
1607
1608 // FilesystemUsage is an instrument used to record metric values conforming to
1609 // the "system.filesystem.usage" semantic conventions. It represents the reports
1610 // a filesystem's space usage across different states.
1611 type FilesystemUsage struct {
1612 metric.Int64UpDownCounter
1613 }
1614
1615 var newFilesystemUsageOpts = []metric.Int64UpDownCounterOption{
1616 metric.WithDescription("Reports a filesystem's space usage across different states."),
1617 metric.WithUnit("By"),
1618 }
1619
1620 // NewFilesystemUsage returns a new FilesystemUsage instrument.
1621 func NewFilesystemUsage(
1622 m metric.Meter,
1623 opt ...metric.Int64UpDownCounterOption,
1624 ) (FilesystemUsage, error) {
1625 // Check if the meter is nil.
1626 if m == nil {
1627 return FilesystemUsage{noop.Int64UpDownCounter{}}, nil
1628 }
1629
1630 if len(opt) == 0 {
1631 opt = newFilesystemUsageOpts
1632 } else {
1633 opt = append(opt, newFilesystemUsageOpts...)
1634 }
1635
1636 i, err := m.Int64UpDownCounter(
1637 "system.filesystem.usage",
1638 opt...,
1639 )
1640 if err != nil {
1641 return FilesystemUsage{noop.Int64UpDownCounter{}}, err
1642 }
1643 return FilesystemUsage{i}, nil
1644 }
1645
1646 // Inst returns the underlying metric instrument.
1647 func (m FilesystemUsage) Inst() metric.Int64UpDownCounter {
1648 return m.Int64UpDownCounter
1649 }
1650
1651 // Name returns the semantic convention name of the instrument.
1652 func (FilesystemUsage) Name() string {
1653 return "system.filesystem.usage"
1654 }
1655
1656 // Unit returns the semantic convention unit of the instrument
1657 func (FilesystemUsage) Unit() string {
1658 return "By"
1659 }
1660
1661 // Description returns the semantic convention description of the instrument
1662 func (FilesystemUsage) Description() string {
1663 return "Reports a filesystem's space usage across different states."
1664 }
1665
1666 // Add adds incr to the existing count for attrs.
1667 //
1668 // All additional attrs passed are included in the recorded value.
1669 //
1670 // The sum of all `system.filesystem.usage` values over the different
1671 // `system.filesystem.state` attributes
1672 // SHOULD equal the total storage capacity of the filesystem, that is
1673 // `system.filesystem.limit`.
1674 func (m FilesystemUsage) Add(
1675 ctx context.Context,
1676 incr int64,
1677 attrs ...attribute.KeyValue,
1678 ) {
1679 if len(attrs) == 0 {
1680 m.Int64UpDownCounter.Add(ctx, incr)
1681 return
1682 }
1683
1684 o := addOptPool.Get().(*[]metric.AddOption)
1685 defer func() {
1686 *o = (*o)[:0]
1687 addOptPool.Put(o)
1688 }()
1689
1690 *o = append(
1691 *o,
1692 metric.WithAttributes(
1693 attrs...,
1694 ),
1695 )
1696
1697 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1698 }
1699
1700 // AddSet adds incr to the existing count for set.
1701 //
1702 // The sum of all `system.filesystem.usage` values over the different
1703 // `system.filesystem.state` attributes
1704 // SHOULD equal the total storage capacity of the filesystem, that is
1705 // `system.filesystem.limit`.
1706 func (m FilesystemUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1707 if set.Len() == 0 {
1708 m.Int64UpDownCounter.Add(ctx, incr)
1709 return
1710 }
1711
1712 o := addOptPool.Get().(*[]metric.AddOption)
1713 defer func() {
1714 *o = (*o)[:0]
1715 addOptPool.Put(o)
1716 }()
1717
1718 *o = append(*o, metric.WithAttributeSet(set))
1719 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1720 }
1721
1722 // AttrDevice returns an optional attribute for the "system.device" semantic
1723 // convention. It represents the identifier for the device where the filesystem
1724 // resides.
1725 func (FilesystemUsage) AttrDevice(val string) attribute.KeyValue {
1726 return attribute.String("system.device", val)
1727 }
1728
1729 // AttrFilesystemMode returns an optional attribute for the
1730 // "system.filesystem.mode" semantic convention. It represents the filesystem
1731 // mode.
1732 func (FilesystemUsage) AttrFilesystemMode(val string) attribute.KeyValue {
1733 return attribute.String("system.filesystem.mode", val)
1734 }
1735
1736 // AttrFilesystemMountpoint returns an optional attribute for the
1737 // "system.filesystem.mountpoint" semantic convention. It represents the
1738 // filesystem mount path.
1739 func (FilesystemUsage) AttrFilesystemMountpoint(val string) attribute.KeyValue {
1740 return attribute.String("system.filesystem.mountpoint", val)
1741 }
1742
1743 // AttrFilesystemState returns an optional attribute for the
1744 // "system.filesystem.state" semantic convention. It represents the filesystem
1745 // state.
1746 func (FilesystemUsage) AttrFilesystemState(val FilesystemStateAttr) attribute.KeyValue {
1747 return attribute.String("system.filesystem.state", string(val))
1748 }
1749
1750 // AttrFilesystemType returns an optional attribute for the
1751 // "system.filesystem.type" semantic convention. It represents the filesystem
1752 // type.
1753 func (FilesystemUsage) AttrFilesystemType(val FilesystemTypeAttr) attribute.KeyValue {
1754 return attribute.String("system.filesystem.type", string(val))
1755 }
1756
1757 // FilesystemUtilization is an instrument used to record metric values conforming
1758 // to the "system.filesystem.utilization" semantic conventions. It represents the
1759 // fraction of filesystem bytes used.
1760 type FilesystemUtilization struct {
1761 metric.Int64Gauge
1762 }
1763
1764 var newFilesystemUtilizationOpts = []metric.Int64GaugeOption{
1765 metric.WithDescription("Fraction of filesystem bytes used."),
1766 metric.WithUnit("1"),
1767 }
1768
1769 // NewFilesystemUtilization returns a new FilesystemUtilization instrument.
1770 func NewFilesystemUtilization(
1771 m metric.Meter,
1772 opt ...metric.Int64GaugeOption,
1773 ) (FilesystemUtilization, error) {
1774 // Check if the meter is nil.
1775 if m == nil {
1776 return FilesystemUtilization{noop.Int64Gauge{}}, nil
1777 }
1778
1779 if len(opt) == 0 {
1780 opt = newFilesystemUtilizationOpts
1781 } else {
1782 opt = append(opt, newFilesystemUtilizationOpts...)
1783 }
1784
1785 i, err := m.Int64Gauge(
1786 "system.filesystem.utilization",
1787 opt...,
1788 )
1789 if err != nil {
1790 return FilesystemUtilization{noop.Int64Gauge{}}, err
1791 }
1792 return FilesystemUtilization{i}, nil
1793 }
1794
1795 // Inst returns the underlying metric instrument.
1796 func (m FilesystemUtilization) Inst() metric.Int64Gauge {
1797 return m.Int64Gauge
1798 }
1799
1800 // Name returns the semantic convention name of the instrument.
1801 func (FilesystemUtilization) Name() string {
1802 return "system.filesystem.utilization"
1803 }
1804
1805 // Unit returns the semantic convention unit of the instrument
1806 func (FilesystemUtilization) Unit() string {
1807 return "1"
1808 }
1809
1810 // Description returns the semantic convention description of the instrument
1811 func (FilesystemUtilization) Description() string {
1812 return "Fraction of filesystem bytes used."
1813 }
1814
1815 // Record records val to the current distribution for attrs.
1816 //
1817 // All additional attrs passed are included in the recorded value.
1818 func (m FilesystemUtilization) Record(
1819 ctx context.Context,
1820 val int64,
1821 attrs ...attribute.KeyValue,
1822 ) {
1823 if len(attrs) == 0 {
1824 m.Int64Gauge.Record(ctx, val)
1825 return
1826 }
1827
1828 o := recOptPool.Get().(*[]metric.RecordOption)
1829 defer func() {
1830 *o = (*o)[:0]
1831 recOptPool.Put(o)
1832 }()
1833
1834 *o = append(
1835 *o,
1836 metric.WithAttributes(
1837 attrs...,
1838 ),
1839 )
1840
1841 m.Int64Gauge.Record(ctx, val, *o...)
1842 }
1843
1844 // RecordSet records val to the current distribution for set.
1845 func (m FilesystemUtilization) RecordSet(ctx context.Context, val int64, set attribute.Set) {
1846 if set.Len() == 0 {
1847 m.Int64Gauge.Record(ctx, val)
1848 return
1849 }
1850
1851 o := recOptPool.Get().(*[]metric.RecordOption)
1852 defer func() {
1853 *o = (*o)[:0]
1854 recOptPool.Put(o)
1855 }()
1856
1857 *o = append(*o, metric.WithAttributeSet(set))
1858 m.Int64Gauge.Record(ctx, val, *o...)
1859 }
1860
1861 // AttrDevice returns an optional attribute for the "system.device" semantic
1862 // convention. It represents the identifier for the device where the filesystem
1863 // resides.
1864 func (FilesystemUtilization) AttrDevice(val string) attribute.KeyValue {
1865 return attribute.String("system.device", val)
1866 }
1867
1868 // AttrFilesystemMode returns an optional attribute for the
1869 // "system.filesystem.mode" semantic convention. It represents the filesystem
1870 // mode.
1871 func (FilesystemUtilization) AttrFilesystemMode(val string) attribute.KeyValue {
1872 return attribute.String("system.filesystem.mode", val)
1873 }
1874
1875 // AttrFilesystemMountpoint returns an optional attribute for the
1876 // "system.filesystem.mountpoint" semantic convention. It represents the
1877 // filesystem mount path.
1878 func (FilesystemUtilization) AttrFilesystemMountpoint(val string) attribute.KeyValue {
1879 return attribute.String("system.filesystem.mountpoint", val)
1880 }
1881
1882 // AttrFilesystemState returns an optional attribute for the
1883 // "system.filesystem.state" semantic convention. It represents the filesystem
1884 // state.
1885 func (FilesystemUtilization) AttrFilesystemState(val FilesystemStateAttr) attribute.KeyValue {
1886 return attribute.String("system.filesystem.state", string(val))
1887 }
1888
1889 // AttrFilesystemType returns an optional attribute for the
1890 // "system.filesystem.type" semantic convention. It represents the filesystem
1891 // type.
1892 func (FilesystemUtilization) AttrFilesystemType(val FilesystemTypeAttr) attribute.KeyValue {
1893 return attribute.String("system.filesystem.type", string(val))
1894 }
1895
1896 // MemoryLimit is an instrument used to record metric values conforming to the
1897 // "system.memory.limit" semantic conventions. It represents the total virtual
1898 // memory available in the system.
1899 type MemoryLimit struct {
1900 metric.Int64UpDownCounter
1901 }
1902
1903 var newMemoryLimitOpts = []metric.Int64UpDownCounterOption{
1904 metric.WithDescription("Total virtual memory available in the system."),
1905 metric.WithUnit("By"),
1906 }
1907
1908 // NewMemoryLimit returns a new MemoryLimit instrument.
1909 func NewMemoryLimit(
1910 m metric.Meter,
1911 opt ...metric.Int64UpDownCounterOption,
1912 ) (MemoryLimit, error) {
1913 // Check if the meter is nil.
1914 if m == nil {
1915 return MemoryLimit{noop.Int64UpDownCounter{}}, nil
1916 }
1917
1918 if len(opt) == 0 {
1919 opt = newMemoryLimitOpts
1920 } else {
1921 opt = append(opt, newMemoryLimitOpts...)
1922 }
1923
1924 i, err := m.Int64UpDownCounter(
1925 "system.memory.limit",
1926 opt...,
1927 )
1928 if err != nil {
1929 return MemoryLimit{noop.Int64UpDownCounter{}}, err
1930 }
1931 return MemoryLimit{i}, nil
1932 }
1933
1934 // Inst returns the underlying metric instrument.
1935 func (m MemoryLimit) Inst() metric.Int64UpDownCounter {
1936 return m.Int64UpDownCounter
1937 }
1938
1939 // Name returns the semantic convention name of the instrument.
1940 func (MemoryLimit) Name() string {
1941 return "system.memory.limit"
1942 }
1943
1944 // Unit returns the semantic convention unit of the instrument
1945 func (MemoryLimit) Unit() string {
1946 return "By"
1947 }
1948
1949 // Description returns the semantic convention description of the instrument
1950 func (MemoryLimit) Description() string {
1951 return "Total virtual memory available in the system."
1952 }
1953
1954 // Add adds incr to the existing count for attrs.
1955 func (m MemoryLimit) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
1956 if len(attrs) == 0 {
1957 m.Int64UpDownCounter.Add(ctx, incr)
1958 return
1959 }
1960
1961 o := addOptPool.Get().(*[]metric.AddOption)
1962 defer func() {
1963 *o = (*o)[:0]
1964 addOptPool.Put(o)
1965 }()
1966
1967 *o = append(*o, metric.WithAttributes(attrs...))
1968 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1969 }
1970
1971 // AddSet adds incr to the existing count for set.
1972 func (m MemoryLimit) AddSet(ctx context.Context, incr int64, set attribute.Set) {
1973 if set.Len() == 0 {
1974 m.Int64UpDownCounter.Add(ctx, incr)
1975 return
1976 }
1977
1978 o := addOptPool.Get().(*[]metric.AddOption)
1979 defer func() {
1980 *o = (*o)[:0]
1981 addOptPool.Put(o)
1982 }()
1983
1984 *o = append(*o, metric.WithAttributeSet(set))
1985 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1986 }
1987
1988 // MemoryLinuxAvailable is an instrument used to record metric values conforming
1989 // to the "system.memory.linux.available" semantic conventions. It represents an
1990 // estimate of how much memory is available for starting new applications,
1991 // without causing swapping.
1992 type MemoryLinuxAvailable struct {
1993 metric.Int64UpDownCounter
1994 }
1995
1996 var newMemoryLinuxAvailableOpts = []metric.Int64UpDownCounterOption{
1997 metric.WithDescription("An estimate of how much memory is available for starting new applications, without causing swapping."),
1998 metric.WithUnit("By"),
1999 }
2000
2001 // NewMemoryLinuxAvailable returns a new MemoryLinuxAvailable instrument.
2002 func NewMemoryLinuxAvailable(
2003 m metric.Meter,
2004 opt ...metric.Int64UpDownCounterOption,
2005 ) (MemoryLinuxAvailable, error) {
2006 // Check if the meter is nil.
2007 if m == nil {
2008 return MemoryLinuxAvailable{noop.Int64UpDownCounter{}}, nil
2009 }
2010
2011 if len(opt) == 0 {
2012 opt = newMemoryLinuxAvailableOpts
2013 } else {
2014 opt = append(opt, newMemoryLinuxAvailableOpts...)
2015 }
2016
2017 i, err := m.Int64UpDownCounter(
2018 "system.memory.linux.available",
2019 opt...,
2020 )
2021 if err != nil {
2022 return MemoryLinuxAvailable{noop.Int64UpDownCounter{}}, err
2023 }
2024 return MemoryLinuxAvailable{i}, nil
2025 }
2026
2027 // Inst returns the underlying metric instrument.
2028 func (m MemoryLinuxAvailable) Inst() metric.Int64UpDownCounter {
2029 return m.Int64UpDownCounter
2030 }
2031
2032 // Name returns the semantic convention name of the instrument.
2033 func (MemoryLinuxAvailable) Name() string {
2034 return "system.memory.linux.available"
2035 }
2036
2037 // Unit returns the semantic convention unit of the instrument
2038 func (MemoryLinuxAvailable) Unit() string {
2039 return "By"
2040 }
2041
2042 // Description returns the semantic convention description of the instrument
2043 func (MemoryLinuxAvailable) Description() string {
2044 return "An estimate of how much memory is available for starting new applications, without causing swapping."
2045 }
2046
2047 // Add adds incr to the existing count for attrs.
2048 //
2049 // This is an alternative to `system.memory.usage` metric with `state=free`.
2050 // Linux starting from 3.14 exports "available" memory. It takes "free" memory as
2051 // a baseline, and then factors in kernel-specific values.
2052 // This is supposed to be more accurate than just "free" memory.
2053 // For reference, see the calculations [here].
2054 // See also `MemAvailable` in [/proc/meminfo].
2055 //
2056 // [here]: https://superuser.com/a/980821
2057 // [/proc/meminfo]: https://man7.org/linux/man-pages/man5/proc.5.html
2058 func (m MemoryLinuxAvailable) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
2059 if len(attrs) == 0 {
2060 m.Int64UpDownCounter.Add(ctx, incr)
2061 return
2062 }
2063
2064 o := addOptPool.Get().(*[]metric.AddOption)
2065 defer func() {
2066 *o = (*o)[:0]
2067 addOptPool.Put(o)
2068 }()
2069
2070 *o = append(*o, metric.WithAttributes(attrs...))
2071 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2072 }
2073
2074 // AddSet adds incr to the existing count for set.
2075 //
2076 // This is an alternative to `system.memory.usage` metric with `state=free`.
2077 // Linux starting from 3.14 exports "available" memory. It takes "free" memory as
2078 // a baseline, and then factors in kernel-specific values.
2079 // This is supposed to be more accurate than just "free" memory.
2080 // For reference, see the calculations [here].
2081 // See also `MemAvailable` in [/proc/meminfo].
2082 //
2083 // [here]: https://superuser.com/a/980821
2084 // [/proc/meminfo]: https://man7.org/linux/man-pages/man5/proc.5.html
2085 func (m MemoryLinuxAvailable) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2086 if set.Len() == 0 {
2087 m.Int64UpDownCounter.Add(ctx, incr)
2088 return
2089 }
2090
2091 o := addOptPool.Get().(*[]metric.AddOption)
2092 defer func() {
2093 *o = (*o)[:0]
2094 addOptPool.Put(o)
2095 }()
2096
2097 *o = append(*o, metric.WithAttributeSet(set))
2098 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2099 }
2100
2101 // MemoryLinuxSlabUsage is an instrument used to record metric values conforming
2102 // to the "system.memory.linux.slab.usage" semantic conventions. It represents
2103 // the reports the memory used by the Linux kernel for managing caches of
2104 // frequently used objects.
2105 type MemoryLinuxSlabUsage struct {
2106 metric.Int64UpDownCounter
2107 }
2108
2109 var newMemoryLinuxSlabUsageOpts = []metric.Int64UpDownCounterOption{
2110 metric.WithDescription("Reports the memory used by the Linux kernel for managing caches of frequently used objects."),
2111 metric.WithUnit("By"),
2112 }
2113
2114 // NewMemoryLinuxSlabUsage returns a new MemoryLinuxSlabUsage instrument.
2115 func NewMemoryLinuxSlabUsage(
2116 m metric.Meter,
2117 opt ...metric.Int64UpDownCounterOption,
2118 ) (MemoryLinuxSlabUsage, error) {
2119 // Check if the meter is nil.
2120 if m == nil {
2121 return MemoryLinuxSlabUsage{noop.Int64UpDownCounter{}}, nil
2122 }
2123
2124 if len(opt) == 0 {
2125 opt = newMemoryLinuxSlabUsageOpts
2126 } else {
2127 opt = append(opt, newMemoryLinuxSlabUsageOpts...)
2128 }
2129
2130 i, err := m.Int64UpDownCounter(
2131 "system.memory.linux.slab.usage",
2132 opt...,
2133 )
2134 if err != nil {
2135 return MemoryLinuxSlabUsage{noop.Int64UpDownCounter{}}, err
2136 }
2137 return MemoryLinuxSlabUsage{i}, nil
2138 }
2139
2140 // Inst returns the underlying metric instrument.
2141 func (m MemoryLinuxSlabUsage) Inst() metric.Int64UpDownCounter {
2142 return m.Int64UpDownCounter
2143 }
2144
2145 // Name returns the semantic convention name of the instrument.
2146 func (MemoryLinuxSlabUsage) Name() string {
2147 return "system.memory.linux.slab.usage"
2148 }
2149
2150 // Unit returns the semantic convention unit of the instrument
2151 func (MemoryLinuxSlabUsage) Unit() string {
2152 return "By"
2153 }
2154
2155 // Description returns the semantic convention description of the instrument
2156 func (MemoryLinuxSlabUsage) Description() string {
2157 return "Reports the memory used by the Linux kernel for managing caches of frequently used objects."
2158 }
2159
2160 // Add adds incr to the existing count for attrs.
2161 //
2162 // All additional attrs passed are included in the recorded value.
2163 //
2164 // The sum over the `reclaimable` and `unreclaimable` state values in
2165 // `memory.linux.slab.usage` SHOULD be equal to the total slab memory available
2166 // on the system.
2167 // Note that the total slab memory is not constant and may vary over time.
2168 // See also the [Slab allocator] and `Slab` in [/proc/meminfo].
2169 //
2170 // [Slab allocator]: https://blogs.oracle.com/linux/post/understanding-linux-kernel-memory-statistics
2171 // [/proc/meminfo]: https://man7.org/linux/man-pages/man5/proc.5.html
2172 func (m MemoryLinuxSlabUsage) Add(
2173 ctx context.Context,
2174 incr int64,
2175 attrs ...attribute.KeyValue,
2176 ) {
2177 if len(attrs) == 0 {
2178 m.Int64UpDownCounter.Add(ctx, incr)
2179 return
2180 }
2181
2182 o := addOptPool.Get().(*[]metric.AddOption)
2183 defer func() {
2184 *o = (*o)[:0]
2185 addOptPool.Put(o)
2186 }()
2187
2188 *o = append(
2189 *o,
2190 metric.WithAttributes(
2191 attrs...,
2192 ),
2193 )
2194
2195 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2196 }
2197
2198 // AddSet adds incr to the existing count for set.
2199 //
2200 // The sum over the `reclaimable` and `unreclaimable` state values in
2201 // `memory.linux.slab.usage` SHOULD be equal to the total slab memory available
2202 // on the system.
2203 // Note that the total slab memory is not constant and may vary over time.
2204 // See also the [Slab allocator] and `Slab` in [/proc/meminfo].
2205 //
2206 // [Slab allocator]: https://blogs.oracle.com/linux/post/understanding-linux-kernel-memory-statistics
2207 // [/proc/meminfo]: https://man7.org/linux/man-pages/man5/proc.5.html
2208 func (m MemoryLinuxSlabUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2209 if set.Len() == 0 {
2210 m.Int64UpDownCounter.Add(ctx, incr)
2211 return
2212 }
2213
2214 o := addOptPool.Get().(*[]metric.AddOption)
2215 defer func() {
2216 *o = (*o)[:0]
2217 addOptPool.Put(o)
2218 }()
2219
2220 *o = append(*o, metric.WithAttributeSet(set))
2221 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2222 }
2223
2224 // AttrMemoryLinuxSlabState returns an optional attribute for the
2225 // "system.memory.linux.slab.state" semantic convention. It represents the Linux
2226 // Slab memory state.
2227 func (MemoryLinuxSlabUsage) AttrMemoryLinuxSlabState(val MemoryLinuxSlabStateAttr) attribute.KeyValue {
2228 return attribute.String("system.memory.linux.slab.state", string(val))
2229 }
2230
2231 // MemoryShared is an instrument used to record metric values conforming to the
2232 // "system.memory.shared" semantic conventions. It represents the shared memory
2233 // used (mostly by tmpfs).
2234 type MemoryShared struct {
2235 metric.Int64UpDownCounter
2236 }
2237
2238 var newMemorySharedOpts = []metric.Int64UpDownCounterOption{
2239 metric.WithDescription("Shared memory used (mostly by tmpfs)."),
2240 metric.WithUnit("By"),
2241 }
2242
2243 // NewMemoryShared returns a new MemoryShared instrument.
2244 func NewMemoryShared(
2245 m metric.Meter,
2246 opt ...metric.Int64UpDownCounterOption,
2247 ) (MemoryShared, error) {
2248 // Check if the meter is nil.
2249 if m == nil {
2250 return MemoryShared{noop.Int64UpDownCounter{}}, nil
2251 }
2252
2253 if len(opt) == 0 {
2254 opt = newMemorySharedOpts
2255 } else {
2256 opt = append(opt, newMemorySharedOpts...)
2257 }
2258
2259 i, err := m.Int64UpDownCounter(
2260 "system.memory.shared",
2261 opt...,
2262 )
2263 if err != nil {
2264 return MemoryShared{noop.Int64UpDownCounter{}}, err
2265 }
2266 return MemoryShared{i}, nil
2267 }
2268
2269 // Inst returns the underlying metric instrument.
2270 func (m MemoryShared) Inst() metric.Int64UpDownCounter {
2271 return m.Int64UpDownCounter
2272 }
2273
2274 // Name returns the semantic convention name of the instrument.
2275 func (MemoryShared) Name() string {
2276 return "system.memory.shared"
2277 }
2278
2279 // Unit returns the semantic convention unit of the instrument
2280 func (MemoryShared) Unit() string {
2281 return "By"
2282 }
2283
2284 // Description returns the semantic convention description of the instrument
2285 func (MemoryShared) Description() string {
2286 return "Shared memory used (mostly by tmpfs)."
2287 }
2288
2289 // Add adds incr to the existing count for attrs.
2290 //
2291 // Equivalent of `shared` from [`free` command] or
2292 // `Shmem` from [`/proc/meminfo`]"
2293 //
2294 // [`free` command]: https://man7.org/linux/man-pages/man1/free.1.html
2295 // [`/proc/meminfo`]: https://man7.org/linux/man-pages/man5/proc.5.html
2296 func (m MemoryShared) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
2297 if len(attrs) == 0 {
2298 m.Int64UpDownCounter.Add(ctx, incr)
2299 return
2300 }
2301
2302 o := addOptPool.Get().(*[]metric.AddOption)
2303 defer func() {
2304 *o = (*o)[:0]
2305 addOptPool.Put(o)
2306 }()
2307
2308 *o = append(*o, metric.WithAttributes(attrs...))
2309 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2310 }
2311
2312 // AddSet adds incr to the existing count for set.
2313 //
2314 // Equivalent of `shared` from [`free` command] or
2315 // `Shmem` from [`/proc/meminfo`]"
2316 //
2317 // [`free` command]: https://man7.org/linux/man-pages/man1/free.1.html
2318 // [`/proc/meminfo`]: https://man7.org/linux/man-pages/man5/proc.5.html
2319 func (m MemoryShared) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2320 if set.Len() == 0 {
2321 m.Int64UpDownCounter.Add(ctx, incr)
2322 return
2323 }
2324
2325 o := addOptPool.Get().(*[]metric.AddOption)
2326 defer func() {
2327 *o = (*o)[:0]
2328 addOptPool.Put(o)
2329 }()
2330
2331 *o = append(*o, metric.WithAttributeSet(set))
2332 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2333 }
2334
2335 // MemoryUsage is an instrument used to record metric values conforming to the
2336 // "system.memory.usage" semantic conventions. It represents the reports memory
2337 // in use by state.
2338 type MemoryUsage struct {
2339 metric.Int64ObservableUpDownCounter
2340 }
2341
2342 var newMemoryUsageOpts = []metric.Int64ObservableUpDownCounterOption{
2343 metric.WithDescription("Reports memory in use by state."),
2344 metric.WithUnit("By"),
2345 }
2346
2347 // NewMemoryUsage returns a new MemoryUsage instrument.
2348 func NewMemoryUsage(
2349 m metric.Meter,
2350 opt ...metric.Int64ObservableUpDownCounterOption,
2351 ) (MemoryUsage, error) {
2352 // Check if the meter is nil.
2353 if m == nil {
2354 return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, nil
2355 }
2356
2357 if len(opt) == 0 {
2358 opt = newMemoryUsageOpts
2359 } else {
2360 opt = append(opt, newMemoryUsageOpts...)
2361 }
2362
2363 i, err := m.Int64ObservableUpDownCounter(
2364 "system.memory.usage",
2365 opt...,
2366 )
2367 if err != nil {
2368 return MemoryUsage{noop.Int64ObservableUpDownCounter{}}, err
2369 }
2370 return MemoryUsage{i}, nil
2371 }
2372
2373 // Inst returns the underlying metric instrument.
2374 func (m MemoryUsage) Inst() metric.Int64ObservableUpDownCounter {
2375 return m.Int64ObservableUpDownCounter
2376 }
2377
2378 // Name returns the semantic convention name of the instrument.
2379 func (MemoryUsage) Name() string {
2380 return "system.memory.usage"
2381 }
2382
2383 // Unit returns the semantic convention unit of the instrument
2384 func (MemoryUsage) Unit() string {
2385 return "By"
2386 }
2387
2388 // Description returns the semantic convention description of the instrument
2389 func (MemoryUsage) Description() string {
2390 return "Reports memory in use by state."
2391 }
2392
2393 // AttrMemoryState returns an optional attribute for the "system.memory.state"
2394 // semantic convention. It represents the memory state.
2395 func (MemoryUsage) AttrMemoryState(val MemoryStateAttr) attribute.KeyValue {
2396 return attribute.String("system.memory.state", string(val))
2397 }
2398
2399 // MemoryUtilization is an instrument used to record metric values conforming to
2400 // the "system.memory.utilization" semantic conventions. It represents the
2401 // percentage of memory bytes in use.
2402 type MemoryUtilization struct {
2403 metric.Float64ObservableGauge
2404 }
2405
2406 var newMemoryUtilizationOpts = []metric.Float64ObservableGaugeOption{
2407 metric.WithDescription("Percentage of memory bytes in use."),
2408 metric.WithUnit("1"),
2409 }
2410
2411 // NewMemoryUtilization returns a new MemoryUtilization instrument.
2412 func NewMemoryUtilization(
2413 m metric.Meter,
2414 opt ...metric.Float64ObservableGaugeOption,
2415 ) (MemoryUtilization, error) {
2416 // Check if the meter is nil.
2417 if m == nil {
2418 return MemoryUtilization{noop.Float64ObservableGauge{}}, nil
2419 }
2420
2421 if len(opt) == 0 {
2422 opt = newMemoryUtilizationOpts
2423 } else {
2424 opt = append(opt, newMemoryUtilizationOpts...)
2425 }
2426
2427 i, err := m.Float64ObservableGauge(
2428 "system.memory.utilization",
2429 opt...,
2430 )
2431 if err != nil {
2432 return MemoryUtilization{noop.Float64ObservableGauge{}}, err
2433 }
2434 return MemoryUtilization{i}, nil
2435 }
2436
2437 // Inst returns the underlying metric instrument.
2438 func (m MemoryUtilization) Inst() metric.Float64ObservableGauge {
2439 return m.Float64ObservableGauge
2440 }
2441
2442 // Name returns the semantic convention name of the instrument.
2443 func (MemoryUtilization) Name() string {
2444 return "system.memory.utilization"
2445 }
2446
2447 // Unit returns the semantic convention unit of the instrument
2448 func (MemoryUtilization) Unit() string {
2449 return "1"
2450 }
2451
2452 // Description returns the semantic convention description of the instrument
2453 func (MemoryUtilization) Description() string {
2454 return "Percentage of memory bytes in use."
2455 }
2456
2457 // AttrMemoryState returns an optional attribute for the "system.memory.state"
2458 // semantic convention. It represents the memory state.
2459 func (MemoryUtilization) AttrMemoryState(val MemoryStateAttr) attribute.KeyValue {
2460 return attribute.String("system.memory.state", string(val))
2461 }
2462
2463 // NetworkConnectionCount is an instrument used to record metric values
2464 // conforming to the "system.network.connection.count" semantic conventions. It
2465 // represents the number of connections.
2466 type NetworkConnectionCount struct {
2467 metric.Int64UpDownCounter
2468 }
2469
2470 var newNetworkConnectionCountOpts = []metric.Int64UpDownCounterOption{
2471 metric.WithDescription("The number of connections."),
2472 metric.WithUnit("{connection}"),
2473 }
2474
2475 // NewNetworkConnectionCount returns a new NetworkConnectionCount instrument.
2476 func NewNetworkConnectionCount(
2477 m metric.Meter,
2478 opt ...metric.Int64UpDownCounterOption,
2479 ) (NetworkConnectionCount, error) {
2480 // Check if the meter is nil.
2481 if m == nil {
2482 return NetworkConnectionCount{noop.Int64UpDownCounter{}}, nil
2483 }
2484
2485 if len(opt) == 0 {
2486 opt = newNetworkConnectionCountOpts
2487 } else {
2488 opt = append(opt, newNetworkConnectionCountOpts...)
2489 }
2490
2491 i, err := m.Int64UpDownCounter(
2492 "system.network.connection.count",
2493 opt...,
2494 )
2495 if err != nil {
2496 return NetworkConnectionCount{noop.Int64UpDownCounter{}}, err
2497 }
2498 return NetworkConnectionCount{i}, nil
2499 }
2500
2501 // Inst returns the underlying metric instrument.
2502 func (m NetworkConnectionCount) Inst() metric.Int64UpDownCounter {
2503 return m.Int64UpDownCounter
2504 }
2505
2506 // Name returns the semantic convention name of the instrument.
2507 func (NetworkConnectionCount) Name() string {
2508 return "system.network.connection.count"
2509 }
2510
2511 // Unit returns the semantic convention unit of the instrument
2512 func (NetworkConnectionCount) Unit() string {
2513 return "{connection}"
2514 }
2515
2516 // Description returns the semantic convention description of the instrument
2517 func (NetworkConnectionCount) Description() string {
2518 return "The number of connections."
2519 }
2520
2521 // Add adds incr to the existing count for attrs.
2522 //
2523 // All additional attrs passed are included in the recorded value.
2524 func (m NetworkConnectionCount) Add(
2525 ctx context.Context,
2526 incr int64,
2527 attrs ...attribute.KeyValue,
2528 ) {
2529 if len(attrs) == 0 {
2530 m.Int64UpDownCounter.Add(ctx, incr)
2531 return
2532 }
2533
2534 o := addOptPool.Get().(*[]metric.AddOption)
2535 defer func() {
2536 *o = (*o)[:0]
2537 addOptPool.Put(o)
2538 }()
2539
2540 *o = append(
2541 *o,
2542 metric.WithAttributes(
2543 attrs...,
2544 ),
2545 )
2546
2547 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2548 }
2549
2550 // AddSet adds incr to the existing count for set.
2551 func (m NetworkConnectionCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2552 if set.Len() == 0 {
2553 m.Int64UpDownCounter.Add(ctx, incr)
2554 return
2555 }
2556
2557 o := addOptPool.Get().(*[]metric.AddOption)
2558 defer func() {
2559 *o = (*o)[:0]
2560 addOptPool.Put(o)
2561 }()
2562
2563 *o = append(*o, metric.WithAttributeSet(set))
2564 m.Int64UpDownCounter.Add(ctx, incr, *o...)
2565 }
2566
2567 // AttrNetworkConnectionState returns an optional attribute for the
2568 // "network.connection.state" semantic convention. It represents the state of
2569 // network connection.
2570 func (NetworkConnectionCount) AttrNetworkConnectionState(val NetworkConnectionStateAttr) attribute.KeyValue {
2571 return attribute.String("network.connection.state", string(val))
2572 }
2573
2574 // AttrNetworkInterfaceName returns an optional attribute for the
2575 // "network.interface.name" semantic convention. It represents the network
2576 // interface name.
2577 func (NetworkConnectionCount) AttrNetworkInterfaceName(val string) attribute.KeyValue {
2578 return attribute.String("network.interface.name", val)
2579 }
2580
2581 // AttrNetworkTransport returns an optional attribute for the "network.transport"
2582 // semantic convention. It represents the [OSI transport layer] or
2583 // [inter-process communication method].
2584 //
2585 // [OSI transport layer]: https://wikipedia.org/wiki/Transport_layer
2586 // [inter-process communication method]: https://wikipedia.org/wiki/Inter-process_communication
2587 func (NetworkConnectionCount) AttrNetworkTransport(val NetworkTransportAttr) attribute.KeyValue {
2588 return attribute.String("network.transport", string(val))
2589 }
2590
2591 // NetworkErrors is an instrument used to record metric values conforming to the
2592 // "system.network.errors" semantic conventions. It represents the count of
2593 // network errors detected.
2594 type NetworkErrors struct {
2595 metric.Int64Counter
2596 }
2597
2598 var newNetworkErrorsOpts = []metric.Int64CounterOption{
2599 metric.WithDescription("Count of network errors detected."),
2600 metric.WithUnit("{error}"),
2601 }
2602
2603 // NewNetworkErrors returns a new NetworkErrors instrument.
2604 func NewNetworkErrors(
2605 m metric.Meter,
2606 opt ...metric.Int64CounterOption,
2607 ) (NetworkErrors, error) {
2608 // Check if the meter is nil.
2609 if m == nil {
2610 return NetworkErrors{noop.Int64Counter{}}, nil
2611 }
2612
2613 if len(opt) == 0 {
2614 opt = newNetworkErrorsOpts
2615 } else {
2616 opt = append(opt, newNetworkErrorsOpts...)
2617 }
2618
2619 i, err := m.Int64Counter(
2620 "system.network.errors",
2621 opt...,
2622 )
2623 if err != nil {
2624 return NetworkErrors{noop.Int64Counter{}}, err
2625 }
2626 return NetworkErrors{i}, nil
2627 }
2628
2629 // Inst returns the underlying metric instrument.
2630 func (m NetworkErrors) Inst() metric.Int64Counter {
2631 return m.Int64Counter
2632 }
2633
2634 // Name returns the semantic convention name of the instrument.
2635 func (NetworkErrors) Name() string {
2636 return "system.network.errors"
2637 }
2638
2639 // Unit returns the semantic convention unit of the instrument
2640 func (NetworkErrors) Unit() string {
2641 return "{error}"
2642 }
2643
2644 // Description returns the semantic convention description of the instrument
2645 func (NetworkErrors) Description() string {
2646 return "Count of network errors detected."
2647 }
2648
2649 // Add adds incr to the existing count for attrs.
2650 //
2651 // All additional attrs passed are included in the recorded value.
2652 //
2653 // Measured as:
2654 //
2655 // - Linux: the `errs` column in `/proc/net/dev` ([source]).
2656 // - Windows: [`InErrors`/`OutErrors`]
2657 // from [`GetIfEntry2`].
2658 //
2659 //
2660 // [source]: https://web.archive.org/web/20180321091318/http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html
2661 // [`InErrors`/`OutErrors`]: https://docs.microsoft.com/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
2662 // [`GetIfEntry2`]: https://docs.microsoft.com/windows/win32/api/netioapi/nf-netioapi-getifentry2
2663 func (m NetworkErrors) Add(
2664 ctx context.Context,
2665 incr int64,
2666 attrs ...attribute.KeyValue,
2667 ) {
2668 if len(attrs) == 0 {
2669 m.Int64Counter.Add(ctx, incr)
2670 return
2671 }
2672
2673 o := addOptPool.Get().(*[]metric.AddOption)
2674 defer func() {
2675 *o = (*o)[:0]
2676 addOptPool.Put(o)
2677 }()
2678
2679 *o = append(
2680 *o,
2681 metric.WithAttributes(
2682 attrs...,
2683 ),
2684 )
2685
2686 m.Int64Counter.Add(ctx, incr, *o...)
2687 }
2688
2689 // AddSet adds incr to the existing count for set.
2690 //
2691 // Measured as:
2692 //
2693 // - Linux: the `errs` column in `/proc/net/dev` ([source]).
2694 // - Windows: [`InErrors`/`OutErrors`]
2695 // from [`GetIfEntry2`].
2696 //
2697 //
2698 // [source]: https://web.archive.org/web/20180321091318/http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html
2699 // [`InErrors`/`OutErrors`]: https://docs.microsoft.com/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
2700 // [`GetIfEntry2`]: https://docs.microsoft.com/windows/win32/api/netioapi/nf-netioapi-getifentry2
2701 func (m NetworkErrors) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2702 if set.Len() == 0 {
2703 m.Int64Counter.Add(ctx, incr)
2704 return
2705 }
2706
2707 o := addOptPool.Get().(*[]metric.AddOption)
2708 defer func() {
2709 *o = (*o)[:0]
2710 addOptPool.Put(o)
2711 }()
2712
2713 *o = append(*o, metric.WithAttributeSet(set))
2714 m.Int64Counter.Add(ctx, incr, *o...)
2715 }
2716
2717 // AttrNetworkInterfaceName returns an optional attribute for the
2718 // "network.interface.name" semantic convention. It represents the network
2719 // interface name.
2720 func (NetworkErrors) AttrNetworkInterfaceName(val string) attribute.KeyValue {
2721 return attribute.String("network.interface.name", val)
2722 }
2723
2724 // AttrNetworkIODirection returns an optional attribute for the
2725 // "network.io.direction" semantic convention. It represents the network IO
2726 // operation direction.
2727 func (NetworkErrors) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
2728 return attribute.String("network.io.direction", string(val))
2729 }
2730
2731 // NetworkIO is an instrument used to record metric values conforming to the
2732 // "system.network.io" semantic conventions. It represents the number of bytes
2733 // transmitted and received.
2734 type NetworkIO struct {
2735 metric.Int64ObservableCounter
2736 }
2737
2738 var newNetworkIOOpts = []metric.Int64ObservableCounterOption{
2739 metric.WithDescription("The number of bytes transmitted and received."),
2740 metric.WithUnit("By"),
2741 }
2742
2743 // NewNetworkIO returns a new NetworkIO instrument.
2744 func NewNetworkIO(
2745 m metric.Meter,
2746 opt ...metric.Int64ObservableCounterOption,
2747 ) (NetworkIO, error) {
2748 // Check if the meter is nil.
2749 if m == nil {
2750 return NetworkIO{noop.Int64ObservableCounter{}}, nil
2751 }
2752
2753 if len(opt) == 0 {
2754 opt = newNetworkIOOpts
2755 } else {
2756 opt = append(opt, newNetworkIOOpts...)
2757 }
2758
2759 i, err := m.Int64ObservableCounter(
2760 "system.network.io",
2761 opt...,
2762 )
2763 if err != nil {
2764 return NetworkIO{noop.Int64ObservableCounter{}}, err
2765 }
2766 return NetworkIO{i}, nil
2767 }
2768
2769 // Inst returns the underlying metric instrument.
2770 func (m NetworkIO) Inst() metric.Int64ObservableCounter {
2771 return m.Int64ObservableCounter
2772 }
2773
2774 // Name returns the semantic convention name of the instrument.
2775 func (NetworkIO) Name() string {
2776 return "system.network.io"
2777 }
2778
2779 // Unit returns the semantic convention unit of the instrument
2780 func (NetworkIO) Unit() string {
2781 return "By"
2782 }
2783
2784 // Description returns the semantic convention description of the instrument
2785 func (NetworkIO) Description() string {
2786 return "The number of bytes transmitted and received."
2787 }
2788
2789 // AttrNetworkInterfaceName returns an optional attribute for the
2790 // "network.interface.name" semantic convention. It represents the network
2791 // interface name.
2792 func (NetworkIO) AttrNetworkInterfaceName(val string) attribute.KeyValue {
2793 return attribute.String("network.interface.name", val)
2794 }
2795
2796 // AttrNetworkIODirection returns an optional attribute for the
2797 // "network.io.direction" semantic convention. It represents the network IO
2798 // operation direction.
2799 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
2800 return attribute.String("network.io.direction", string(val))
2801 }
2802
2803 // NetworkPacketCount is an instrument used to record metric values conforming to
2804 // the "system.network.packet.count" semantic conventions. It represents the
2805 // number of packets transferred.
2806 type NetworkPacketCount struct {
2807 metric.Int64Counter
2808 }
2809
2810 var newNetworkPacketCountOpts = []metric.Int64CounterOption{
2811 metric.WithDescription("The number of packets transferred."),
2812 metric.WithUnit("{packet}"),
2813 }
2814
2815 // NewNetworkPacketCount returns a new NetworkPacketCount instrument.
2816 func NewNetworkPacketCount(
2817 m metric.Meter,
2818 opt ...metric.Int64CounterOption,
2819 ) (NetworkPacketCount, error) {
2820 // Check if the meter is nil.
2821 if m == nil {
2822 return NetworkPacketCount{noop.Int64Counter{}}, nil
2823 }
2824
2825 if len(opt) == 0 {
2826 opt = newNetworkPacketCountOpts
2827 } else {
2828 opt = append(opt, newNetworkPacketCountOpts...)
2829 }
2830
2831 i, err := m.Int64Counter(
2832 "system.network.packet.count",
2833 opt...,
2834 )
2835 if err != nil {
2836 return NetworkPacketCount{noop.Int64Counter{}}, err
2837 }
2838 return NetworkPacketCount{i}, nil
2839 }
2840
2841 // Inst returns the underlying metric instrument.
2842 func (m NetworkPacketCount) Inst() metric.Int64Counter {
2843 return m.Int64Counter
2844 }
2845
2846 // Name returns the semantic convention name of the instrument.
2847 func (NetworkPacketCount) Name() string {
2848 return "system.network.packet.count"
2849 }
2850
2851 // Unit returns the semantic convention unit of the instrument
2852 func (NetworkPacketCount) Unit() string {
2853 return "{packet}"
2854 }
2855
2856 // Description returns the semantic convention description of the instrument
2857 func (NetworkPacketCount) Description() string {
2858 return "The number of packets transferred."
2859 }
2860
2861 // Add adds incr to the existing count for attrs.
2862 //
2863 // All additional attrs passed are included in the recorded value.
2864 func (m NetworkPacketCount) Add(
2865 ctx context.Context,
2866 incr int64,
2867 attrs ...attribute.KeyValue,
2868 ) {
2869 if len(attrs) == 0 {
2870 m.Int64Counter.Add(ctx, incr)
2871 return
2872 }
2873
2874 o := addOptPool.Get().(*[]metric.AddOption)
2875 defer func() {
2876 *o = (*o)[:0]
2877 addOptPool.Put(o)
2878 }()
2879
2880 *o = append(
2881 *o,
2882 metric.WithAttributes(
2883 attrs...,
2884 ),
2885 )
2886
2887 m.Int64Counter.Add(ctx, incr, *o...)
2888 }
2889
2890 // AddSet adds incr to the existing count for set.
2891 func (m NetworkPacketCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
2892 if set.Len() == 0 {
2893 m.Int64Counter.Add(ctx, incr)
2894 return
2895 }
2896
2897 o := addOptPool.Get().(*[]metric.AddOption)
2898 defer func() {
2899 *o = (*o)[:0]
2900 addOptPool.Put(o)
2901 }()
2902
2903 *o = append(*o, metric.WithAttributeSet(set))
2904 m.Int64Counter.Add(ctx, incr, *o...)
2905 }
2906
2907 // AttrNetworkIODirection returns an optional attribute for the
2908 // "network.io.direction" semantic convention. It represents the network IO
2909 // operation direction.
2910 func (NetworkPacketCount) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
2911 return attribute.String("network.io.direction", string(val))
2912 }
2913
2914 // AttrDevice returns an optional attribute for the "system.device" semantic
2915 // convention. It represents the device identifier.
2916 func (NetworkPacketCount) AttrDevice(val string) attribute.KeyValue {
2917 return attribute.String("system.device", val)
2918 }
2919
2920 // NetworkPacketDropped is an instrument used to record metric values conforming
2921 // to the "system.network.packet.dropped" semantic conventions. It represents the
2922 // count of packets that are dropped or discarded even though there was no error.
2923 type NetworkPacketDropped struct {
2924 metric.Int64Counter
2925 }
2926
2927 var newNetworkPacketDroppedOpts = []metric.Int64CounterOption{
2928 metric.WithDescription("Count of packets that are dropped or discarded even though there was no error."),
2929 metric.WithUnit("{packet}"),
2930 }
2931
2932 // NewNetworkPacketDropped returns a new NetworkPacketDropped instrument.
2933 func NewNetworkPacketDropped(
2934 m metric.Meter,
2935 opt ...metric.Int64CounterOption,
2936 ) (NetworkPacketDropped, error) {
2937 // Check if the meter is nil.
2938 if m == nil {
2939 return NetworkPacketDropped{noop.Int64Counter{}}, nil
2940 }
2941
2942 if len(opt) == 0 {
2943 opt = newNetworkPacketDroppedOpts
2944 } else {
2945 opt = append(opt, newNetworkPacketDroppedOpts...)
2946 }
2947
2948 i, err := m.Int64Counter(
2949 "system.network.packet.dropped",
2950 opt...,
2951 )
2952 if err != nil {
2953 return NetworkPacketDropped{noop.Int64Counter{}}, err
2954 }
2955 return NetworkPacketDropped{i}, nil
2956 }
2957
2958 // Inst returns the underlying metric instrument.
2959 func (m NetworkPacketDropped) Inst() metric.Int64Counter {
2960 return m.Int64Counter
2961 }
2962
2963 // Name returns the semantic convention name of the instrument.
2964 func (NetworkPacketDropped) Name() string {
2965 return "system.network.packet.dropped"
2966 }
2967
2968 // Unit returns the semantic convention unit of the instrument
2969 func (NetworkPacketDropped) Unit() string {
2970 return "{packet}"
2971 }
2972
2973 // Description returns the semantic convention description of the instrument
2974 func (NetworkPacketDropped) Description() string {
2975 return "Count of packets that are dropped or discarded even though there was no error."
2976 }
2977
2978 // Add adds incr to the existing count for attrs.
2979 //
2980 // All additional attrs passed are included in the recorded value.
2981 //
2982 // Measured as:
2983 //
2984 // - Linux: the `drop` column in `/proc/net/dev` ([source])
2985 // - Windows: [`InDiscards`/`OutDiscards`]
2986 // from [`GetIfEntry2`]
2987 //
2988 //
2989 // [source]: https://web.archive.org/web/20180321091318/http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html
2990 // [`InDiscards`/`OutDiscards`]: https://docs.microsoft.com/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
2991 // [`GetIfEntry2`]: https://docs.microsoft.com/windows/win32/api/netioapi/nf-netioapi-getifentry2
2992 func (m NetworkPacketDropped) Add(
2993 ctx context.Context,
2994 incr int64,
2995 attrs ...attribute.KeyValue,
2996 ) {
2997 if len(attrs) == 0 {
2998 m.Int64Counter.Add(ctx, incr)
2999 return
3000 }
3001
3002 o := addOptPool.Get().(*[]metric.AddOption)
3003 defer func() {
3004 *o = (*o)[:0]
3005 addOptPool.Put(o)
3006 }()
3007
3008 *o = append(
3009 *o,
3010 metric.WithAttributes(
3011 attrs...,
3012 ),
3013 )
3014
3015 m.Int64Counter.Add(ctx, incr, *o...)
3016 }
3017
3018 // AddSet adds incr to the existing count for set.
3019 //
3020 // Measured as:
3021 //
3022 // - Linux: the `drop` column in `/proc/net/dev` ([source])
3023 // - Windows: [`InDiscards`/`OutDiscards`]
3024 // from [`GetIfEntry2`]
3025 //
3026 //
3027 // [source]: https://web.archive.org/web/20180321091318/http://www.onlamp.com/pub/a/linux/2000/11/16/LinuxAdmin.html
3028 // [`InDiscards`/`OutDiscards`]: https://docs.microsoft.com/windows/win32/api/netioapi/ns-netioapi-mib_if_row2
3029 // [`GetIfEntry2`]: https://docs.microsoft.com/windows/win32/api/netioapi/nf-netioapi-getifentry2
3030 func (m NetworkPacketDropped) AddSet(ctx context.Context, incr int64, set attribute.Set) {
3031 if set.Len() == 0 {
3032 m.Int64Counter.Add(ctx, incr)
3033 return
3034 }
3035
3036 o := addOptPool.Get().(*[]metric.AddOption)
3037 defer func() {
3038 *o = (*o)[:0]
3039 addOptPool.Put(o)
3040 }()
3041
3042 *o = append(*o, metric.WithAttributeSet(set))
3043 m.Int64Counter.Add(ctx, incr, *o...)
3044 }
3045
3046 // AttrNetworkInterfaceName returns an optional attribute for the
3047 // "network.interface.name" semantic convention. It represents the network
3048 // interface name.
3049 func (NetworkPacketDropped) AttrNetworkInterfaceName(val string) attribute.KeyValue {
3050 return attribute.String("network.interface.name", val)
3051 }
3052
3053 // AttrNetworkIODirection returns an optional attribute for the
3054 // "network.io.direction" semantic convention. It represents the network IO
3055 // operation direction.
3056 func (NetworkPacketDropped) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
3057 return attribute.String("network.io.direction", string(val))
3058 }
3059
3060 // PagingFaults is an instrument used to record metric values conforming to the
3061 // "system.paging.faults" semantic conventions. It represents the number of page
3062 // faults.
3063 type PagingFaults struct {
3064 metric.Int64Counter
3065 }
3066
3067 var newPagingFaultsOpts = []metric.Int64CounterOption{
3068 metric.WithDescription("The number of page faults."),
3069 metric.WithUnit("{fault}"),
3070 }
3071
3072 // NewPagingFaults returns a new PagingFaults instrument.
3073 func NewPagingFaults(
3074 m metric.Meter,
3075 opt ...metric.Int64CounterOption,
3076 ) (PagingFaults, error) {
3077 // Check if the meter is nil.
3078 if m == nil {
3079 return PagingFaults{noop.Int64Counter{}}, nil
3080 }
3081
3082 if len(opt) == 0 {
3083 opt = newPagingFaultsOpts
3084 } else {
3085 opt = append(opt, newPagingFaultsOpts...)
3086 }
3087
3088 i, err := m.Int64Counter(
3089 "system.paging.faults",
3090 opt...,
3091 )
3092 if err != nil {
3093 return PagingFaults{noop.Int64Counter{}}, err
3094 }
3095 return PagingFaults{i}, nil
3096 }
3097
3098 // Inst returns the underlying metric instrument.
3099 func (m PagingFaults) Inst() metric.Int64Counter {
3100 return m.Int64Counter
3101 }
3102
3103 // Name returns the semantic convention name of the instrument.
3104 func (PagingFaults) Name() string {
3105 return "system.paging.faults"
3106 }
3107
3108 // Unit returns the semantic convention unit of the instrument
3109 func (PagingFaults) Unit() string {
3110 return "{fault}"
3111 }
3112
3113 // Description returns the semantic convention description of the instrument
3114 func (PagingFaults) Description() string {
3115 return "The number of page faults."
3116 }
3117
3118 // Add adds incr to the existing count for attrs.
3119 //
3120 // All additional attrs passed are included in the recorded value.
3121 func (m PagingFaults) Add(
3122 ctx context.Context,
3123 incr int64,
3124 attrs ...attribute.KeyValue,
3125 ) {
3126 if len(attrs) == 0 {
3127 m.Int64Counter.Add(ctx, incr)
3128 return
3129 }
3130
3131 o := addOptPool.Get().(*[]metric.AddOption)
3132 defer func() {
3133 *o = (*o)[:0]
3134 addOptPool.Put(o)
3135 }()
3136
3137 *o = append(
3138 *o,
3139 metric.WithAttributes(
3140 attrs...,
3141 ),
3142 )
3143
3144 m.Int64Counter.Add(ctx, incr, *o...)
3145 }
3146
3147 // AddSet adds incr to the existing count for set.
3148 func (m PagingFaults) AddSet(ctx context.Context, incr int64, set attribute.Set) {
3149 if set.Len() == 0 {
3150 m.Int64Counter.Add(ctx, incr)
3151 return
3152 }
3153
3154 o := addOptPool.Get().(*[]metric.AddOption)
3155 defer func() {
3156 *o = (*o)[:0]
3157 addOptPool.Put(o)
3158 }()
3159
3160 *o = append(*o, metric.WithAttributeSet(set))
3161 m.Int64Counter.Add(ctx, incr, *o...)
3162 }
3163
3164 // AttrPagingFaultType returns an optional attribute for the
3165 // "system.paging.fault.type" semantic convention. It represents the paging fault
3166 // type.
3167 func (PagingFaults) AttrPagingFaultType(val PagingFaultTypeAttr) attribute.KeyValue {
3168 return attribute.String("system.paging.fault.type", string(val))
3169 }
3170
3171 // PagingOperations is an instrument used to record metric values conforming to
3172 // the "system.paging.operations" semantic conventions. It represents the number
3173 // of paging operations.
3174 type PagingOperations struct {
3175 metric.Int64Counter
3176 }
3177
3178 var newPagingOperationsOpts = []metric.Int64CounterOption{
3179 metric.WithDescription("The number of paging operations."),
3180 metric.WithUnit("{operation}"),
3181 }
3182
3183 // NewPagingOperations returns a new PagingOperations instrument.
3184 func NewPagingOperations(
3185 m metric.Meter,
3186 opt ...metric.Int64CounterOption,
3187 ) (PagingOperations, error) {
3188 // Check if the meter is nil.
3189 if m == nil {
3190 return PagingOperations{noop.Int64Counter{}}, nil
3191 }
3192
3193 if len(opt) == 0 {
3194 opt = newPagingOperationsOpts
3195 } else {
3196 opt = append(opt, newPagingOperationsOpts...)
3197 }
3198
3199 i, err := m.Int64Counter(
3200 "system.paging.operations",
3201 opt...,
3202 )
3203 if err != nil {
3204 return PagingOperations{noop.Int64Counter{}}, err
3205 }
3206 return PagingOperations{i}, nil
3207 }
3208
3209 // Inst returns the underlying metric instrument.
3210 func (m PagingOperations) Inst() metric.Int64Counter {
3211 return m.Int64Counter
3212 }
3213
3214 // Name returns the semantic convention name of the instrument.
3215 func (PagingOperations) Name() string {
3216 return "system.paging.operations"
3217 }
3218
3219 // Unit returns the semantic convention unit of the instrument
3220 func (PagingOperations) Unit() string {
3221 return "{operation}"
3222 }
3223
3224 // Description returns the semantic convention description of the instrument
3225 func (PagingOperations) Description() string {
3226 return "The number of paging operations."
3227 }
3228
3229 // Add adds incr to the existing count for attrs.
3230 //
3231 // All additional attrs passed are included in the recorded value.
3232 func (m PagingOperations) Add(
3233 ctx context.Context,
3234 incr int64,
3235 attrs ...attribute.KeyValue,
3236 ) {
3237 if len(attrs) == 0 {
3238 m.Int64Counter.Add(ctx, incr)
3239 return
3240 }
3241
3242 o := addOptPool.Get().(*[]metric.AddOption)
3243 defer func() {
3244 *o = (*o)[:0]
3245 addOptPool.Put(o)
3246 }()
3247
3248 *o = append(
3249 *o,
3250 metric.WithAttributes(
3251 attrs...,
3252 ),
3253 )
3254
3255 m.Int64Counter.Add(ctx, incr, *o...)
3256 }
3257
3258 // AddSet adds incr to the existing count for set.
3259 func (m PagingOperations) AddSet(ctx context.Context, incr int64, set attribute.Set) {
3260 if set.Len() == 0 {
3261 m.Int64Counter.Add(ctx, incr)
3262 return
3263 }
3264
3265 o := addOptPool.Get().(*[]metric.AddOption)
3266 defer func() {
3267 *o = (*o)[:0]
3268 addOptPool.Put(o)
3269 }()
3270
3271 *o = append(*o, metric.WithAttributeSet(set))
3272 m.Int64Counter.Add(ctx, incr, *o...)
3273 }
3274
3275 // AttrPagingDirection returns an optional attribute for the
3276 // "system.paging.direction" semantic convention. It represents the paging access
3277 // direction.
3278 func (PagingOperations) AttrPagingDirection(val PagingDirectionAttr) attribute.KeyValue {
3279 return attribute.String("system.paging.direction", string(val))
3280 }
3281
3282 // AttrPagingFaultType returns an optional attribute for the
3283 // "system.paging.fault.type" semantic convention. It represents the paging fault
3284 // type.
3285 func (PagingOperations) AttrPagingFaultType(val PagingFaultTypeAttr) attribute.KeyValue {
3286 return attribute.String("system.paging.fault.type", string(val))
3287 }
3288
3289 // PagingUsage is an instrument used to record metric values conforming to the
3290 // "system.paging.usage" semantic conventions. It represents the unix swap or
3291 // windows pagefile usage.
3292 type PagingUsage struct {
3293 metric.Int64UpDownCounter
3294 }
3295
3296 var newPagingUsageOpts = []metric.Int64UpDownCounterOption{
3297 metric.WithDescription("Unix swap or windows pagefile usage."),
3298 metric.WithUnit("By"),
3299 }
3300
3301 // NewPagingUsage returns a new PagingUsage instrument.
3302 func NewPagingUsage(
3303 m metric.Meter,
3304 opt ...metric.Int64UpDownCounterOption,
3305 ) (PagingUsage, error) {
3306 // Check if the meter is nil.
3307 if m == nil {
3308 return PagingUsage{noop.Int64UpDownCounter{}}, nil
3309 }
3310
3311 if len(opt) == 0 {
3312 opt = newPagingUsageOpts
3313 } else {
3314 opt = append(opt, newPagingUsageOpts...)
3315 }
3316
3317 i, err := m.Int64UpDownCounter(
3318 "system.paging.usage",
3319 opt...,
3320 )
3321 if err != nil {
3322 return PagingUsage{noop.Int64UpDownCounter{}}, err
3323 }
3324 return PagingUsage{i}, nil
3325 }
3326
3327 // Inst returns the underlying metric instrument.
3328 func (m PagingUsage) Inst() metric.Int64UpDownCounter {
3329 return m.Int64UpDownCounter
3330 }
3331
3332 // Name returns the semantic convention name of the instrument.
3333 func (PagingUsage) Name() string {
3334 return "system.paging.usage"
3335 }
3336
3337 // Unit returns the semantic convention unit of the instrument
3338 func (PagingUsage) Unit() string {
3339 return "By"
3340 }
3341
3342 // Description returns the semantic convention description of the instrument
3343 func (PagingUsage) Description() string {
3344 return "Unix swap or windows pagefile usage."
3345 }
3346
3347 // Add adds incr to the existing count for attrs.
3348 //
3349 // All additional attrs passed are included in the recorded value.
3350 func (m PagingUsage) Add(
3351 ctx context.Context,
3352 incr int64,
3353 attrs ...attribute.KeyValue,
3354 ) {
3355 if len(attrs) == 0 {
3356 m.Int64UpDownCounter.Add(ctx, incr)
3357 return
3358 }
3359
3360 o := addOptPool.Get().(*[]metric.AddOption)
3361 defer func() {
3362 *o = (*o)[:0]
3363 addOptPool.Put(o)
3364 }()
3365
3366 *o = append(
3367 *o,
3368 metric.WithAttributes(
3369 attrs...,
3370 ),
3371 )
3372
3373 m.Int64UpDownCounter.Add(ctx, incr, *o...)
3374 }
3375
3376 // AddSet adds incr to the existing count for set.
3377 func (m PagingUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
3378 if set.Len() == 0 {
3379 m.Int64UpDownCounter.Add(ctx, incr)
3380 return
3381 }
3382
3383 o := addOptPool.Get().(*[]metric.AddOption)
3384 defer func() {
3385 *o = (*o)[:0]
3386 addOptPool.Put(o)
3387 }()
3388
3389 *o = append(*o, metric.WithAttributeSet(set))
3390 m.Int64UpDownCounter.Add(ctx, incr, *o...)
3391 }
3392
3393 // AttrDevice returns an optional attribute for the "system.device" semantic
3394 // convention. It represents the unique identifier for the device responsible for
3395 // managing paging operations.
3396 func (PagingUsage) AttrDevice(val string) attribute.KeyValue {
3397 return attribute.String("system.device", val)
3398 }
3399
3400 // AttrPagingState returns an optional attribute for the "system.paging.state"
3401 // semantic convention. It represents the memory paging state.
3402 func (PagingUsage) AttrPagingState(val PagingStateAttr) attribute.KeyValue {
3403 return attribute.String("system.paging.state", string(val))
3404 }
3405
3406 // PagingUtilization is an instrument used to record metric values conforming to
3407 // the "system.paging.utilization" semantic conventions. It represents the swap
3408 // (unix) or pagefile (windows) utilization.
3409 type PagingUtilization struct {
3410 metric.Int64Gauge
3411 }
3412
3413 var newPagingUtilizationOpts = []metric.Int64GaugeOption{
3414 metric.WithDescription("Swap (unix) or pagefile (windows) utilization."),
3415 metric.WithUnit("1"),
3416 }
3417
3418 // NewPagingUtilization returns a new PagingUtilization instrument.
3419 func NewPagingUtilization(
3420 m metric.Meter,
3421 opt ...metric.Int64GaugeOption,
3422 ) (PagingUtilization, error) {
3423 // Check if the meter is nil.
3424 if m == nil {
3425 return PagingUtilization{noop.Int64Gauge{}}, nil
3426 }
3427
3428 if len(opt) == 0 {
3429 opt = newPagingUtilizationOpts
3430 } else {
3431 opt = append(opt, newPagingUtilizationOpts...)
3432 }
3433
3434 i, err := m.Int64Gauge(
3435 "system.paging.utilization",
3436 opt...,
3437 )
3438 if err != nil {
3439 return PagingUtilization{noop.Int64Gauge{}}, err
3440 }
3441 return PagingUtilization{i}, nil
3442 }
3443
3444 // Inst returns the underlying metric instrument.
3445 func (m PagingUtilization) Inst() metric.Int64Gauge {
3446 return m.Int64Gauge
3447 }
3448
3449 // Name returns the semantic convention name of the instrument.
3450 func (PagingUtilization) Name() string {
3451 return "system.paging.utilization"
3452 }
3453
3454 // Unit returns the semantic convention unit of the instrument
3455 func (PagingUtilization) Unit() string {
3456 return "1"
3457 }
3458
3459 // Description returns the semantic convention description of the instrument
3460 func (PagingUtilization) Description() string {
3461 return "Swap (unix) or pagefile (windows) utilization."
3462 }
3463
3464 // Record records val to the current distribution for attrs.
3465 //
3466 // All additional attrs passed are included in the recorded value.
3467 func (m PagingUtilization) Record(
3468 ctx context.Context,
3469 val int64,
3470 attrs ...attribute.KeyValue,
3471 ) {
3472 if len(attrs) == 0 {
3473 m.Int64Gauge.Record(ctx, val)
3474 return
3475 }
3476
3477 o := recOptPool.Get().(*[]metric.RecordOption)
3478 defer func() {
3479 *o = (*o)[:0]
3480 recOptPool.Put(o)
3481 }()
3482
3483 *o = append(
3484 *o,
3485 metric.WithAttributes(
3486 attrs...,
3487 ),
3488 )
3489
3490 m.Int64Gauge.Record(ctx, val, *o...)
3491 }
3492
3493 // RecordSet records val to the current distribution for set.
3494 func (m PagingUtilization) RecordSet(ctx context.Context, val int64, set attribute.Set) {
3495 if set.Len() == 0 {
3496 m.Int64Gauge.Record(ctx, val)
3497 return
3498 }
3499
3500 o := recOptPool.Get().(*[]metric.RecordOption)
3501 defer func() {
3502 *o = (*o)[:0]
3503 recOptPool.Put(o)
3504 }()
3505
3506 *o = append(*o, metric.WithAttributeSet(set))
3507 m.Int64Gauge.Record(ctx, val, *o...)
3508 }
3509
3510 // AttrDevice returns an optional attribute for the "system.device" semantic
3511 // convention. It represents the unique identifier for the device responsible for
3512 // managing paging operations.
3513 func (PagingUtilization) AttrDevice(val string) attribute.KeyValue {
3514 return attribute.String("system.device", val)
3515 }
3516
3517 // AttrPagingState returns an optional attribute for the "system.paging.state"
3518 // semantic convention. It represents the memory paging state.
3519 func (PagingUtilization) AttrPagingState(val PagingStateAttr) attribute.KeyValue {
3520 return attribute.String("system.paging.state", string(val))
3521 }
3522
3523 // ProcessCount is an instrument used to record metric values conforming to the
3524 // "system.process.count" semantic conventions. It represents the total number of
3525 // processes in each state.
3526 type ProcessCount struct {
3527 metric.Int64UpDownCounter
3528 }
3529
3530 var newProcessCountOpts = []metric.Int64UpDownCounterOption{
3531 metric.WithDescription("Total number of processes in each state."),
3532 metric.WithUnit("{process}"),
3533 }
3534
3535 // NewProcessCount returns a new ProcessCount instrument.
3536 func NewProcessCount(
3537 m metric.Meter,
3538 opt ...metric.Int64UpDownCounterOption,
3539 ) (ProcessCount, error) {
3540 // Check if the meter is nil.
3541 if m == nil {
3542 return ProcessCount{noop.Int64UpDownCounter{}}, nil
3543 }
3544
3545 if len(opt) == 0 {
3546 opt = newProcessCountOpts
3547 } else {
3548 opt = append(opt, newProcessCountOpts...)
3549 }
3550
3551 i, err := m.Int64UpDownCounter(
3552 "system.process.count",
3553 opt...,
3554 )
3555 if err != nil {
3556 return ProcessCount{noop.Int64UpDownCounter{}}, err
3557 }
3558 return ProcessCount{i}, nil
3559 }
3560
3561 // Inst returns the underlying metric instrument.
3562 func (m ProcessCount) Inst() metric.Int64UpDownCounter {
3563 return m.Int64UpDownCounter
3564 }
3565
3566 // Name returns the semantic convention name of the instrument.
3567 func (ProcessCount) Name() string {
3568 return "system.process.count"
3569 }
3570
3571 // Unit returns the semantic convention unit of the instrument
3572 func (ProcessCount) Unit() string {
3573 return "{process}"
3574 }
3575
3576 // Description returns the semantic convention description of the instrument
3577 func (ProcessCount) Description() string {
3578 return "Total number of processes in each state."
3579 }
3580
3581 // Add adds incr to the existing count for attrs.
3582 //
3583 // All additional attrs passed are included in the recorded value.
3584 func (m ProcessCount) Add(
3585 ctx context.Context,
3586 incr int64,
3587 attrs ...attribute.KeyValue,
3588 ) {
3589 if len(attrs) == 0 {
3590 m.Int64UpDownCounter.Add(ctx, incr)
3591 return
3592 }
3593
3594 o := addOptPool.Get().(*[]metric.AddOption)
3595 defer func() {
3596 *o = (*o)[:0]
3597 addOptPool.Put(o)
3598 }()
3599
3600 *o = append(
3601 *o,
3602 metric.WithAttributes(
3603 attrs...,
3604 ),
3605 )
3606
3607 m.Int64UpDownCounter.Add(ctx, incr, *o...)
3608 }
3609
3610 // AddSet adds incr to the existing count for set.
3611 func (m ProcessCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
3612 if set.Len() == 0 {
3613 m.Int64UpDownCounter.Add(ctx, incr)
3614 return
3615 }
3616
3617 o := addOptPool.Get().(*[]metric.AddOption)
3618 defer func() {
3619 *o = (*o)[:0]
3620 addOptPool.Put(o)
3621 }()
3622
3623 *o = append(*o, metric.WithAttributeSet(set))
3624 m.Int64UpDownCounter.Add(ctx, incr, *o...)
3625 }
3626
3627 // AttrProcessState returns an optional attribute for the "process.state"
3628 // semantic convention. It represents the process state, e.g.,
3629 // [Linux Process State Codes].
3630 //
3631 // [Linux Process State Codes]: https://man7.org/linux/man-pages/man1/ps.1.html#PROCESS_STATE_CODES
3632 func (ProcessCount) AttrProcessState(val ProcessStateAttr) attribute.KeyValue {
3633 return attribute.String("process.state", string(val))
3634 }
3635
3636 // ProcessCreated is an instrument used to record metric values conforming to the
3637 // "system.process.created" semantic conventions. It represents the total number
3638 // of processes created over uptime of the host.
3639 type ProcessCreated struct {
3640 metric.Int64Counter
3641 }
3642
3643 var newProcessCreatedOpts = []metric.Int64CounterOption{
3644 metric.WithDescription("Total number of processes created over uptime of the host."),
3645 metric.WithUnit("{process}"),
3646 }
3647
3648 // NewProcessCreated returns a new ProcessCreated instrument.
3649 func NewProcessCreated(
3650 m metric.Meter,
3651 opt ...metric.Int64CounterOption,
3652 ) (ProcessCreated, error) {
3653 // Check if the meter is nil.
3654 if m == nil {
3655 return ProcessCreated{noop.Int64Counter{}}, nil
3656 }
3657
3658 if len(opt) == 0 {
3659 opt = newProcessCreatedOpts
3660 } else {
3661 opt = append(opt, newProcessCreatedOpts...)
3662 }
3663
3664 i, err := m.Int64Counter(
3665 "system.process.created",
3666 opt...,
3667 )
3668 if err != nil {
3669 return ProcessCreated{noop.Int64Counter{}}, err
3670 }
3671 return ProcessCreated{i}, nil
3672 }
3673
3674 // Inst returns the underlying metric instrument.
3675 func (m ProcessCreated) Inst() metric.Int64Counter {
3676 return m.Int64Counter
3677 }
3678
3679 // Name returns the semantic convention name of the instrument.
3680 func (ProcessCreated) Name() string {
3681 return "system.process.created"
3682 }
3683
3684 // Unit returns the semantic convention unit of the instrument
3685 func (ProcessCreated) Unit() string {
3686 return "{process}"
3687 }
3688
3689 // Description returns the semantic convention description of the instrument
3690 func (ProcessCreated) Description() string {
3691 return "Total number of processes created over uptime of the host."
3692 }
3693
3694 // Add adds incr to the existing count for attrs.
3695 func (m ProcessCreated) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
3696 if len(attrs) == 0 {
3697 m.Int64Counter.Add(ctx, incr)
3698 return
3699 }
3700
3701 o := addOptPool.Get().(*[]metric.AddOption)
3702 defer func() {
3703 *o = (*o)[:0]
3704 addOptPool.Put(o)
3705 }()
3706
3707 *o = append(*o, metric.WithAttributes(attrs...))
3708 m.Int64Counter.Add(ctx, incr, *o...)
3709 }
3710
3711 // AddSet adds incr to the existing count for set.
3712 func (m ProcessCreated) AddSet(ctx context.Context, incr int64, set attribute.Set) {
3713 if set.Len() == 0 {
3714 m.Int64Counter.Add(ctx, incr)
3715 return
3716 }
3717
3718 o := addOptPool.Get().(*[]metric.AddOption)
3719 defer func() {
3720 *o = (*o)[:0]
3721 addOptPool.Put(o)
3722 }()
3723
3724 *o = append(*o, metric.WithAttributeSet(set))
3725 m.Int64Counter.Add(ctx, incr, *o...)
3726 }
3727
3728 // Uptime is an instrument used to record metric values conforming to the
3729 // "system.uptime" semantic conventions. It represents the time the system has
3730 // been running.
3731 type Uptime struct {
3732 metric.Float64Gauge
3733 }
3734
3735 var newUptimeOpts = []metric.Float64GaugeOption{
3736 metric.WithDescription("The time the system has been running."),
3737 metric.WithUnit("s"),
3738 }
3739
3740 // NewUptime returns a new Uptime instrument.
3741 func NewUptime(
3742 m metric.Meter,
3743 opt ...metric.Float64GaugeOption,
3744 ) (Uptime, error) {
3745 // Check if the meter is nil.
3746 if m == nil {
3747 return Uptime{noop.Float64Gauge{}}, nil
3748 }
3749
3750 if len(opt) == 0 {
3751 opt = newUptimeOpts
3752 } else {
3753 opt = append(opt, newUptimeOpts...)
3754 }
3755
3756 i, err := m.Float64Gauge(
3757 "system.uptime",
3758 opt...,
3759 )
3760 if err != nil {
3761 return Uptime{noop.Float64Gauge{}}, err
3762 }
3763 return Uptime{i}, nil
3764 }
3765
3766 // Inst returns the underlying metric instrument.
3767 func (m Uptime) Inst() metric.Float64Gauge {
3768 return m.Float64Gauge
3769 }
3770
3771 // Name returns the semantic convention name of the instrument.
3772 func (Uptime) Name() string {
3773 return "system.uptime"
3774 }
3775
3776 // Unit returns the semantic convention unit of the instrument
3777 func (Uptime) Unit() string {
3778 return "s"
3779 }
3780
3781 // Description returns the semantic convention description of the instrument
3782 func (Uptime) Description() string {
3783 return "The time the system has been running."
3784 }
3785
3786 // Record records val to the current distribution for attrs.
3787 //
3788 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
3789 // seconds as a floating point number with the highest precision available.
3790 // The actual accuracy would depend on the instrumentation and operating system.
3791 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
3792 if len(attrs) == 0 {
3793 m.Float64Gauge.Record(ctx, val)
3794 return
3795 }
3796
3797 o := recOptPool.Get().(*[]metric.RecordOption)
3798 defer func() {
3799 *o = (*o)[:0]
3800 recOptPool.Put(o)
3801 }()
3802
3803 *o = append(*o, metric.WithAttributes(attrs...))
3804 m.Float64Gauge.Record(ctx, val, *o...)
3805 }
3806
3807 // RecordSet records val to the current distribution for set.
3808 //
3809 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
3810 // seconds as a floating point number with the highest precision available.
3811 // The actual accuracy would depend on the instrumentation and operating system.
3812 func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
3813 if set.Len() == 0 {
3814 m.Float64Gauge.Record(ctx, val)
3815 return
3816 }
3817
3818 o := recOptPool.Get().(*[]metric.RecordOption)
3819 defer func() {
3820 *o = (*o)[:0]
3821 recOptPool.Put(o)
3822 }()
3823
3824 *o = append(*o, metric.WithAttributeSet(set))
3825 m.Float64Gauge.Record(ctx, val, *o...)
3826 }