Debian Codegraph @

semconv/v1.36.0/processconv/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 processconv provides types and functionality for OpenTelemetry semantic
7 // conventions in the "process" namespace.
8 package processconv
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 a process SHOULD be characterized *either* by data points with
26 // no `mode` labels, *or only* data points with `mode` labels.
27 type CPUModeAttr string
28
29 var (
30 // CPUModeUser is the standardized value "user" of CPUModeAttr.
31 CPUModeUser CPUModeAttr = "user"
32 // CPUModeSystem is the standardized value "system" of CPUModeAttr.
33 CPUModeSystem CPUModeAttr = "system"
34 // CPUModeNice is the standardized value "nice" of CPUModeAttr.
35 CPUModeNice CPUModeAttr = "nice"
36 // CPUModeIdle is the standardized value "idle" of CPUModeAttr.
37 CPUModeIdle CPUModeAttr = "idle"
38 // CPUModeIOWait is the standardized value "iowait" of CPUModeAttr.
39 CPUModeIOWait CPUModeAttr = "iowait"
40 // CPUModeInterrupt is the standardized value "interrupt" of CPUModeAttr.
41 CPUModeInterrupt CPUModeAttr = "interrupt"
42 // CPUModeSteal is the standardized value "steal" of CPUModeAttr.
43 CPUModeSteal CPUModeAttr = "steal"
44 // CPUModeKernel is the standardized value "kernel" of CPUModeAttr.
45 CPUModeKernel CPUModeAttr = "kernel"
46 )
47
48 // DiskIODirectionAttr is an attribute conforming to the disk.io.direction
49 // semantic conventions. It represents the disk IO operation direction.
50 type DiskIODirectionAttr string
51
52 var (
53 // DiskIODirectionRead is the standardized value "read" of DiskIODirectionAttr.
54 DiskIODirectionRead DiskIODirectionAttr = "read"
55 // DiskIODirectionWrite is the standardized value "write" of
56 // DiskIODirectionAttr.
57 DiskIODirectionWrite DiskIODirectionAttr = "write"
58 )
59
60 // NetworkIODirectionAttr is an attribute conforming to the network.io.direction
61 // semantic conventions. It represents the network IO operation direction.
62 type NetworkIODirectionAttr string
63
64 var (
65 // NetworkIODirectionTransmit is the standardized value "transmit" of
66 // NetworkIODirectionAttr.
67 NetworkIODirectionTransmit NetworkIODirectionAttr = "transmit"
68 // NetworkIODirectionReceive is the standardized value "receive" of
69 // NetworkIODirectionAttr.
70 NetworkIODirectionReceive NetworkIODirectionAttr = "receive"
71 )
72
73 // ContextSwitchTypeAttr is an attribute conforming to the
74 // process.context_switch_type semantic conventions. It represents the specifies
75 // whether the context switches for this data point were voluntary or
76 // involuntary.
77 type ContextSwitchTypeAttr string
78
79 var (
80 // ContextSwitchTypeVoluntary is the standardized value "voluntary" of
81 // ContextSwitchTypeAttr.
82 ContextSwitchTypeVoluntary ContextSwitchTypeAttr = "voluntary"
83 // ContextSwitchTypeInvoluntary is the standardized value "involuntary" of
84 // ContextSwitchTypeAttr.
85 ContextSwitchTypeInvoluntary ContextSwitchTypeAttr = "involuntary"
86 )
87
88 // PagingFaultTypeAttr is an attribute conforming to the
89 // process.paging.fault_type semantic conventions. It represents the type of page
90 // fault for this data point. Type `major` is for major/hard page faults, and
91 // `minor` is for minor/soft page faults.
92 type PagingFaultTypeAttr string
93
94 var (
95 // PagingFaultTypeMajor is the standardized value "major" of
96 // PagingFaultTypeAttr.
97 PagingFaultTypeMajor PagingFaultTypeAttr = "major"
98 // PagingFaultTypeMinor is the standardized value "minor" of
99 // PagingFaultTypeAttr.
100 PagingFaultTypeMinor PagingFaultTypeAttr = "minor"
101 )
102
103 // ContextSwitches is an instrument used to record metric values conforming to
104 // the "process.context_switches" semantic conventions. It represents the number
105 // of times the process has been context switched.
106 type ContextSwitches struct {
107 metric.Int64Counter
108 }
109
110 // NewContextSwitches returns a new ContextSwitches instrument.
111 func NewContextSwitches(
112 m metric.Meter,
113 opt ...metric.Int64CounterOption,
114 ) (ContextSwitches, error) {
115 // Check if the meter is nil.
116 if m == nil {
117 return ContextSwitches{noop.Int64Counter{}}, nil
118 }
119
120 i, err := m.Int64Counter(
121 "process.context_switches",
122 append([]metric.Int64CounterOption{
123 metric.WithDescription("Number of times the process has been context switched."),
124 metric.WithUnit("{context_switch}"),
125 }, opt...)...,
126 )
127 if err != nil {
128 return ContextSwitches{noop.Int64Counter{}}, err
129 }
130 return ContextSwitches{i}, nil
131 }
132
133 // Inst returns the underlying metric instrument.
134 func (m ContextSwitches) Inst() metric.Int64Counter {
135 return m.Int64Counter
136 }
137
138 // Name returns the semantic convention name of the instrument.
139 func (ContextSwitches) Name() string {
140 return "process.context_switches"
141 }
142
143 // Unit returns the semantic convention unit of the instrument
144 func (ContextSwitches) Unit() string {
145 return "{context_switch}"
146 }
147
148 // Description returns the semantic convention description of the instrument
149 func (ContextSwitches) Description() string {
150 return "Number of times the process has been context switched."
151 }
152
153 // Add adds incr to the existing count for attrs.
154 //
155 // All additional attrs passed are included in the recorded value.
156 func (m ContextSwitches) Add(
157 ctx context.Context,
158 incr int64,
159 attrs ...attribute.KeyValue,
160 ) {
161 if len(attrs) == 0 {
162 m.Int64Counter.Add(ctx, incr)
163 return
164 }
165
166 o := addOptPool.Get().(*[]metric.AddOption)
167 defer func() {
168 *o = (*o)[:0]
169 addOptPool.Put(o)
170 }()
171
172 *o = append(
173 *o,
174 metric.WithAttributes(
175 attrs...,
176 ),
177 )
178
179 m.Int64Counter.Add(ctx, incr, *o...)
180 }
181
182 // AddSet adds incr to the existing count for set.
183 func (m ContextSwitches) AddSet(ctx context.Context, incr int64, set attribute.Set) {
184 if set.Len() == 0 {
185 m.Int64Counter.Add(ctx, incr)
186 return
187 }
188
189 o := addOptPool.Get().(*[]metric.AddOption)
190 defer func() {
191 *o = (*o)[:0]
192 addOptPool.Put(o)
193 }()
194
195 *o = append(*o, metric.WithAttributeSet(set))
196 m.Int64Counter.Add(ctx, incr, *o...)
197 }
198
199 // AttrContextSwitchType returns an optional attribute for the
200 // "process.context_switch_type" semantic convention. It represents the specifies
201 // whether the context switches for this data point were voluntary or
202 // involuntary.
203 func (ContextSwitches) AttrContextSwitchType(val ContextSwitchTypeAttr) attribute.KeyValue {
204 return attribute.String("process.context_switch_type", string(val))
205 }
206
207 // CPUTime is an instrument used to record metric values conforming to the
208 // "process.cpu.time" semantic conventions. It represents the total CPU seconds
209 // broken down by different states.
210 type CPUTime struct {
211 metric.Float64ObservableCounter
212 }
213
214 // NewCPUTime returns a new CPUTime instrument.
215 func NewCPUTime(
216 m metric.Meter,
217 opt ...metric.Float64ObservableCounterOption,
218 ) (CPUTime, error) {
219 // Check if the meter is nil.
220 if m == nil {
221 return CPUTime{noop.Float64ObservableCounter{}}, nil
222 }
223
224 i, err := m.Float64ObservableCounter(
225 "process.cpu.time",
226 append([]metric.Float64ObservableCounterOption{
227 metric.WithDescription("Total CPU seconds broken down by different states."),
228 metric.WithUnit("s"),
229 }, opt...)...,
230 )
231 if err != nil {
232 return CPUTime{noop.Float64ObservableCounter{}}, err
233 }
234 return CPUTime{i}, nil
235 }
236
237 // Inst returns the underlying metric instrument.
238 func (m CPUTime) Inst() metric.Float64ObservableCounter {
239 return m.Float64ObservableCounter
240 }
241
242 // Name returns the semantic convention name of the instrument.
243 func (CPUTime) Name() string {
244 return "process.cpu.time"
245 }
246
247 // Unit returns the semantic convention unit of the instrument
248 func (CPUTime) Unit() string {
249 return "s"
250 }
251
252 // Description returns the semantic convention description of the instrument
253 func (CPUTime) Description() string {
254 return "Total CPU seconds broken down by different states."
255 }
256
257 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
258 // convention. It represents a process SHOULD be characterized *either* by data
259 // points with no `mode` labels, *or only* data points with `mode` labels.
260 func (CPUTime) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
261 return attribute.String("cpu.mode", string(val))
262 }
263
264 // CPUUtilization is an instrument used to record metric values conforming to the
265 // "process.cpu.utilization" semantic conventions. It represents the difference
266 // in process.cpu.time since the last measurement, divided by the elapsed time
267 // and number of CPUs available to the process.
268 type CPUUtilization struct {
269 metric.Int64Gauge
270 }
271
272 // NewCPUUtilization returns a new CPUUtilization instrument.
273 func NewCPUUtilization(
274 m metric.Meter,
275 opt ...metric.Int64GaugeOption,
276 ) (CPUUtilization, error) {
277 // Check if the meter is nil.
278 if m == nil {
279 return CPUUtilization{noop.Int64Gauge{}}, nil
280 }
281
282 i, err := m.Int64Gauge(
283 "process.cpu.utilization",
284 append([]metric.Int64GaugeOption{
285 metric.WithDescription("Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process."),
286 metric.WithUnit("1"),
287 }, opt...)...,
288 )
289 if err != nil {
290 return CPUUtilization{noop.Int64Gauge{}}, err
291 }
292 return CPUUtilization{i}, nil
293 }
294
295 // Inst returns the underlying metric instrument.
296 func (m CPUUtilization) Inst() metric.Int64Gauge {
297 return m.Int64Gauge
298 }
299
300 // Name returns the semantic convention name of the instrument.
301 func (CPUUtilization) Name() string {
302 return "process.cpu.utilization"
303 }
304
305 // Unit returns the semantic convention unit of the instrument
306 func (CPUUtilization) Unit() string {
307 return "1"
308 }
309
310 // Description returns the semantic convention description of the instrument
311 func (CPUUtilization) Description() string {
312 return "Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process."
313 }
314
315 // Record records val to the current distribution for attrs.
316 //
317 // All additional attrs passed are included in the recorded value.
318 func (m CPUUtilization) Record(
319 ctx context.Context,
320 val int64,
321 attrs ...attribute.KeyValue,
322 ) {
323 if len(attrs) == 0 {
324 m.Int64Gauge.Record(ctx, val)
325 return
326 }
327
328 o := recOptPool.Get().(*[]metric.RecordOption)
329 defer func() {
330 *o = (*o)[:0]
331 recOptPool.Put(o)
332 }()
333
334 *o = append(
335 *o,
336 metric.WithAttributes(
337 attrs...,
338 ),
339 )
340
341 m.Int64Gauge.Record(ctx, val, *o...)
342 }
343
344 // RecordSet records val to the current distribution for set.
345 func (m CPUUtilization) RecordSet(ctx context.Context, val int64, set attribute.Set) {
346 if set.Len() == 0 {
347 m.Int64Gauge.Record(ctx, val)
348 return
349 }
350
351 o := recOptPool.Get().(*[]metric.RecordOption)
352 defer func() {
353 *o = (*o)[:0]
354 recOptPool.Put(o)
355 }()
356
357 *o = append(*o, metric.WithAttributeSet(set))
358 m.Int64Gauge.Record(ctx, val, *o...)
359 }
360
361 // AttrCPUMode returns an optional attribute for the "cpu.mode" semantic
362 // convention. It represents a process SHOULD be characterized *either* by data
363 // points with no `mode` labels, *or only* data points with `mode` labels.
364 func (CPUUtilization) AttrCPUMode(val CPUModeAttr) attribute.KeyValue {
365 return attribute.String("cpu.mode", string(val))
366 }
367
368 // DiskIO is an instrument used to record metric values conforming to the
369 // "process.disk.io" semantic conventions. It represents the disk bytes
370 // transferred.
371 type DiskIO struct {
372 metric.Int64Counter
373 }
374
375 // NewDiskIO returns a new DiskIO instrument.
376 func NewDiskIO(
377 m metric.Meter,
378 opt ...metric.Int64CounterOption,
379 ) (DiskIO, error) {
380 // Check if the meter is nil.
381 if m == nil {
382 return DiskIO{noop.Int64Counter{}}, nil
383 }
384
385 i, err := m.Int64Counter(
386 "process.disk.io",
387 append([]metric.Int64CounterOption{
388 metric.WithDescription("Disk bytes transferred."),
389 metric.WithUnit("By"),
390 }, opt...)...,
391 )
392 if err != nil {
393 return DiskIO{noop.Int64Counter{}}, err
394 }
395 return DiskIO{i}, nil
396 }
397
398 // Inst returns the underlying metric instrument.
399 func (m DiskIO) Inst() metric.Int64Counter {
400 return m.Int64Counter
401 }
402
403 // Name returns the semantic convention name of the instrument.
404 func (DiskIO) Name() string {
405 return "process.disk.io"
406 }
407
408 // Unit returns the semantic convention unit of the instrument
409 func (DiskIO) Unit() string {
410 return "By"
411 }
412
413 // Description returns the semantic convention description of the instrument
414 func (DiskIO) Description() string {
415 return "Disk bytes transferred."
416 }
417
418 // Add adds incr to the existing count for attrs.
419 //
420 // All additional attrs passed are included in the recorded value.
421 func (m DiskIO) Add(
422 ctx context.Context,
423 incr int64,
424 attrs ...attribute.KeyValue,
425 ) {
426 if len(attrs) == 0 {
427 m.Int64Counter.Add(ctx, incr)
428 return
429 }
430
431 o := addOptPool.Get().(*[]metric.AddOption)
432 defer func() {
433 *o = (*o)[:0]
434 addOptPool.Put(o)
435 }()
436
437 *o = append(
438 *o,
439 metric.WithAttributes(
440 attrs...,
441 ),
442 )
443
444 m.Int64Counter.Add(ctx, incr, *o...)
445 }
446
447 // AddSet adds incr to the existing count for set.
448 func (m DiskIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
449 if set.Len() == 0 {
450 m.Int64Counter.Add(ctx, incr)
451 return
452 }
453
454 o := addOptPool.Get().(*[]metric.AddOption)
455 defer func() {
456 *o = (*o)[:0]
457 addOptPool.Put(o)
458 }()
459
460 *o = append(*o, metric.WithAttributeSet(set))
461 m.Int64Counter.Add(ctx, incr, *o...)
462 }
463
464 // AttrDiskIODirection returns an optional attribute for the "disk.io.direction"
465 // semantic convention. It represents the disk IO operation direction.
466 func (DiskIO) AttrDiskIODirection(val DiskIODirectionAttr) attribute.KeyValue {
467 return attribute.String("disk.io.direction", string(val))
468 }
469
470 // MemoryUsage is an instrument used to record metric values conforming to the
471 // "process.memory.usage" semantic conventions. It represents the amount of
472 // physical memory in use.
473 type MemoryUsage struct {
474 metric.Int64UpDownCounter
475 }
476
477 // NewMemoryUsage returns a new MemoryUsage instrument.
478 func NewMemoryUsage(
479 m metric.Meter,
480 opt ...metric.Int64UpDownCounterOption,
481 ) (MemoryUsage, error) {
482 // Check if the meter is nil.
483 if m == nil {
484 return MemoryUsage{noop.Int64UpDownCounter{}}, nil
485 }
486
487 i, err := m.Int64UpDownCounter(
488 "process.memory.usage",
489 append([]metric.Int64UpDownCounterOption{
490 metric.WithDescription("The amount of physical memory in use."),
491 metric.WithUnit("By"),
492 }, opt...)...,
493 )
494 if err != nil {
495 return MemoryUsage{noop.Int64UpDownCounter{}}, err
496 }
497 return MemoryUsage{i}, nil
498 }
499
500 // Inst returns the underlying metric instrument.
501 func (m MemoryUsage) Inst() metric.Int64UpDownCounter {
502 return m.Int64UpDownCounter
503 }
504
505 // Name returns the semantic convention name of the instrument.
506 func (MemoryUsage) Name() string {
507 return "process.memory.usage"
508 }
509
510 // Unit returns the semantic convention unit of the instrument
511 func (MemoryUsage) Unit() string {
512 return "By"
513 }
514
515 // Description returns the semantic convention description of the instrument
516 func (MemoryUsage) Description() string {
517 return "The amount of physical memory in use."
518 }
519
520 // Add adds incr to the existing count for attrs.
521 func (m MemoryUsage) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
522 if len(attrs) == 0 {
523 m.Int64UpDownCounter.Add(ctx, incr)
524 return
525 }
526
527 o := addOptPool.Get().(*[]metric.AddOption)
528 defer func() {
529 *o = (*o)[:0]
530 addOptPool.Put(o)
531 }()
532
533 *o = append(*o, metric.WithAttributes(attrs...))
534 m.Int64UpDownCounter.Add(ctx, incr, *o...)
535 }
536
537 // AddSet adds incr to the existing count for set.
538 func (m MemoryUsage) AddSet(ctx context.Context, incr int64, set attribute.Set) {
539 if set.Len() == 0 {
540 m.Int64UpDownCounter.Add(ctx, incr)
541 return
542 }
543
544 o := addOptPool.Get().(*[]metric.AddOption)
545 defer func() {
546 *o = (*o)[:0]
547 addOptPool.Put(o)
548 }()
549
550 *o = append(*o, metric.WithAttributeSet(set))
551 m.Int64UpDownCounter.Add(ctx, incr, *o...)
552 }
553
554 // MemoryVirtual is an instrument used to record metric values conforming to the
555 // "process.memory.virtual" semantic conventions. It represents the amount of
556 // committed virtual memory.
557 type MemoryVirtual struct {
558 metric.Int64UpDownCounter
559 }
560
561 // NewMemoryVirtual returns a new MemoryVirtual instrument.
562 func NewMemoryVirtual(
563 m metric.Meter,
564 opt ...metric.Int64UpDownCounterOption,
565 ) (MemoryVirtual, error) {
566 // Check if the meter is nil.
567 if m == nil {
568 return MemoryVirtual{noop.Int64UpDownCounter{}}, nil
569 }
570
571 i, err := m.Int64UpDownCounter(
572 "process.memory.virtual",
573 append([]metric.Int64UpDownCounterOption{
574 metric.WithDescription("The amount of committed virtual memory."),
575 metric.WithUnit("By"),
576 }, opt...)...,
577 )
578 if err != nil {
579 return MemoryVirtual{noop.Int64UpDownCounter{}}, err
580 }
581 return MemoryVirtual{i}, nil
582 }
583
584 // Inst returns the underlying metric instrument.
585 func (m MemoryVirtual) Inst() metric.Int64UpDownCounter {
586 return m.Int64UpDownCounter
587 }
588
589 // Name returns the semantic convention name of the instrument.
590 func (MemoryVirtual) Name() string {
591 return "process.memory.virtual"
592 }
593
594 // Unit returns the semantic convention unit of the instrument
595 func (MemoryVirtual) Unit() string {
596 return "By"
597 }
598
599 // Description returns the semantic convention description of the instrument
600 func (MemoryVirtual) Description() string {
601 return "The amount of committed virtual memory."
602 }
603
604 // Add adds incr to the existing count for attrs.
605 func (m MemoryVirtual) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
606 if len(attrs) == 0 {
607 m.Int64UpDownCounter.Add(ctx, incr)
608 return
609 }
610
611 o := addOptPool.Get().(*[]metric.AddOption)
612 defer func() {
613 *o = (*o)[:0]
614 addOptPool.Put(o)
615 }()
616
617 *o = append(*o, metric.WithAttributes(attrs...))
618 m.Int64UpDownCounter.Add(ctx, incr, *o...)
619 }
620
621 // AddSet adds incr to the existing count for set.
622 func (m MemoryVirtual) AddSet(ctx context.Context, incr int64, set attribute.Set) {
623 if set.Len() == 0 {
624 m.Int64UpDownCounter.Add(ctx, incr)
625 return
626 }
627
628 o := addOptPool.Get().(*[]metric.AddOption)
629 defer func() {
630 *o = (*o)[:0]
631 addOptPool.Put(o)
632 }()
633
634 *o = append(*o, metric.WithAttributeSet(set))
635 m.Int64UpDownCounter.Add(ctx, incr, *o...)
636 }
637
638 // NetworkIO is an instrument used to record metric values conforming to the
639 // "process.network.io" semantic conventions. It represents the network bytes
640 // transferred.
641 type NetworkIO struct {
642 metric.Int64Counter
643 }
644
645 // NewNetworkIO returns a new NetworkIO instrument.
646 func NewNetworkIO(
647 m metric.Meter,
648 opt ...metric.Int64CounterOption,
649 ) (NetworkIO, error) {
650 // Check if the meter is nil.
651 if m == nil {
652 return NetworkIO{noop.Int64Counter{}}, nil
653 }
654
655 i, err := m.Int64Counter(
656 "process.network.io",
657 append([]metric.Int64CounterOption{
658 metric.WithDescription("Network bytes transferred."),
659 metric.WithUnit("By"),
660 }, opt...)...,
661 )
662 if err != nil {
663 return NetworkIO{noop.Int64Counter{}}, err
664 }
665 return NetworkIO{i}, nil
666 }
667
668 // Inst returns the underlying metric instrument.
669 func (m NetworkIO) Inst() metric.Int64Counter {
670 return m.Int64Counter
671 }
672
673 // Name returns the semantic convention name of the instrument.
674 func (NetworkIO) Name() string {
675 return "process.network.io"
676 }
677
678 // Unit returns the semantic convention unit of the instrument
679 func (NetworkIO) Unit() string {
680 return "By"
681 }
682
683 // Description returns the semantic convention description of the instrument
684 func (NetworkIO) Description() string {
685 return "Network bytes transferred."
686 }
687
688 // Add adds incr to the existing count for attrs.
689 //
690 // All additional attrs passed are included in the recorded value.
691 func (m NetworkIO) Add(
692 ctx context.Context,
693 incr int64,
694 attrs ...attribute.KeyValue,
695 ) {
696 if len(attrs) == 0 {
697 m.Int64Counter.Add(ctx, incr)
698 return
699 }
700
701 o := addOptPool.Get().(*[]metric.AddOption)
702 defer func() {
703 *o = (*o)[:0]
704 addOptPool.Put(o)
705 }()
706
707 *o = append(
708 *o,
709 metric.WithAttributes(
710 attrs...,
711 ),
712 )
713
714 m.Int64Counter.Add(ctx, incr, *o...)
715 }
716
717 // AddSet adds incr to the existing count for set.
718 func (m NetworkIO) AddSet(ctx context.Context, incr int64, set attribute.Set) {
719 if set.Len() == 0 {
720 m.Int64Counter.Add(ctx, incr)
721 return
722 }
723
724 o := addOptPool.Get().(*[]metric.AddOption)
725 defer func() {
726 *o = (*o)[:0]
727 addOptPool.Put(o)
728 }()
729
730 *o = append(*o, metric.WithAttributeSet(set))
731 m.Int64Counter.Add(ctx, incr, *o...)
732 }
733
734 // AttrNetworkIODirection returns an optional attribute for the
735 // "network.io.direction" semantic convention. It represents the network IO
736 // operation direction.
737 func (NetworkIO) AttrNetworkIODirection(val NetworkIODirectionAttr) attribute.KeyValue {
738 return attribute.String("network.io.direction", string(val))
739 }
740
741 // OpenFileDescriptorCount is an instrument used to record metric values
742 // conforming to the "process.open_file_descriptor.count" semantic conventions.
743 // It represents the number of file descriptors in use by the process.
744 type OpenFileDescriptorCount struct {
745 metric.Int64UpDownCounter
746 }
747
748 // NewOpenFileDescriptorCount returns a new OpenFileDescriptorCount instrument.
749 func NewOpenFileDescriptorCount(
750 m metric.Meter,
751 opt ...metric.Int64UpDownCounterOption,
752 ) (OpenFileDescriptorCount, error) {
753 // Check if the meter is nil.
754 if m == nil {
755 return OpenFileDescriptorCount{noop.Int64UpDownCounter{}}, nil
756 }
757
758 i, err := m.Int64UpDownCounter(
759 "process.open_file_descriptor.count",
760 append([]metric.Int64UpDownCounterOption{
761 metric.WithDescription("Number of file descriptors in use by the process."),
762 metric.WithUnit("{file_descriptor}"),
763 }, opt...)...,
764 )
765 if err != nil {
766 return OpenFileDescriptorCount{noop.Int64UpDownCounter{}}, err
767 }
768 return OpenFileDescriptorCount{i}, nil
769 }
770
771 // Inst returns the underlying metric instrument.
772 func (m OpenFileDescriptorCount) Inst() metric.Int64UpDownCounter {
773 return m.Int64UpDownCounter
774 }
775
776 // Name returns the semantic convention name of the instrument.
777 func (OpenFileDescriptorCount) Name() string {
778 return "process.open_file_descriptor.count"
779 }
780
781 // Unit returns the semantic convention unit of the instrument
782 func (OpenFileDescriptorCount) Unit() string {
783 return "{file_descriptor}"
784 }
785
786 // Description returns the semantic convention description of the instrument
787 func (OpenFileDescriptorCount) Description() string {
788 return "Number of file descriptors in use by the process."
789 }
790
791 // Add adds incr to the existing count for attrs.
792 func (m OpenFileDescriptorCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
793 if len(attrs) == 0 {
794 m.Int64UpDownCounter.Add(ctx, incr)
795 return
796 }
797
798 o := addOptPool.Get().(*[]metric.AddOption)
799 defer func() {
800 *o = (*o)[:0]
801 addOptPool.Put(o)
802 }()
803
804 *o = append(*o, metric.WithAttributes(attrs...))
805 m.Int64UpDownCounter.Add(ctx, incr, *o...)
806 }
807
808 // AddSet adds incr to the existing count for set.
809 func (m OpenFileDescriptorCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
810 if set.Len() == 0 {
811 m.Int64UpDownCounter.Add(ctx, incr)
812 return
813 }
814
815 o := addOptPool.Get().(*[]metric.AddOption)
816 defer func() {
817 *o = (*o)[:0]
818 addOptPool.Put(o)
819 }()
820
821 *o = append(*o, metric.WithAttributeSet(set))
822 m.Int64UpDownCounter.Add(ctx, incr, *o...)
823 }
824
825 // PagingFaults is an instrument used to record metric values conforming to the
826 // "process.paging.faults" semantic conventions. It represents the number of page
827 // faults the process has made.
828 type PagingFaults struct {
829 metric.Int64Counter
830 }
831
832 // NewPagingFaults returns a new PagingFaults instrument.
833 func NewPagingFaults(
834 m metric.Meter,
835 opt ...metric.Int64CounterOption,
836 ) (PagingFaults, error) {
837 // Check if the meter is nil.
838 if m == nil {
839 return PagingFaults{noop.Int64Counter{}}, nil
840 }
841
842 i, err := m.Int64Counter(
843 "process.paging.faults",
844 append([]metric.Int64CounterOption{
845 metric.WithDescription("Number of page faults the process has made."),
846 metric.WithUnit("{fault}"),
847 }, opt...)...,
848 )
849 if err != nil {
850 return PagingFaults{noop.Int64Counter{}}, err
851 }
852 return PagingFaults{i}, nil
853 }
854
855 // Inst returns the underlying metric instrument.
856 func (m PagingFaults) Inst() metric.Int64Counter {
857 return m.Int64Counter
858 }
859
860 // Name returns the semantic convention name of the instrument.
861 func (PagingFaults) Name() string {
862 return "process.paging.faults"
863 }
864
865 // Unit returns the semantic convention unit of the instrument
866 func (PagingFaults) Unit() string {
867 return "{fault}"
868 }
869
870 // Description returns the semantic convention description of the instrument
871 func (PagingFaults) Description() string {
872 return "Number of page faults the process has made."
873 }
874
875 // Add adds incr to the existing count for attrs.
876 //
877 // All additional attrs passed are included in the recorded value.
878 func (m PagingFaults) Add(
879 ctx context.Context,
880 incr int64,
881 attrs ...attribute.KeyValue,
882 ) {
883 if len(attrs) == 0 {
884 m.Int64Counter.Add(ctx, incr)
885 return
886 }
887
888 o := addOptPool.Get().(*[]metric.AddOption)
889 defer func() {
890 *o = (*o)[:0]
891 addOptPool.Put(o)
892 }()
893
894 *o = append(
895 *o,
896 metric.WithAttributes(
897 attrs...,
898 ),
899 )
900
901 m.Int64Counter.Add(ctx, incr, *o...)
902 }
903
904 // AddSet adds incr to the existing count for set.
905 func (m PagingFaults) AddSet(ctx context.Context, incr int64, set attribute.Set) {
906 if set.Len() == 0 {
907 m.Int64Counter.Add(ctx, incr)
908 return
909 }
910
911 o := addOptPool.Get().(*[]metric.AddOption)
912 defer func() {
913 *o = (*o)[:0]
914 addOptPool.Put(o)
915 }()
916
917 *o = append(*o, metric.WithAttributeSet(set))
918 m.Int64Counter.Add(ctx, incr, *o...)
919 }
920
921 // AttrPagingFaultType returns an optional attribute for the
922 // "process.paging.fault_type" semantic convention. It represents the type of
923 // page fault for this data point. Type `major` is for major/hard page faults,
924 // and `minor` is for minor/soft page faults.
925 func (PagingFaults) AttrPagingFaultType(val PagingFaultTypeAttr) attribute.KeyValue {
926 return attribute.String("process.paging.fault_type", string(val))
927 }
928
929 // ThreadCount is an instrument used to record metric values conforming to the
930 // "process.thread.count" semantic conventions. It represents the process threads
931 // count.
932 type ThreadCount struct {
933 metric.Int64UpDownCounter
934 }
935
936 // NewThreadCount returns a new ThreadCount instrument.
937 func NewThreadCount(
938 m metric.Meter,
939 opt ...metric.Int64UpDownCounterOption,
940 ) (ThreadCount, error) {
941 // Check if the meter is nil.
942 if m == nil {
943 return ThreadCount{noop.Int64UpDownCounter{}}, nil
944 }
945
946 i, err := m.Int64UpDownCounter(
947 "process.thread.count",
948 append([]metric.Int64UpDownCounterOption{
949 metric.WithDescription("Process threads count."),
950 metric.WithUnit("{thread}"),
951 }, opt...)...,
952 )
953 if err != nil {
954 return ThreadCount{noop.Int64UpDownCounter{}}, err
955 }
956 return ThreadCount{i}, nil
957 }
958
959 // Inst returns the underlying metric instrument.
960 func (m ThreadCount) Inst() metric.Int64UpDownCounter {
961 return m.Int64UpDownCounter
962 }
963
964 // Name returns the semantic convention name of the instrument.
965 func (ThreadCount) Name() string {
966 return "process.thread.count"
967 }
968
969 // Unit returns the semantic convention unit of the instrument
970 func (ThreadCount) Unit() string {
971 return "{thread}"
972 }
973
974 // Description returns the semantic convention description of the instrument
975 func (ThreadCount) Description() string {
976 return "Process threads count."
977 }
978
979 // Add adds incr to the existing count for attrs.
980 func (m ThreadCount) Add(ctx context.Context, incr int64, attrs ...attribute.KeyValue) {
981 if len(attrs) == 0 {
982 m.Int64UpDownCounter.Add(ctx, incr)
983 return
984 }
985
986 o := addOptPool.Get().(*[]metric.AddOption)
987 defer func() {
988 *o = (*o)[:0]
989 addOptPool.Put(o)
990 }()
991
992 *o = append(*o, metric.WithAttributes(attrs...))
993 m.Int64UpDownCounter.Add(ctx, incr, *o...)
994 }
995
996 // AddSet adds incr to the existing count for set.
997 func (m ThreadCount) AddSet(ctx context.Context, incr int64, set attribute.Set) {
998 if set.Len() == 0 {
999 m.Int64UpDownCounter.Add(ctx, incr)
1000 return
1001 }
1002
1003 o := addOptPool.Get().(*[]metric.AddOption)
1004 defer func() {
1005 *o = (*o)[:0]
1006 addOptPool.Put(o)
1007 }()
1008
1009 *o = append(*o, metric.WithAttributeSet(set))
1010 m.Int64UpDownCounter.Add(ctx, incr, *o...)
1011 }
1012
1013 // Uptime is an instrument used to record metric values conforming to the
1014 // "process.uptime" semantic conventions. It represents the time the process has
1015 // been running.
1016 type Uptime struct {
1017 metric.Float64Gauge
1018 }
1019
1020 // NewUptime returns a new Uptime instrument.
1021 func NewUptime(
1022 m metric.Meter,
1023 opt ...metric.Float64GaugeOption,
1024 ) (Uptime, error) {
1025 // Check if the meter is nil.
1026 if m == nil {
1027 return Uptime{noop.Float64Gauge{}}, nil
1028 }
1029
1030 i, err := m.Float64Gauge(
1031 "process.uptime",
1032 append([]metric.Float64GaugeOption{
1033 metric.WithDescription("The time the process has been running."),
1034 metric.WithUnit("s"),
1035 }, opt...)...,
1036 )
1037 if err != nil {
1038 return Uptime{noop.Float64Gauge{}}, err
1039 }
1040 return Uptime{i}, nil
1041 }
1042
1043 // Inst returns the underlying metric instrument.
1044 func (m Uptime) Inst() metric.Float64Gauge {
1045 return m.Float64Gauge
1046 }
1047
1048 // Name returns the semantic convention name of the instrument.
1049 func (Uptime) Name() string {
1050 return "process.uptime"
1051 }
1052
1053 // Unit returns the semantic convention unit of the instrument
1054 func (Uptime) Unit() string {
1055 return "s"
1056 }
1057
1058 // Description returns the semantic convention description of the instrument
1059 func (Uptime) Description() string {
1060 return "The time the process has been running."
1061 }
1062
1063 // Record records val to the current distribution for attrs.
1064 //
1065 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1066 // seconds as a floating point number with the highest precision available.
1067 // The actual accuracy would depend on the instrumentation and operating system.
1068 func (m Uptime) Record(ctx context.Context, val float64, attrs ...attribute.KeyValue) {
1069 if len(attrs) == 0 {
1070 m.Float64Gauge.Record(ctx, val)
1071 return
1072 }
1073
1074 o := recOptPool.Get().(*[]metric.RecordOption)
1075 defer func() {
1076 *o = (*o)[:0]
1077 recOptPool.Put(o)
1078 }()
1079
1080 *o = append(*o, metric.WithAttributes(attrs...))
1081 m.Float64Gauge.Record(ctx, val, *o...)
1082 }
1083
1084 // RecordSet records val to the current distribution for set.
1085 //
1086 // Instrumentations SHOULD use a gauge with type `double` and measure uptime in
1087 // seconds as a floating point number with the highest precision available.
1088 // The actual accuracy would depend on the instrumentation and operating system.
1089 func (m Uptime) RecordSet(ctx context.Context, val float64, set attribute.Set) {
1090 if set.Len() == 0 {
1091 m.Float64Gauge.Record(ctx, val)
1092 return
1093 }
1094
1095 o := recOptPool.Get().(*[]metric.RecordOption)
1096 defer func() {
1097 *o = (*o)[:0]
1098 recOptPool.Put(o)
1099 }()
1100
1101 *o = append(*o, metric.WithAttributeSet(set))
1102 m.Float64Gauge.Record(ctx, val, *o...)
1103 }