1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import (
Callable,
Final,
Generator,
Iterable,
Optional,
Sequence,
Union,
)
from opentelemetry.metrics import (
CallbackOptions,
Counter,
Meter,
ObservableGauge,
Observation,
UpDownCounter,
)
# pylint: disable=invalid-name
CallbackT = Union[
Callable[[CallbackOptions], Iterable[Observation]],
Generator[Iterable[Observation], CallbackOptions, None],
]
PROCESS_CONTEXT_SWITCHES: Final = "process.context_switches"
"""
Number of times the process has been context switched
Instrument: counter
Unit: {context_switch}
"""
def create_process_context_switches(meter: Meter) -> Counter:
"""Number of times the process has been context switched"""
return meter.create_counter(
name=PROCESS_CONTEXT_SWITCHES,
description="Number of times the process has been context switched.",
unit="{context_switch}",
)
PROCESS_CPU_TIME: Final = "process.cpu.time"
"""
Total CPU seconds broken down by different states
Instrument: counter
Unit: s
"""
def create_process_cpu_time(meter: Meter) -> Counter:
"""Total CPU seconds broken down by different states"""
return meter.create_counter(
name=PROCESS_CPU_TIME,
description="Total CPU seconds broken down by different states.",
unit="s",
)
PROCESS_CPU_UTILIZATION: Final = "process.cpu.utilization"
"""
Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process
Instrument: gauge
Unit: 1
"""
def create_process_cpu_utilization(
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
"""Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process"""
return meter.create_observable_gauge(
name=PROCESS_CPU_UTILIZATION,
callbacks=callbacks,
description="Difference in process.cpu.time since the last measurement, divided by the elapsed time and number of CPUs available to the process.",
unit="1",
)
PROCESS_DISK_IO: Final = "process.disk.io"
"""
Disk bytes transferred
Instrument: counter
Unit: By
"""
def create_process_disk_io(meter: Meter) -> Counter:
"""Disk bytes transferred"""
return meter.create_counter(
name=PROCESS_DISK_IO,
description="Disk bytes transferred.",
unit="By",
)
PROCESS_MEMORY_USAGE: Final = "process.memory.usage"
"""
The amount of physical memory in use
Instrument: updowncounter
Unit: By
"""
def create_process_memory_usage(meter: Meter) -> UpDownCounter:
"""The amount of physical memory in use"""
return meter.create_up_down_counter(
name=PROCESS_MEMORY_USAGE,
description="The amount of physical memory in use.",
unit="By",
)
PROCESS_MEMORY_VIRTUAL: Final = "process.memory.virtual"
"""
The amount of committed virtual memory
Instrument: updowncounter
Unit: By
"""
def create_process_memory_virtual(meter: Meter) -> UpDownCounter:
"""The amount of committed virtual memory"""
return meter.create_up_down_counter(
name=PROCESS_MEMORY_VIRTUAL,
description="The amount of committed virtual memory.",
unit="By",
)
PROCESS_NETWORK_IO: Final = "process.network.io"
"""
Network bytes transferred
Instrument: counter
Unit: By
"""
def create_process_network_io(meter: Meter) -> Counter:
"""Network bytes transferred"""
return meter.create_counter(
name=PROCESS_NETWORK_IO,
description="Network bytes transferred.",
unit="By",
)
PROCESS_OPEN_FILE_DESCRIPTOR_COUNT: Final = (
"process.open_file_descriptor.count"
)
"""
Number of file descriptors in use by the process
Instrument: updowncounter
Unit: {file_descriptor}
"""
def create_process_open_file_descriptor_count(meter: Meter) -> UpDownCounter:
"""Number of file descriptors in use by the process"""
return meter.create_up_down_counter(
name=PROCESS_OPEN_FILE_DESCRIPTOR_COUNT,
description="Number of file descriptors in use by the process.",
unit="{file_descriptor}",
)
PROCESS_PAGING_FAULTS: Final = "process.paging.faults"
"""
Number of page faults the process has made
Instrument: counter
Unit: {fault}
"""
def create_process_paging_faults(meter: Meter) -> Counter:
"""Number of page faults the process has made"""
return meter.create_counter(
name=PROCESS_PAGING_FAULTS,
description="Number of page faults the process has made.",
unit="{fault}",
)
PROCESS_THREAD_COUNT: Final = "process.thread.count"
"""
Process threads count
Instrument: updowncounter
Unit: {thread}
"""
def create_process_thread_count(meter: Meter) -> UpDownCounter:
"""Process threads count"""
return meter.create_up_down_counter(
name=PROCESS_THREAD_COUNT,
description="Process threads count.",
unit="{thread}",
)
PROCESS_UPTIME: Final = "process.uptime"
"""
The time the process has been running
Instrument: gauge
Unit: s
Note: Instrumentations SHOULD use a gauge with type `double` and measure uptime in seconds as a floating point number with the highest precision available.
The actual accuracy would depend on the instrumentation and operating system.
"""
def create_process_uptime(
meter: Meter, callbacks: Optional[Sequence[CallbackT]]
) -> ObservableGauge:
"""The time the process has been running"""
return meter.create_observable_gauge(
name=PROCESS_UPTIME,
callbacks=callbacks,
description="The time the process has been running.",
unit="s",
)
|