Debian Codegraph @

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