Debian Codegraph @

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