-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux_kernel_monitoring.txt
320 lines (278 loc) · 14.3 KB
/
linux_kernel_monitoring.txt
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
[[{monitoring.kernel,monitoring.I/O,monitoring.network,monitoring.jobs]]
# Kernel Monitorization
## dmesg
* `dmesg` prints or controls the kernel ring buffer.
```
| KERNEL MONITORIZATION [[doc_has.diagram,troubleshooting]]
| ┌ ┌───────────────────────────────────────────────────────┐
| · │ APPLICATIONS │
| · ├───────────────────────────────────────────────────────┤
| · │[ltrace][ldd] System Libraries gethostlatency perf│
| · ├───────────────────────────────────────────────────────┤
| · │ strace,sydgid System Call Interface [*3] perf│
| · │ opensnoop,statsnoop,syncsnoop │ CPU
|perf ┌ ├─────────────────┬───┬──────────────┬┬─────────────────┤ Inter- ┌────┐
|dtrace · │ VFS │ │SOCKETS [ss] ││SCHEDULER [perf│ connect |CPU1│
| · │ opensnoop │ │ ││ ├──────────┤perf│
|stap · ├─────────────────┤ │──────────────┤│ perf <·· top └─·──·
|lttnp · │ FILE SYSTEM │ │TCP/UPD [*2] ││ latencytop │ · ps · ·
|lttnp L │ │ │tcptop, ││ mpstat │ · pidstat · ·
|ktap I │ lsof,fstrace │ │tcplife, │├─────────────────┤ · · ·
| · N │ filelie,pcstat │ │tcpconnect, ││VIRTUAL MEMORY │ · Memory · ·
| · U ├─────────────────┤ │tcpaccept ││[vmstat] <·· BUS · ·
| · X │ VOLUME MANAGERS │ │tcpconnlat, ││[slabtop] <·· ┌─v─┐·
| · │ mdflush │ ├tcpretrans ││[free] ├··········>RAM│·
| · K ├─────────────────┤ ├──────────────┤│[memleak] │ └───┘·
| · E │ BLOCK DEVICE │ │IP ip, ││[comkill] │ numastat ·
| · R │ INTERFACE │ │route, ││[slabratetop] │ lstop ·
| · N │ iostat,iotop │ │iptables ││ │ ·
| · E │ blktrace │ │ ││ │ ·
| · L │ pidstat │ │ ││ │ ·
| · · │ biosnoop │ │──────────────│├─────────────────┤ ·
| · · │ biolatency │ │Ethernet [ss] ││CLOCKSOURCE │ ·
| · · │ biotop,blktrace │ │[tcpdump] ││[/sys/...] │ ·
| · · ├──·──────────────┴───┴──────────────┴┴─────────────────┤ ·
| · · │ ·[hardirqs][criticalstat] Device Drivers │ ·
| └ └ └──·────────────────────────────────────────────────────┘ I/O perf ·
| · Expander-Interconnect ┌ I/O ──┐BUS tiptop·
| · ─┬──────────────────────────────────────┬───┤ BRidge├···········┘
| · │ │ └───────┘
| └┐ │ │
| ┌v────┴───────────┐ ┌─ Network ──┴─┐ nicstat
| │I/O Controller *1│ │Controller │ ss, ip
| └─────────────────┘ └───────┬──────┘
| ┬──────┴───────┬ ┬──────┴────┬
| │ │ │ │
| Disk[*1] Swap [swapon] Port Port
| ping, traceroute]
| ethtool] [snmpget]
| lldptool]
| OTHERS: [sar] [dstat] [/proc]
|
| ┌───┐[sar -m FAN] ┌────────────┐[ipmitool]
| │FAN│ │POWER SUPPLY│[dmidecode]
| └───┘ └────────────┘
```
## `/proc/meminfo`
```
| $ cat /proc/meminfo
| MemTotal: 16116792 kB
| MemFree: 2042420 kB
| MemAvailable: 10656344 kB
| Buffers: 1637424 kB
| Cached: 6513208 kB
| SwapCached: 352 kB
| Active: 8372356 kB
| Inactive: 3940908 kB
| Active(anon): 3755128 kB
| Inactive(anon): 645496 kB
| Active(file): 4617228 kB
| Inactive(file): 3295412 kB
| Unevictable: 0 kB
| Mlocked: 0 kB
| SwapTotal: 8126460 kB
| SwapFree: 8124156 kB
| Dirty: 1304 kB
| Writeback: 0 kB
| AnonPages: 4162388 kB
| Mapped: 732652 kB
| Shmem: 238000 kB
| Slab: 1337700 kB
| SReclaimable: 1029376 kB
| SUnreclaim: 308324 kB
| KernelStack: 15632 kB
| PageTables: 31724 kB
| NFS_Unstable: 0 kB
| Bounce: 0 kB
| WritebackTmp: 0 kB
| CommitLimit: 16184856 kB
| Committed_AS: 11012532 kB
| VmallocTotal: 34359738367 kB
| VmallocUsed: 0 kB
| VmallocChunk: 0 kB
| HardwareCorrupted: 0 kB
| AnonHugePages: 0 kB
| ShmemHugePages: 0 kB
| ShmemPmdMapped: 0 kB
| CmaTotal: 0 kB
| CmaFree: 0 kB
| HugePages_Total: 0
| HugePages_Free: 0
| HugePages_Rsvd: 0
| HugePages_Surp: 0
| Hugepagesize: 2048 kB
| Hugetlb: 0 kB
| DirectMap4k: 1147072 kB
| DirectMap2M: 15319040 kB
```
[[{PM.TODO]]
## BCC
* Dynamic Tracing toolkit for creating efficient Linux kernel tracing,
performance Monitoring, networking and much more.
* It makes use of extended BPF (Berkeley Packet Filters), formally known as eBPF
* <https://github.com/iovisor/bcc>
[[PM.TODO}]]
[[{doc_has.comparative,PM.TODO]]
### Linux Tracer comparative
* <http://www.brendangregg.com/blog/2015-07-08/choosing-a-linux-tracer.html>
[[doc_has.comparative}]]
## ltrace: Library Call Tracer [[{monitoring.jobs]]
* <https://linux.die.net/man/1/ltrace>
Summary:
```
ltrace | ltrace -c # ← Count time and calls for each library call*
| and report a summary on program exit. *
[-e filter|-L] | [-e filter|-L]
[-l|--library=library_pattern] | [-l|--library=library_pattern]
[-x filter] | [-x filter]
[-S] | [-S]
[-b|--no-signals] |
[-i] [-w|--where=nr] |
[-r|-t|-tt|-ttt] |
[-T] |
[-F pathlist] |
[-A maxelts] |
[-s strsize] |
[-C|--demangle] |
[-a|--align column] |
[-n|--indent nr] |
[-o|--output filename] | [-o|--output filename]
[-D|--debug mask] |
[-u username] |
[-f] | [-f]
[-p pid] | [-p pid]
[ [--] command [arg ...] ] | [ [--] command [arg ...] ]
```
* runs the specified command until it exits, intercepting/recording:
* dynamic library calls by process
* Display functions and funct.parameters.
* external prototype libraries is needed
for human-readable output.
(ltrace.conf(5), section PROTOTYPE LIBRARY DISCOVERY )
* signals which received by process
* system calls by process
[[}]]
[[{monitoring.jobs.strace]]
## strace: System call tracer
* man 1 strace
```
| strace | strace -c ← -c: Count time, calls, and errors
| | for each system call and report summary on exit.
| | -f aggregate over all forked processes
| [ -dDffhiqrtttTvVxx ] | [ -D ]
| [ -acolumn ] |
| [ -eexpr ] ... | [ -eexpr ] ...
| | [ -Ooverhead ]
| [ -ofile ] |
| [ -ppid ] ... |
| [ -sstrsize ] |
| [ -uusername ] |
| [ -Evar=val ] ... |
| [ -Evar ] ... | [ -Ssortby ]
| | [ -Ssortby ]
| [ command [ arg ... ] ] | [ command [ arg ... ] ]
```
* strace runs specified command until it exits intercepting:
* system calls called by a process
* system-call-name + arguments + return-value is printed to STDERR (or -o file)
* signals received by a process
```
| Ex system-call output:
| open("/dev/null", O_RDONLY) = 3
| open("/foo/bar", O_RDONLY) = -1 ENOENT (No such file or directory)
| ...
| Ex signal output:
| $ strace sleep 111
| ...
| sigsuspend([] <unfinished ...>
| --- SIGINT (Interrupt) --- ← Signal received
| ...
| +++ killed by SIGINT +++
```
* If a system call is being executed and meanwhile another one is being called
from a different thread/process then strace will try to preserve the order
of those events and mark the ongoing call as being unfinished.
* When the call returns it will be marked as resumed. Ex. output:
```
→ [pid 28772] select(4, [3], NULL, NULL, NULL *unfinished ... *
→ [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
→ [pid 28772] *<... select resumed>* ) = 1 (in [3])
```
Interruption of a (restartable) system call by a signal delivery is
processed differently as kernel terminates the system call and also
arranges its immediate reexecution after the signal handler completes.
```
| read(0, 0x7ffff72cf5cf, 1) = ? *ERESTARTSYS (To be restarted)*
| --- SIGALRM (Alarm clock) @ 0 (0) ---
| rt_sigreturn(0xe) = 0
| read(0, ""..., 1) = 0
```
* explain: Tool to decode the error returned from strace
<https://linux.die.net/man/1/explain>
[[monitoring.jobs.strace}]]
[[{monitoring.cpu]]
## mpstat-CPU stats (ints., hypervisor...)
* <https://linux.die.net/man/1/mpstat>
```
| mpstat
| [ -A ] == -I ALL -u -P ALL
| [ -I { SUM | CPU | ALL } ] == Report interrupts statistics
| [ -u ] Reports cpu utilization (default)
| [ -P { cpu [,...] | ON | ALL } ] Indicates the processor number
| [ -V ]
| [ secs_interval [ count ] ]
| secs_interval = 0 => Report from times system startup (boot)
|
| mpstat writes to standard output activities for each available processor,
| Global average activities among all processors are also reported.
|
| CPU output columns:
| %usr : executing at the user level (application).
| %nice : executing at the user level with nice priority.
| %sys : executing at the system level (kernel).
| It does NOT include time spent servicing hardware
| and software interrupts.
| %iowait: idle during which the system had an outstanding disk I/O request.
| %irq : time spent by the CPU or CPUs to service hardware interrupts.
| %soft : time spent by the CPU or CPUs to service software interrupts.
|
| %steal : **time spent in involuntary wait by the virtual CPU or CPUs
| while the hypervisor was servicing another virtual processor** !!!!
| [[monitoring.hypervisor]]
|
| %guest : time spent by the CPU or CPUs to run a virtual processor.
| %idle : time that the CPU or CPUs were idle and the system did not have
| an outstanding disk I/O request.
```
[[}]]
[[{profiling.latencytop,troubleshooting.performance.101,troubleshooting.locks,troubleshooting.jobs,QA.UX,PM.low_code]]
## latencytop
* <https://linux.die.net/man/8/xlatencytop>
* aimed at:
* identifying and visualizing where (kernel and userspace) latencies are happening
* What kind of operation/action is causing the latency
**LATENCYTOP FOCUSES ON THE CASES WHERE THE APPLICATIONS WANT TO RUN
AND EXECUTE USEFUL CODE, BUT THERE'S SOME RESOURCE THAT'S NOT
CURRENTLY AVAILABLE (AND THE KERNEL THEN BLOCKS THE PROCESS).**
This is done both on a system level and on a per process level,
so that you can see what's happening to the system, and which
process is suffering and/or causing the delays.
```
| $ sudo latencytop <·· Press "s" + "letter" to display active processes
| starting with that lettter.
| Press "s" followed by 0 to remove the filter
```
* NOTES:
* See also notes about disk write-read pending queue.
* There are newer alternatives based on BPF:
<http://www.brendangregg.com/blog/2016-10-27/dtrace-for-linux-2016.html>
* See also the more advanced TimeChart:
* <http://www.linux-magazine.com/Online/News/Timechart-Zoom-in-on-Operating-System>
* <http://blog.fenrus.org/?p=5>
[[profiling.latencytop}]]
[[monitoring.kernel}]]
[[{monitoring.kernel,monitoring.eBPF,kernel.eBPF]]
## eBPF Tracing
* Tutorial and Examples:
<https://www.brendangregg.com/blog/2019-01-01/learn-ebpf-tracing.html>
[[monitoring.kernel.eBPF}]]