Table des matières

Version : 2022.01

Updated: 2022/11/01 07:25

Topic 200: Capacity Planning

Présentation des Fichiers Spéciaux

Dans l'ordinateur les périphériques sont reliés à un contrôleur qui communique avec le processeur à l'aide d'un bus. Le contrôleur ainsi que les périphériques nécessitent des pilotes. Sous Linux, les pilotes sont généralement fournis sous la forme d'un module. Chaque périphérique est représenté par un fichier spécial dans le répertoire /dev et c'est dans ce fichier que le système trouve les informations nécessaires pour s'adresser au pilote.

Important : Les périphériques qui nécessitent à ce que l'ordinateur soit éteint afin des les brancher/débrancher sont appelés communément Cold Plug Devices. Les périphériques qui peuvent être brancher/débrancher à chaud sont appelés des Hot Plug Devices.

Consultez le contenu du répertoire /dev :

root@debian11:~# ls -l /dev | more
total 0
crw-r--r--  1 root root     10, 235 Apr 26 13:08 autofs
drwxr-xr-x  2 root root         480 Apr 28 06:26 block
drwxr-xr-x  2 root root         120 Apr 26 13:08 bsg
crw-rw----  1 root disk     10, 234 Apr 28 05:31 btrfs-control
drwxr-xr-x  3 root root          60 Apr 26 13:08 bus
lrwxrwxrwx  1 root root           3 Apr 26 13:08 cdrom -> sr0
drwxr-xr-x  2 root root        2800 Apr 28 06:02 char
crw--w----  1 root tty       5,   1 Apr 30 12:19 console
lrwxrwxrwx  1 root root          11 Apr 26 13:08 core -> /proc/kcore
crw-------  1 root root     10,  62 Apr 26 13:08 cpu_dma_latency
crw-------  1 root root     10, 203 Apr 26 13:08 cuse
drwxr-xr-x  7 root root         140 Apr 26 13:08 disk
brw-rw----  1 root disk    254,   0 Apr 27 15:21 dm-0
brw-rw----  1 root disk    254,   1 Apr 26 16:33 dm-1
brw-rw----  1 root disk    254,   2 Apr 28 06:27 dm-2
drwxr-xr-x  3 root root          80 Apr 26 13:08 dri
lrwxrwxrx  1 root root           3 Apr 26 13:08 dvd -> sr0
crw-------  1 root root     10,  61 Apr 28 06:02 ecryptfs
crw-rw----  1 root video    29,   0 Apr 26 13:08 fb0
lrwxrwxrwx  1 root root          13 Apr 26 13:08 fd -> /proc/self/fd
crw-rw-rw-  1 root root      1,   7 Apr 26 13:08 full
crw-rw-rw-  1 root root     10, 229 Apr 26 13:08 fuse
crw-------  1 root root    248,   0 Apr 26 13:08 hidraw0
crw-------  1 root root     10, 228 Apr 26 13:08 hpet
drwxr-xr-x  2 root root           0 Apr 26 13:08 hugepages
lrwxrwxrwx  1 root root          12 Apr 26 13:08 initctl -> /run/initctl
drwxr-xr-x  4 root root         280 Apr 26 13:08 input
crw-r--r--  1 root root      1,  11 Apr 26 13:08 kmsg
lrwxrwxrwx  1 root root          28 Apr 26 13:08 log -> /run/systemd/journal/dev-log
crw-rw----  1 root disk     10, 237 Apr 26 13:08 loop-control
drwxr-xr-x  2 root root         120 Apr 28 06:26 mapper
crw-r-----  1 root kmem      1,   1 Apr 26 13:08 mem
drwxrwxrwt  2 root root          40 Apr 26 13:08 mqueue
drwxr-xr-x  2 root root          60 Apr 26 13:08 net
crw-rw-rw-  1 root root      1,   3 Apr 26 13:08 null
crw-------  1 root root     10, 144 Apr 26 13:08 nvram
crw-r-----  1 root kmem      1,   4 Apr 26 13:08 port
crw-------  1 root root    108,   0 Apr 26 13:08 ppp
crw-------  1 root root     10,   1 Apr 26 13:08 psaux
crw-rw-rw-  1 root tty       5,   2 Apr 30 15:29 ptmx
drwxr-xr-x  2 root root           0 Apr 26 13:08 pts
crw-rw-rw-  1 root root      1,   8 Apr 26 13:08 random
crw-rw-r--  1 root netdev   10, 242 Apr 26 13:08 rfkill
lrwxrwxrwx  1 root root           4 Apr 26 13:08 rtc -> rtc0
crw-------  1 root root    252,   0 Apr 26 13:08 rtc0
--More--
[q]

On peut noter dans la sortie de la commande que certains fichiers sont de type bloc (b), tandis que d'autre sont de type caractère (c).

...
brw-rw----  1 root disk      8,  33 Apr 26 13:46 sdc1
...
crw--w----  1 root tty       5,   1 Apr 30 12:19 console
...

La différence entre les deux repose sur le type de communication entre le système et le module. Dans le premier cas le système accède au périphérique par des coordonnées du bloc de données sur le support tandis que dans le deuxième cas la communication d'échange de données se fait octet par octet sans utiliser des tampons.

Les deux informations clefs du fichier spécial sont situées à la place de la taille d'un fichier normal et se nomment le majeur et le mineur :

LAB #1 - Commandes

1.1 - La Commande lspci

Cette commande vous renseigne sur les adaptateurs reliés aux bus PCI, AGP et PCI express :

root@debian11:~# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II] (rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Device 1234:1111 (rev 02)
00:03.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
00:05.0 SCSI storage controller: Red Hat, Inc. Virtio SCSI
00:12.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:1e.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge
00:1f.0 PCI bridge: Red Hat, Inc. QEMU PCI-PCI bridge

Pour obtenir de l'information sur un adaptateur spécifique, il convient d'utiliser la même commande avec l'option -v en spécifiant l'identifiant concerné :

root@debian11:~# lspci -v -s 00:03.0
00:03.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
        Subsystem: Red Hat, Inc. Virtio memory balloon
        Physical Slot: 3
        Flags: bus master, fast devsel, latency 0, IRQ 10
        I/O ports at e000 [size=64]
        Memory at fe400000 (64-bit, prefetchable) [size=16K]
        Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
        Capabilities: [70] Vendor Specific Information: VirtIO: Notify
        Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
        Capabilities: [50] Vendor Specific Information: VirtIO: ISR
        Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg
        Kernel driver in use: virtio-pci
        Kernel modules: virtio_pci

ou :

root@debian11:~# lspci -vv -s 00:03.0
00:03.0 Unclassified device [00ff]: Red Hat, Inc. Virtio memory balloon
        Subsystem: Red Hat, Inc. Virtio memory balloon
        Physical Slot: 3
        Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 0
        Interrupt: pin A routed to IRQ 10
        Region 0: I/O ports at e000 [size=64]
        Region 4: Memory at fe400000 (64-bit, prefetchable) [size=16K]
        Capabilities: [84] Vendor Specific Information: VirtIO: <unknown>
                BAR=0 offset=00000000 size=00000000
        Capabilities: [70] Vendor Specific Information: VirtIO: Notify
                BAR=4 offset=00003000 size=00001000 multiplier=00000004
        Capabilities: [60] Vendor Specific Information: VirtIO: DeviceCfg
                BAR=4 offset=00002000 size=00001000
        Capabilities: [50] Vendor Specific Information: VirtIO: ISR
                BAR=4 offset=00001000 size=00001000
        Capabilities: [40] Vendor Specific Information: VirtIO: CommonCfg
                BAR=4 offset=00000000 size=00001000
        Kernel driver in use: virtio-pci
        Kernel modules: virtio_pci

Les options de cette commande sont :

root@debian11:~# lspci --help
lspci: invalid option -- '-'
Usage: lspci [<switches>]

Basic display modes:
-mm             Produce machine-readable output (single -m for an obsolete format)
-t              Show bus tree

Display options:
-v              Be verbose (-vv or -vvv for higher verbosity)
-k              Show kernel drivers handling each device
-x              Show hex-dump of the standard part of the config space
-xxx            Show hex-dump of the whole config space (dangerous; root only)
-xxxx           Show hex-dump of the 4096-byte extended config space (root only)
-b              Bus-centric view (addresses and IRQ's as seen by the bus)
-D              Always show domain numbers
-P              Display bridge path in addition to bus and device number
-PP             Display bus path in addition to bus and device number

Resolving of device ID's to names:
-n              Show numeric ID's
-nn             Show both textual and numeric ID's (names & numbers)
-q              Query the PCI ID database for unknown ID's via DNS
-qq             As above, but re-query locally cached entries
-Q              Query the PCI ID database for all ID's via DNS

Selection of devices:
-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]   Show only devices in selected slots
-d [<vendor>]:[<device>][:<class>]              Show only devices with specified ID's

Other options:
-i <file>       Use specified ID database instead of /usr/share/misc/pci.ids.gz
-p <file>       Look up kernel modules in a given file instead of default modules.pcimap
-M              Enable `bus mapping' mode (dangerous; root only)

PCI access options:
-A <method>     Use the specified PCI access method (see `-A help' for a list)
-O <par>=<val>  Set PCI access parameter (see `-O help' for a list)
-G              Enable PCI access debugging
-H <mode>       Use direct hardware access (<mode> = 1 or 2)
-F <file>       Read PCI configuration dump from a given file

1.2 - La Commande lsusb

Cette commande vous renseigne sur les adaptateurs reliés au bus usb :

root@debian11:~# lsusb
Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd QEMU USB Tablet
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

root@debian11:~# lsusb -vt
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
    ID 1d6b:0001 Linux Foundation 1.1 root hub
    |__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 12M
        ID 0627:0001 Adomax Technology Co., Ltd 

Les options de cette commande sont :

root@debian11:~# lsusb --help
Usage: lsusb [options]...
List USB devices
  -v, --verbose
      Increase verbosity (show descriptors)
  -s [[bus]:][devnum]
      Show only devices with specified device and/or
      bus numbers (in decimal)
  -d vendor:[product]
      Show only devices with the specified vendor and
      product ID numbers (in hexadecimal)
  -D device
      Selects which device lsusb will examine
  -t, --tree
      Dump the physical USB device hierarchy as a tree
  -V, --version
      Show version of program
  -h, --help
      Show usage and help

1.3 - La Commande lsblk

Cette commande vous renseigne sur les périphériques de type bloc :

root@debian11:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
sda           8:0    0   32G  0 disk  
├─sda1        8:1    0   31G  0 part  /
├─sda2        8:2    0    1K  0 part  
└─sda5        8:5    0  975M  0 part  [SWAP]
sdb           8:16   0   64G  0 disk  
sdc           8:32   0    4G  0 disk  
├─sdc1        8:33   0  100M  0 part  
├─sdc2        8:34   0  100M  0 part  
├─sdc3        8:35   0  100M  0 part  
├─sdc4        8:36   0    1K  0 part  
├─sdc5        8:37   0  500M  0 part  
├─sdc6        8:38   0  200M  0 part  
│ └─vg0-lv1 254:0    0  104M  0 lvm   
├─sdc7        8:39   0  300M  0 part  
│ └─vg0-lv2 254:1    0  112M  0 lvm   
├─sdc8        8:40   0  500M  0 part  
│ └─md1       9:1    0  996M  0 raid5 
├─sdc9        8:41   0  400M  0 part  
│ └─vg0-lv2 254:1    0  112M  0 lvm   
├─sdc10       8:42   0  500M  0 part  
│ └─md1       9:1    0  996M  0 raid5 
├─sdc11       8:43   0  500M  0 part  
│ └─md1       9:1    0  996M  0 raid5 
└─sdc12       8:44   0  200M  0 part  
sr0          11:0    1  378M  0 rom    

Les options de cette commande sont :

root@debian11:~# lsblk --help

Usage:
 lsblk [options] [<device> ...]

List information about block devices.

Options:
 -D, --discard        print discard capabilities
 -E, --dedup <column> de-duplicate output by <column>
 -I, --include <list> show only devices with specified major numbers
 -J, --json           use JSON output format
 -O, --output-all     output all columns
 -P, --pairs          use key="value" output format
 -S, --scsi           output info about SCSI devices
 -T, --tree[=<column>] use tree format output
 -a, --all            print all devices
 -b, --bytes          print SIZE in bytes rather than in human readable format
 -d, --nodeps         don't print slaves or holders
 -e, --exclude <list> exclude devices by major number (default: RAM disks)
 -f, --fs             output info about filesystems
 -i, --ascii          use ascii characters only
 -l, --list           use list format output
 -M, --merge          group parents of sub-trees (usable for RAIDs, Multi-path)
 -m, --perms          output info about permissions
 -n, --noheadings     don't print headings
 -o, --output <list>  output columns
 -p, --paths          print complete device path
 -r, --raw            use raw output format
 -s, --inverse        inverse dependencies
 -t, --topology       output info about topology
 -z, --zoned          print zone model
 -x, --sort <column>  sort output by <column>
     --sysroot <dir>  use specified directory as system root

 -h, --help           display this help
 -V, --version        display version

Available output columns:
        NAME  device name
       KNAME  internal kernel device name
        PATH  path to the device node
     MAJ:MIN  major:minor device number
     FSAVAIL  filesystem size available
      FSSIZE  filesystem size
      FSTYPE  filesystem type
      FSUSED  filesystem size used
      FSUSE%  filesystem use percentage
       FSVER  filesystem version
  MOUNTPOINT  where the device is mounted
       LABEL  filesystem LABEL
        UUID  filesystem UUID
      PTUUID  partition table identifier (usually UUID)
      PTTYPE  partition table type
    PARTTYPE  partition type code or UUID
 PARTTYPENAME  partition type name
   PARTLABEL  partition LABEL
    PARTUUID  partition UUID
   PARTFLAGS  partition flags
          RA  read-ahead of the device
          RO  read-only device
          RM  removable device
     HOTPLUG  removable or hotplug device (usb, pcmcia, ...)
       MODEL  device identifier
      SERIAL  disk serial number
        SIZE  size of the device
       STATE  state of the device
       OWNER  user name
       GROUP  group name
        MODE  device node permissions
   ALIGNMENT  alignment offset
      MIN-IO  minimum I/O size
      OPT-IO  optimal I/O size
     PHY-SEC  physical sector size
     LOG-SEC  logical sector size
        ROTA  rotational device
       SCHED  I/O scheduler name
     RQ-SIZE  request queue size
        TYPE  device type
    DISC-ALN  discard alignment offset
   DISC-GRAN  discard granularity
    DISC-MAX  discard max bytes
   DISC-ZERO  discard zeroes data
       WSAME  write same max bytes
         WWN  unique storage identifier
        RAND  adds randomness
      PKNAME  internal parent kernel device name
        HCTL  Host:Channel:Target:Lun for SCSI
        TRAN  device transport type
  SUBSYSTEMS  de-duplicated chain of subsystems
         REV  device revision
      VENDOR  device vendor
       ZONED  zone model
         DAX  dax-capable device

For more details see lsblk(8).

1.4 - La Commande dmidecode

La commande dmidecode lit la table DMI (Desktop Management Interface) aussi appelée SMBIOS (System Management BIOS) et fourni les informations sur :

root@debian11:~# dmidecode
# dmidecode 3.3
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.
10 structures occupying 443 bytes.
Table at 0x000F58C0.

Handle 0x0000, DMI type 0, 24 bytes
BIOS Information
        Vendor: SeaBIOS
        Version: rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org
        Release Date: 04/01/2014
        Address: 0xE8000
        Runtime Size: 96 kB
        ROM Size: 64 kB
        Characteristics:
                BIOS characteristics not supported
                Targeted content distribution is supported
        BIOS Revision: 0.0

Handle 0x0100, DMI type 1, 27 bytes
System Information
        Manufacturer: QEMU
        Product Name: Standard PC (i440FX + PIIX, 1996)
        Version: pc-i440fx-5.2
        Serial Number: Not Specified
        UUID: ce816e48-faa4-4cb9-a03e-f0f58040c52b
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Not Specified

Handle 0x0300, DMI type 3, 22 bytes
Chassis Information
        Manufacturer: QEMU
        Type: Other
        Lock: Not Present
        Version: pc-i440fx-5.2
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Boot-up State: Safe
        Power Supply State: Safe
        Thermal State: Safe
        Security Status: Unknown
        OEM Information: 0x00000000
        Height: Unspecified
        Number Of Power Cords: Unspecified
        Contained Elements: 0
        SKU Number: Not Specified

Handle 0x0400, DMI type 4, 42 bytes
Processor Information
        Socket Designation: CPU 0
        Type: Central Processor
        Family: Other
        Manufacturer: QEMU
        ID: 61 0F 00 00 FF FB 8B 07
        Version: pc-i440fx-5.2
        Voltage: Unknown
        External Clock: Unknown
        Max Speed: 2000 MHz
        Current Speed: 2000 MHz
        Status: Populated, Enabled
        Upgrade: Other
        L1 Cache Handle: Not Provided
        L2 Cache Handle: Not Provided
        L3 Cache Handle: Not Provided
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified
        Core Count: 2
        Core Enabled: 2
        Thread Count: 1
        Characteristics: None

Handle 0x1000, DMI type 16, 23 bytes
Physical Memory Array
        Location: Other
        Use: System Memory
        Error Correction Type: Multi-bit ECC
        Maximum Capacity: 4 GB
        Error Information Handle: Not Provided
        Number Of Devices: 1

Handle 0x1100, DMI type 17, 40 bytes
Memory Device
        Array Handle: 0x1000
        Error Information Handle: Not Provided
        Total Width: Unknown
        Data Width: Unknown
        Size: 4 GB
        Form Factor: DIMM
        Set: None
        Locator: DIMM 0
        Bank Locator: Not Specified
        Type: RAM
        Type Detail: Other
        Speed: Unknown
        Manufacturer: QEMU
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified
        Rank: Unknown
        Configured Memory Speed: Unknown
        Minimum Voltage: Unknown
        Maximum Voltage: Unknown
        Configured Voltage: Unknown

Handle 0x1300, DMI type 19, 31 bytes
Memory Array Mapped Address
        Starting Address: 0x00000000000
        Ending Address: 0x000BFFFFFFF
        Range Size: 3 GB
        Physical Array Handle: 0x1000
        Partition Width: 1

Handle 0x1301, DMI type 19, 31 bytes
Memory Array Mapped Address
        Starting Address: 0x00100000000
        Ending Address: 0x0013FFFFFFF
        Range Size: 1 GB
        Physical Array Handle: 0x1000
        Partition Width: 1

Handle 0x2000, DMI type 32, 11 bytes
System Boot Information
        Status: No errors detected

Handle 0x7F00, DMI type 127, 4 bytes
End Of Table

Les options de cette commande sont :

root@debian11:~# dmidecode --help
Usage: dmidecode [OPTIONS]
Options are:
 -d, --dev-mem FILE     Read memory from device FILE (default: /dev/mem)
 -h, --help             Display this help text and exit
 -q, --quiet            Less verbose output
 -s, --string KEYWORD   Only display the value of the given DMI string
 -t, --type TYPE        Only display the entries of given type
 -H, --handle HANDLE    Only display the entry of given handle
 -u, --dump             Do not decode the entries
     --dump-bin FILE    Dump the DMI data to a binary file
     --from-dump FILE   Read the DMI data from a binary file
     --no-sysfs         Do not attempt to read DMI data from sysfs files
     --oem-string N     Only display the value of the given OEM string
 -V, --version          Display the version and exit

LAB #2 - La commande sysctl

2.1 - Répertoire /proc

Le répertoire /proc contient des fichiers et des répertoires virtuels. Le contenu de ces fichiers est créé dynamiquement lors de la consultation. Seul root peut consulter la totalité des informations dans le répertoire /proc.

root@debian11:~# ls /proc
1    128  24     34952  46798  54400  55364  56363  57690  68    acpi       dynamic_debug  key-users    mtrr          sys
10   13   244    4      46804  54401  55367  56440  57691  71    buddyinfo  execdomains    kmsg         net           sysrq-trigger
11   15   25     42378  46805  54405  55368  56894  57772  72    bus        fb             kpagecgroup  pagetypeinfo  sysvipc
116  16   27     42390  46806  54406  55385  56910  57773  7576  cgroups    filesystems    kpagecount   partitions    thread-self
119  17   28     42391  46808  54407  55392  56911  57781  7708  cmdline    fs             kpageflags   pressure      timer_list
12   176  287    42392  46812  54408  55549  56912  57785  7709  consoles   interrupts     loadavg      sched_debug   tty
120  177  29     42401  46813  55     55563  57     57792  7883  cpuinfo    iomem          locks        schedstat     uptime
121  18   3      42402  50     55345  55565  57148  57798  7894  crypto     ioports        mdstat       self          version
122  2    30     46777  51     55347  55569  57149  57800  8     devices    irq            meminfo      slabinfo      vmallocinfo
123  20   31     46780  52     55348  55571  57150  58     8904  diskstats  kallsyms       misc         softirqs      vmstat
126  214  32     46782  53     55350  56     57308  59     8905  dma        kcore          modules      stat          zoneinfo
127  23   34924  46797  54     55353  56135  57689  6      9     driver     keys           mounts       swaps

Fichiers

Processeur
root@debian11:~# cat /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 15
model           : 6
model name      : Common KVM processor
stepping        : 1
microcode       : 0x1
cpu MHz         : 2399.982
cache size      : 16384 KB
physical id     : 0
siblings        : 2
core id         : 0
cpu cores       : 2
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl xtopology cpuid tsc_known_freq pni cx16 x2apic hypervisor lahf_lm cpuid_fault pti
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 4799.96
clflush size    : 64
cache_alignment : 128
address sizes   : 40 bits physical, 48 bits virtual
power management:

processor       : 1
vendor_id       : GenuineIntel
cpu family      : 15
model           : 6
model name      : Common KVM processor
stepping        : 1
microcode       : 0x1
cpu MHz         : 2399.982
cache size      : 16384 KB
physical id     : 0
siblings        : 2
core id         : 1
cpu cores       : 2
apicid          : 1
initial apicid  : 1
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl xtopology cpuid tsc_known_freq pni cx16 x2apic hypervisor lahf_lm cpuid_fault pti
bugs            : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips        : 4799.96
clflush size    : 64
cache_alignment : 128
address sizes   : 40 bits physical, 48 bits virtual
power management:
Interruptions système
root@debian11:~# cat /proc/interrupts
           CPU0       CPU1       
  0:         29          0   IO-APIC   2-edge      timer
  1:          0          9   IO-APIC   1-edge      i8042
  6:          0          3   IO-APIC   6-edge      floppy
  8:          1          0   IO-APIC   8-edge      rtc0
  9:          0          0   IO-APIC   9-fasteoi   acpi
 10:          0     177277   IO-APIC  10-fasteoi   virtio0
 11:         40          0   IO-APIC  11-fasteoi   uhci_hcd:usb1
 12:         15          0   IO-APIC  12-edge      i8042
 14:          0          0   IO-APIC  14-edge      ata_piix
 15:          0     352265   IO-APIC  15-edge      ata_piix
 24:          0          0   PCI-MSI 294912-edge      virtio2-config
 25:      24163          0   PCI-MSI 294913-edge      virtio2-input.0
 26:          0      18954   PCI-MSI 294914-edge      virtio2-output.0
 27:          0          0   PCI-MSI 81920-edge      virtio1-config
 28:          0          0   PCI-MSI 81921-edge      virtio1-control
 29:          0          0   PCI-MSI 81922-edge      virtio1-event
 30:      74023          0   PCI-MSI 81923-edge      virtio1-request
 31:          0      71408   PCI-MSI 81924-edge      virtio1-request
NMI:          0          0   Non-maskable interrupts
LOC:    1701175    2400564   Local timer interrupts
SPU:          0          0   Spurious interrupts
PMI:          0          0   Performance monitoring interrupts
IWI:          1          0   IRQ work interrupts
RTR:          0          0   APIC ICR read retries
RES:     284026     248715   Rescheduling interrupts
CAL:      47419      21994   Function call interrupts
TLB:      23047      13223   TLB shootdowns
TRM:          0          0   Thermal event interrupts
THR:          0          0   Threshold APIC interrupts
DFR:          0          0   Deferred Error APIC interrupts
MCE:          0          0   Machine check exceptions
MCP:       1140       1140   Machine check polls
ERR:          0
MIS:          0
PIN:          0          0   Posted-interrupt notification event
NPI:          0          0   Nested posted-interrupt event
PIW:          0          0   Posted-interrupt wakeup event

Important : Un pilote de périphérique demande au processeur de fournir un service en utilisant un IRQ. Quand la demande est faite, le processeur interrompe ses activités et passe le contrôle au pilote identifié par l'IRQ. Techniquement l'attribution d'un IRQ à un périphérique doit être exclusive. Dans le cas où deux périphériques demandent un service en même temps, c'est le périphérique ayant l'IRQ le plus bas qui est prioritaire.

Canaux DMA
root@debian11:~# cat /proc/dma
 2: floppy
 4: cascade
Plages d'entrée/sortie
root@debian11:~# cat /proc/ioports
0000-0cf7 : PCI Bus 0000:00
  0000-001f : dma1
  0020-0021 : pic1
  0040-0043 : timer0
  0050-0053 : timer1
  0060-0060 : keyboard
  0064-0064 : keyboard
  0070-0077 : rtc0
  0080-008f : dma page reg
  00a0-00a1 : pic2
  00c0-00df : dma2
  00f0-00ff : fpu
  0170-0177 : 0000:00:01.1
    0170-0177 : ata_piix
  01f0-01f7 : 0000:00:01.1
    01f0-01f7 : ata_piix
  0376-0376 : 0000:00:01.1
    0376-0376 : ata_piix
  03c0-03df : vga+
  03f2-03f2 : floppy
  03f4-03f5 : floppy
  03f6-03f6 : 0000:00:01.1
    03f6-03f6 : ata_piix
  03f7-03f7 : floppy
  0510-051b : QEMU0002:00
    0510-051b : fw_cfg_io
  0600-063f : 0000:00:01.3
    0600-0603 : ACPI PM1a_EVT_BLK
    0604-0605 : ACPI PM1a_CNT_BLK
    0608-060b : ACPI PM_TMR
  0700-070f : 0000:00:01.3
    0700-0708 : piix4_smbus
0cf8-0cff : PCI conf1
0d00-ffff : PCI Bus 0000:00
  afe0-afe3 : ACPI GPE0_BLK
  c000-cfff : PCI Bus 0000:02
  d000-dfff : PCI Bus 0000:01
  e000-e03f : 0000:00:03.0
  e040-e07f : 0000:00:05.0
  e080-e09f : 0000:00:01.2
    e080-e09f : uhci_hcd
  e0a0-e0bf : 0000:00:12.0
  e0c0-e0cf : 0000:00:01.1
    e0c0-e0cf : ata_piix

Important - Si deux périphériques ont le même port, les deux périphériques seront inutilisables.

Périphériques
root@debian11:~# cat /proc/devices
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  4 ttyS
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  6 lp
  7 vcs
 10 misc
 13 input
 21 sg
 29 fb
 99 ppdev
128 ptm
136 pts
153 spi
180 usb
189 usb_device
226 drm
248 hidraw
249 aux
250 cec
251 bsg
252 rtc
253 dax
254 gpiochip

Block devices:
  2 fd
  8 sd
  9 md
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
253 mdp
254 device-mapper
259 blkext
Modules
root@debian11:~# cat /proc/modules | more
ufs 94208 0 - Live 0xffffffffc0cde000
qnx4 16384 0 - Live 0xffffffffc07a3000
hfsplus 126976 0 - Live 0xffffffffc0d2b000
hfs 73728 0 - Live 0xffffffffc0cc4000
minix 45056 0 - Live 0xffffffffc0cb8000
vfat 20480 0 - Live 0xffffffffc0cb2000
msdos 20480 0 - Live 0xffffffffc0cac000
fat 86016 2 vfat,msdos, Live 0xffffffffc0c8f000
jfs 212992 0 - Live 0xffffffffc0cf6000
xfs 1773568 0 - Live 0xffffffffc0add000
xts 16384 1 - Live 0xffffffffc0ad2000
dm_crypt 53248 1 - Live 0xffffffffc0ac4000
cbc 16384 0 - Live 0xffffffffc0abf000
aes_generic 36864 3 - Live 0xffffffffc0ab5000
libaes 16384 1 aes_generic, Live 0xffffffffc0ab0000
crypto_simd 16384 0 - Live 0xffffffffc0aab000
cryptd 24576 1 crypto_simd, Live 0xffffffffc0a9f000
glue_helper 16384 0 - Live 0xffffffffc08dd000
ecb 16384 2 - Live 0xffffffffc0883000
ecryptfs 122880 0 - Live 0xffffffffc0a80000
btrfs 1568768 0 - Live 0xffffffffc0900000
blake2b_generic 20480 0 - Live 0xffffffffc087d000
raid1 53248 0 - Live 0xffffffffc08f2000
dm_raid 45056 0 - Live 0xffffffffc08e6000
raid456 180224 1 dm_raid, Live 0xffffffffc08b0000
async_raid6_recov 24576 1 raid456, Live 0xffffffffc08a7000
async_memcpy 20480 2 raid456,async_raid6_recov, Live 0xffffffffc089f000
async_pq 20480 2 raid456,async_raid6_recov, Live 0xffffffffc0899000
async_xor 20480 3 raid456,async_raid6_recov,async_pq, Live 0xffffffffc0893000
async_tx 20480 5 raid456,async_raid6_recov,async_memcpy,async_pq,async_xor, Live 0xffffffffc088a000
md_mod 180224 3 raid1,dm_raid,raid456, Live 0xffffffffc0850000
xor 24576 2 btrfs,async_xor, Live 0xffffffffc0845000
raid6_pq 122880 4 btrfs,raid456,async_raid6_recov,async_pq, Live 0xffffffffc0822000
libcrc32c 16384 3 xfs,btrfs,raid456, Live 0xffffffffc07b3000
dm_snapshot 53248 0 - Live 0xffffffffc07b9000
dm_bufio 36864 1 dm_snapshot, Live 0xffffffffc07a9000
dm_mod 163840 10 dm_crypt,dm_raid,dm_snapshot,dm_bufio, Live 0xffffffffc07f6000
rfkill 28672 0 - Live 0xffffffffc07cb000
joydev 28672 0 - Live 0xffffffffc0725000
evdev 28672 2 - Live 0xffffffffc071d000
virtio_balloon 24576 0 - Live 0xffffffffc06f7000
sg 36864 0 - Live 0xffffffffc06cc000
serio_raw 20480 0 - Live 0xffffffffc06ba000
pcspkr 16384 0 - Live 0xffffffffc06b0000
qemu_fw_cfg 20480 0 - Live 0xffffffffc06aa000
parport_pc 40960 0 - Live 0xffffffffc0679000
ppdev 24576 0 - Live 0xffffffffc0664000
lp 20480 0 - Live 0xffffffffc066b000
parport 69632 3 parport_pc,ppdev,lp, Live 0xffffffffc0652000
fuse 167936 1 - Live 0xffffffffc0628000
--More--
[q]
Statistiques de l'utilisation des disques
root@debian11:~# cat /proc/diskstats
  11       0 sr0 77 0 4235 23 0 0 0 0 0 68 23 0 0 0 0 0 0
   8       0 sda 12242 8305 1103196 42502 11683 13369 1910368 718254 0 105044 783887 0 0 0 0 2936 23131
   8       1 sda1 11481 8305 1067918 41666 10597 13369 1910368 717761 0 103920 759427 0 0 0 0 0 0
   8       2 sda2 11 0 14 38 0 0 0 0 0 64 38 0 0 0 0 0 0
   8       5 sda5 201 0 14692 296 0 0 0 0 0 460 296 0 0 0 0 0 0
   8      16 sdb 227 0 8976 27 0 0 0 0 0 72 27 0 0 0 0 0 0
   8      32 sdc 5023 507625 4247435 13154 1528 253646 2060274 14491 0 12120 31223 0 0 0 0 141 3577
   8      33 sdc1 144 0 9972 5 0 0 0 0 0 68 5 0 0 0 0 0 0
   8      34 sdc2 138 0 9924 6 0 0 0 0 0 64 6 0 0 0 0 0 0
   8      35 sdc3 138 0 9924 6 0 0 0 0 0 64 6 0 0 0 0 0 0
   8      36 sdc4 24 0 566 43 0 0 0 0 0 124 43 0 0 0 0 0 0
   8      37 sdc5 941 127001 1035648 1742 19 0 26 1281 0 3504 3024 0 0 0 0 0 0
   8      38 sdc6 278 0 24508 243 0 0 0 0 0 352 243 0 0 0 0 0 0
   8      39 sdc7 220 8 19832 268 0 0 0 0 0 376 268 0 0 0 0 0 0
   8      40 sdc8 1539 253750 2054126 3152 41 0 48 3380 0 6968 6533 0 0 0 0 0 0
   8      41 sdc9 142 4 19720 211 0 0 0 0 0 332 211 0 0 0 0 0 0
   8      42 sdc10 807 126861 1033214 5955 734 126795 1019952 4901 0 8468 10857 0 0 0 0 0 0
   8      43 sdc11 281 1 9545 835 715 126851 1040248 4581 0 5564 5417 0 0 0 0 0 0
   8      44 sdc12 148 0 13300 287 0 0 0 0 0 368 287 0 0 0 0 0 0
 254       0 dm-0 210 0 8440 72 0 0 0 0 0 108 72 0 0 0 0 0 0
 254       1 dm-1 242 0 8440 164 0 0 0 0 0 168 164 0 0 0 0 0 0
   9       1 md1 57 0 2304 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Partitions
root@debian11:~# cat /proc/partitions
major minor  #blocks  name

  11        0     387072 sr0
   8        0   33554432 sda
   8        1   32552960 sda1
   8        2          1 sda2
   8        5     998400 sda5
   8       16   67108864 sdb
   8       32    4194304 sdc
   8       33     102400 sdc1
   8       34     102400 sdc2
   8       35     102400 sdc3
   8       36          1 sdc4
   8       37     512000 sdc5
   8       38     204800 sdc6
   8       39     307200 sdc7
   8       40     512000 sdc8
   8       41     409600 sdc9
   8       42     512000 sdc10
   8       43     512000 sdc11
   8       44     204800 sdc12
 254        0     106496 dm-0
 254        1     114688 dm-1
   9        1    1019904 md1
Espaces de pagination
root@debian11:~# cat /proc/swaps
Filename                                Type            Size            Used         Priority
/dev/sda5                               partition       998396          0            -2
Statistiques d'utilisation du processeur
root@debian11:~# cat /proc/loadavg
0.00 0.00 0.00 1/292 57813
Statistiques d'utilisation de la mémoire
root@debian11:~# cat /proc/meminfo
MemTotal:        4025596 kB
MemFree:         2604608 kB
MemAvailable:    3626000 kB
Buffers:           28244 kB
Cached:          1159028 kB
SwapCached:            0 kB
Active:           447852 kB
Inactive:         807036 kB
Active(anon):        748 kB
Inactive(anon):    68892 kB
Active(file):     447104 kB
Inactive(file):   738144 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        998396 kB
SwapFree:         998396 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:         67648 kB
Mapped:            65484 kB
Shmem:              2024 kB
KReclaimable:      82492 kB
Slab:             120008 kB
SReclaimable:      82492 kB
SUnreclaim:        37516 kB
KernelStack:        4688 kB
PageTables:         3504 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3011192 kB
Committed_AS:    1645372 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       27688 kB
VmallocChunk:          0 kB
Percpu:             2080 kB
HardwareCorrupted:     0 kB
AnonHugePages:     26624 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      114536 kB
DirectMap2M:     4079616 kB
Version du noyau
root@debian11:~# cat /proc/version
Linux version 5.10.0-13-amd64 (debian-kernel@lists.debian.org) (gcc-10 (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.106-1 (2022-03-17)

Répertoires

ide/scsi

Ce répertoire contient des répertoires dans lesquels se trouvent des informations sur la capacité, le type et la géométrie des disques.

acpi

Ce répertoire contient des informations sur la gestion de l'énérgie, les températures, les vitesses de ventilateurs, la charge des batteries.

bus

Ce répertoire contient un sous-répertoire par bus.

net

Ce répertoire contient des informations sur le réseau.

sys

Ce répertoire contient des paramètres du noyau. Certains des fichiers dans ce répertoire sont accessibles en écriture par root en temps réel. Par exemple pour éviter des attaques réseau DoS utilisant la commande ping, saisissez la commande suivante :

# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all [Entrée]

Cette commande a pour résultat d'ignorer les reqûetes ping.

2.2 - Utilisation de la Commande sysctl

Les fichiers dans le répertoire /proc/sys peuvent être administrés par la commande sysctl en temps réel.

La commande sysctl applique les règles consignés dans le fichier /etc/sysctl.conf au démarrage de la machine.

Saisissez la commande :

root@debian11:~# cat /etc/sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additional system variables.
# See sysctl.conf (5) for information.
#

#kernel.domainname = example.com

# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3

###################################################################
# Functions previously found in netbase
#

# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
#net.ipv4.conf.default.rp_filter=1
#net.ipv4.conf.all.rp_filter=1

# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
#net.ipv4.tcp_syncookies=1

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

# Uncomment the next line to enable packet forwarding for IPv6
#  Enabling this option disables Stateless Address Autoconfiguration
#  based on Router Advertisements for this host
#net.ipv6.conf.all.forwarding=1


###################################################################
# Additional settings - these settings can improve the network
# security of the host and prevent against some network attacks
# including spoofing attacks and man in the middle attacks through
# redirection. Some network environments, however, require that these
# settings are disabled so review and enable them as needed.
#
# Do not accept ICMP redirects (prevent MITM attacks)
#net.ipv4.conf.all.accept_redirects = 0
#net.ipv6.conf.all.accept_redirects = 0
# _or_
# Accept ICMP redirects only for gateways listed in our default
# gateway list (enabled by default)
# net.ipv4.conf.all.secure_redirects = 1
#
# Do not send ICMP redirects (we are not a router)
#net.ipv4.conf.all.send_redirects = 0
#
# Do not accept IP source route packets (we are not a router)
#net.ipv4.conf.all.accept_source_route = 0
#net.ipv6.conf.all.accept_source_route = 0
#
# Log Martian Packets
#net.ipv4.conf.all.log_martians = 1
#

###################################################################
# Magic system request Key
# 0=disable, 1=enable all, >1 bitmask of sysrq functions
# See https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
# for what other values do
#kernel.sysrq=438

root@debian11:~# ls -l /etc/sysctl.d/
total 4
lrwxrwxrwx 1 root root  14 Mar 20 20:55 99-sysctl.conf -> ../sysctl.conf
-rw-r--r-- 1 root root 639 Apr  6  2021 README.sysctl

Les options de la commande sysctl sont :

root@debian11:~# sysctl --help

Usage:
 sysctl [options] [variable[=value] ...]

Options:
  -a, --all            display all variables
  -A                   alias of -a
  -X                   alias of -a
      --deprecated     include deprecated parameters to listing
  -b, --binary         print value without new line
  -e, --ignore         ignore unknown variables errors
  -N, --names          print variable names without values
  -n, --values         print only values of the given variable(s)
  -p, --load[=<file>]  read values from file
  -f                   alias of -p
      --system         read values from all system directories
  -r, --pattern <expression>
                       select setting that match expression
  -q, --quiet          do not echo variable set
  -w, --write          enable writing a value to variable
  -o                   does nothing
  -x                   does nothing
  -d                   alias of -h

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see sysctl(8).

LAB#3 - Interprétation des informations dans /proc

Les informations brutes stockées dans /proc peuvent être interprétées grâce à l'utilisation des commandes dites de gestion des performances :

3.1 - La Commande free

La commande free permet de donner l’état de la mémoire totale, libre, partagée, swap et bufferisée. Saisissez donc la commande suivante :

root@debian11:~# free -m
               total        used        free      shared  buff/cache   available
Mem:            3931         147        2543           1        1240        3541
Swap:            974           0         974

Dans le cas de cet exemple, nous pouvons constater que l’affichage montre :

Les options de cette commande sont :

root@debian11:~# free --help

Usage:
 free [options]

Options:
 -b, --bytes         show output in bytes
     --kilo          show output in kilobytes
     --mega          show output in megabytes
     --giga          show output in gigabytes
     --tera          show output in terabytes
     --peta          show output in petabytes
 -k, --kibi          show output in kibibytes
 -m, --mebi          show output in mebibytes
 -g, --gibi          show output in gibibytes
     --tebi          show output in tebibytes
     --pebi          show output in pebibytes
 -h, --human         show human-readable output
     --si            use powers of 1000 not 1024
 -l, --lohi          show detailed low and high memory statistics
 -t, --total         show total for RAM + swap
 -s N, --seconds N   repeat printing every N seconds
 -c N, --count N     repeat printing N times, then exit
 -w, --wide          wide output

     --help     display this help and exit
 -V, --version  output version information and exit

For more details see free(1).

3.2 - Les Commandes uptime et w

Chacune des ces commandes indique la charge moyenne du ou des processeurs depuis 1 minute, 5 minutes et 15 minutes :

root@debian11:~# uptime
 15:51:36 up 4 days,  2:43,  1 user,  load average: 0.10, 0.03, 0.01

root@debian11:~# w
 15:51:38 up 4 days,  2:43,  1 user,  load average: 0.10, 0.03, 0.01
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
trainee  pts/0    10.0.2.1         10:54    2.00s  0.43s  0.06s sshd: trainee [priv]

Les valeurs load average ou charge moyenne indiquent le nombre moyen de processus en cours de traitement ou en attente pour la période concernée.

Par exemple si les valeurs sur un système muni d'un seul processeur étaient 3,48 4,00 3,85 ceci indiquerait que le processeur a du mal à traiter les processus mettant en moyenne :

Les options de ces commandes sont :

root@debian11:~# uptime --help

Usage:
 uptime [options]

Options:
 -p, --pretty   show uptime in pretty format
 -h, --help     display this help and exit
 -s, --since    system up since
 -V, --version  output version information and exit

For more details see uptime(1).

root@debian11:~# w --help

Usage:
 w [options]

Options:
 -h, --no-header     do not print header
 -u, --no-current    ignore current process username
 -s, --short         short format
 -f, --from          show remote hostname field
 -o, --old-style     old style output
 -i, --ip-addr       display IP address instead of hostname (if possible)

     --help     display this help and exit
 -V, --version  output version information and exit

For more details see w(1).

3.3 - La Commande iostat

La commande iostat affiche des statistiques sur l'utilisation des disques, des terminaux et des lecteurs de cartouche :

root@debian11:~# iostat
-bash: iostat: command not found
root@debian11:~# apt -y install sysstat
root@debian11:~# iostat
Linux 5.10.0-13-amd64 (debian11)        05/01/2022      _x86_64_        (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.21    0.00    0.11    0.31    0.00   99.38

Device             tps    kB_read/s    kB_wrtn/s    kB_dscd/s    kB_read    kB_wrtn    kB_dscd
dm-0              0.01         0.29         0.00         0.00       4220          0          0
dm-1              0.02         0.29         0.00         0.00       4220          0          0
md1               0.00         0.08         0.00         0.00       1152          0          0
sda               1.64        37.79        65.45         0.00     551666     955604          0
sdb               0.02         0.31         0.00         0.00       4488          0          0
sdc               0.45       145.46        70.56         0.00    2123717    1030137          0
sr0               0.01         0.15         0.00         0.00       2117          0          0

Au-dessous de la première ligne indiquant la version du noyau du système et son nom d'hôte ainsi que la date actuelle, iostat affiche une vue d'ensemble de l'utilisation CPU moyenne du système depuis le dernier démarrage. Le rapport d'utilisation du CPU inclut les pourcentages suivants :

Notez la valeur de %iowait. Dans le cas où ce pourcentage est trop élévé, ceci indique que le processeur passe son temps à attendre les entrées et les sorties de disque.

Au-dessous du rapport d'utilisation du CPU de la sortie de la commande iostat figure le rapport d'utilisation des périphériques. Ce dernier contient une ligne pour chaque périphérique disque du système et inclut les informations suivantes :

Dernièrement, pour voir les statistiques étendues des disques, utilisez la commande suivante :

root@debian11:~# iostat -d -x
Linux 5.10.0-13-amd64 (debian11)        05/01/2022      _x86_64_        (2 CPU)

Device            r/s     rkB/s   rrqm/s  %rrqm r_await rareq-sz     w/s     wkB/s   wrqm/s  %wrqm w_await wareq-sz     d/s     dkB/s   drqm/s  %drqm d_await dareq-sz     f/s f_await  aqu-sz  %util
dm-0             0.01      0.29     0.00   0.00    0.34    20.10    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00
dm-1             0.02      0.29     0.00   0.00    0.68    17.44    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00
md1              0.00      0.08     0.00   0.00    0.00    20.21    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00
sda              0.84     37.71     0.57  40.42    3.47    45.06    0.80     65.31     0.91  53.23   61.25    81.27    0.00      0.00     0.00   0.00    0.00     0.00    0.20    7.89    0.05   0.72
sdb              0.02      0.31     0.00   0.00    0.12    19.77    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00
sdc              0.34    145.15    34.70  99.02    2.62   422.80    0.10     70.41    17.34  99.40    9.48   674.17    0.00      0.00     0.00   0.00    0.00     0.00    0.01   25.37    0.00   0.08
sr0              0.01      0.14     0.00   0.00    0.30    27.50    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00

Les options de cette commande sont :

root@debian11:~# iostat --help
Usage: iostat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -s ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ]
[ { -f | +f } <directory> ] [ -j { ID | LABEL | PATH | UUID | ... } ]
[ --dec={ 0 | 1 | 2 } ] [ --human ] [ --pretty ] [ -o JSON ]
[ [ -H ] -g <group_name> ] [ -p [ <device> [,...] | ALL ] ]
[ <device> [...] | ALL ]

3.4 - La Commande hdparm

Pour surveiller la vitesse des entrées et des sorties du disque, vous pouvez utiliser la commande hdparm :

root@debian11:~# hdparm -t /dev/sdc

root@debian11:~# apt -y install hdparm

root@debian11:~# hdparm -t /dev/sdc

/dev/sdc:
 Timing buffered disk reads: 2788 MB in  3.00 seconds = 928.32 MB/sec

3.5 - La Commande vmstat

La commande vmstat affiche des statistiques sur la mémoire, la pagination et la charge ponctuelle du processeur :

root@debian11:~# vmstat 1 10
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 3229368  26228 621512    0    0    22    33   14   27  0  0 99  0  0
 0  0      0 3229360  26228 621552    0    0     0     0   34   42  0  0 100  0  0
 0  0      0 3229360  26228 621552    0    0     0     0   22   31  0  0 100  0  0
 0  0      0 3229360  26228 621552    0    0     0     0   29   43  0  0 100  0  0
 0  0      0 3229360  26228 621552    0    0     0     0   28   40  0  0 100  0  0
 0  0      0 3229360  26228 621552    0    0     0     0   29   41  0  0 100  0  0
 0  0      0 3229392  26236 621544    0    0     0    12   33   52  0  0 95  6  0
 0  0      0 3229392  26236 621552    0    0     0     0   40   50  0  0 100  0  0
 0  0      0 3229392  26236 621552    0    0     0     0   29   40  0  0 100  0  0
 0  0      0 3229392  26236 621552    0    0     0     0   36   60  0  0 100  0  0

La première ligne subdivise le champ en six catégories à savoir : processus, mémoire, swap, E/S, système et CPU sur lesquelles elle donne des statistiques. La seconde ligne identifie de manière encore plus détaillée chacun des champs, permettant ainsi de parcourir simplement et rapidement l'ensemble des données lors de la recherche de statistiques spécifiques.

Les champs relatifs aux processus sont les suivants :

Les champs relatifs à la mémoire sont les suivants :

Les champs relatifs au swap sont les suivants :

Les champs relatifs aux Entrées/Sorties (E/S) sont les suivants :

Les champs relatifs au système sont les suivants :

Les champs relatifs au CPU sont les suivants :

Les options de cette commande sont :

root@debian11:~# vmstat --help

Usage:
 vmstat [options] [delay [count]]

Options:
 -a, --active           active/inactive memory
 -f, --forks            number of forks since boot
 -m, --slabs            slabinfo
 -n, --one-header       do not redisplay header
 -s, --stats            event counter statistics
 -d, --disk             disk statistics
 -D, --disk-sum         summarize disk statistics
 -p, --partition <dev>  partition specific statistics
 -S, --unit <char>      define display unit
 -w, --wide             wide output
 -t, --timestamp        show timestamp

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see vmstat(8).

Important : Par défaut la commande vmstat affiche des informations depuis le démarrage du système.

3.6 - La Commande mpstat

La commande mpstat affiche des statistiques détaillées sur le CPU :

root@debian11:~# mpstat
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:10:45 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:10:45 PM  all    0.04    0.00    0.02    0.12    0.00    0.00    0.00    0.00    0.00   99.83

Dans le cas où vous avez plusieurs processeurs ou coeurs, vous pouvez visualiser ces mêmes informations par unité de traitement :

root@debian11:~# mpstat -P ALL
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:11:05 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:11:05 PM  all    0.04    0.00    0.02    0.12    0.00    0.00    0.00    0.00    0.00   99.83
04:11:05 PM    0    0.04    0.00    0.02    0.13    0.00    0.00    0.00    0.00    0.00   99.81
04:11:05 PM    1    0.04    0.00    0.02    0.10    0.00    0.00    0.00    0.00    0.00   99.84

Pour afficher 5 jeux de statistiques à des intervales de 2 secondes pour tous les unités de traitement, il convient d'utiliser la commande suivante :

root@debian11:~# mpstat -P ALL 2 5
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:11:24 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:11:26 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:11:26 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:11:26 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

04:11:26 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:11:28 PM  all    0.00    0.00    0.25    0.00    0.00    0.00    0.00    0.00    0.00   99.75
04:11:28 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:11:28 PM    1    0.00    0.00    0.50    0.00    0.00    0.00    0.00    0.00    0.00   99.50

04:11:28 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:11:30 PM  all    0.00    0.00    0.25    0.00    0.00    0.00    0.00    0.00    0.00   99.75
04:11:30 PM    0    0.00    0.00    0.50    0.00    0.00    0.00    0.00    0.00    0.00   99.50
04:11:30 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

04:11:30 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:11:32 PM  all    0.25    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.75
04:11:32 PM    0    0.50    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.50
04:11:32 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

04:11:32 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
04:11:34 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:11:34 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
04:11:34 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

Average:     CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
Average:     all    0.05    0.00    0.10    0.00    0.00    0.00    0.00    0.00    0.00   99.85
Average:       0    0.10    0.00    0.10    0.00    0.00    0.00    0.00    0.00    0.00   99.80
Average:       1    0.00    0.00    0.10    0.00    0.00    0.00    0.00    0.00    0.00   99.90

Les options de cette commande sont :

root@debian11:~# mpstat --help
Usage: mpstat [ options ] [ <interval> [ <count> ] ]
Options are:
[ -A ] [ -n ] [ -T ] [ -u ] [ -V ]
[ -I { SUM | CPU | SCPU | ALL } ] [ -N { <node_list> | ALL } ]
[ --dec={ 0 | 1 | 2 } ] [ -o JSON ] [ -P { <cpu_list> | ALL } ]

3.7 - La Commande sar

La commande sar (System Activity Reporter) permet de surveiller toutes les ressources du système selon l'option qui est passée en argument à la commande. Quelques options importantes sont :

Option Description
-u Pourcentage d'utilisation du CPU
-q Nombre de processus en attente
-r Utilisation de la mémoire centrale
-w Surveillance du swapping
-p Surveillance de la pagination
-b Utilisation des tampons
-d Utilisation des disques

Sous Debian 11 la commande /usr/lib/sysstat/sadc permet de collecter les informations :

root@debian8:~# ls /usr/lib/sysstat/
debian-sa1  sa1  sa2  sadc

Le script /usr/lib/sysstat/sa1 exécutent la commande sadc. Sous Debian 11, c'est le script debian-sa1 qui est appelé à la place de sa1 afin de rectifier une bogue dans ce dernier ( Bug#499461 ). Ce script, tout comme le script sa1, prend deux options :

Option Description
-t L'interval entre les collectes
-n Nombre de collectes

Le script /usr/lib/sysstat/sa2 exécutent la commande sar et consignent les informations dans un fichier au format /var/log/sysstat/sar<jj>.

Sous Debian 11, l'intervalle entre les collectes des informations est configuré par les timers de systemd au lieu des cron jobs :

root@debian11:~# cat /usr/lib/systemd/system/sysstat-collect.timer
# /lib/systemd/system/sysstat-collect.timer
# (C) 2014 Tomasz Torcz <tomek@pipebreaker.pl>
#
# sysstat-12.5.2 systemd unit file:
#        Activates activity collector every 10 minutes

[Unit]
Description=Run system activity accounting tool every 10 minutes

[Timer]
OnCalendar=*:00/10

[Install]
WantedBy=sysstat.service

La valeur de OnCalendar indique un collecte toutes les dix minutes.

Pour modifier l'intervalle entre les collectes, il faut créer un fichier override dans le répertoire /etc/systemd/system/ en utilisant la commande systemctl edit :

root@debian11:~# EDITOR=/usr/bin/vi
root@debian11:~# export EDITOR
root@debian11:~# systemctl edit sysstat-collect.timer
### Editing /etc/systemd/system/sysstat-collect.timer.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Unit]
Description=Run system activity accounting tool every 2 minutes

[Timer]
OnCalendar=
OnCalendar=*:00/2

[Install]
WantedBy=sysstat.service

### Lines below this comment will be discarded

### /lib/systemd/system/sysstat-collect.timer
# # /lib/systemd/system/sysstat-collect.timer
# # (C) 2014 Tomasz Torcz <tomek@pipebreaker.pl>
# #
# # sysstat-12.5.2 systemd unit file:
# #        Activates activity collector every 10 minutes
#
# [Unit]
# Description=Run system activity accounting tool every 10 minutes
#
# [Timer]
# OnCalendar=*:00/10
#
# [Install]
# WantedBy=sysstat.service
[Escape] [:] [x]  <<<<<<<<<<<<<<<<<<<<<<<<APPUYEZ sur le touches


root@debian11:~# cat /etc/systemd/system/sysstat-collect.timer.d/override.conf
[Unit]
Description=Run system activity accounting tool every 2 minutes

[Timer]
OnCalendar=
OnCalendar=*:00/2 

[Install]
WantedBy=sysstat.serviceroot@debian11:~# 

Important : Notez la ligne OnCalendar= qui est necessaire afin de surcharger la valeur par défaut.

Vérifiez ensuite la prise en compte de la configuration :

root@debian11:~# systemctl status sysstat-collect.timer
● sysstat-collect.timer - Run system activity accounting tool every 2 minutes
     Loaded: loaded (/lib/systemd/system/sysstat-collect.timer; disabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/sysstat-collect.timer.d
             └─override.conf
     Active: inactive (dead)
    Trigger: n/a
   Triggers: ● sysstat-collect.service
root@debian11:~# systemctl start sysstat-collect.timer
root@debian11:~# systemctl status sysstat-collect.timer
● sysstat-collect.timer - Run system activity accounting tool every 2 minutes
     Loaded: loaded (/lib/systemd/system/sysstat-collect.timer; disabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/sysstat-collect.timer.d
             └─override.conf
     Active: active (waiting) since Sat 2022-04-30 16:30:54 CEST; 2s ago
    Trigger: Sat 2022-04-30 16:32:00 CEST; 1min 2s left
   Triggers: ● sysstat-collect.service

Apr 30 16:30:54 debian11 systemd[1]: Started Run system activity accounting tool every 2 minutes. <<<<<<<<<<<<< NOTEZ "2 minutes"
Saisissez la commande suivante :

<code>
root@debian11:~# sar
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

Statistiques d'Utilisation du CPU

Visualisez maintenant les statistiques d'utilisation du CPU:

root@debian11:~# sar -u 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:33:15 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
04:33:20 PM     all      0.00      0.00      0.00      0.00      0.00    100.00
04:33:25 PM     all      0.00      0.00      0.00      0.00      0.00    100.00
04:33:30 PM     all      0.00      0.00      0.00      0.00      0.00    100.00
Average:        all      0.00      0.00      0.00      0.00      0.00    100.00

D'avantage de statistiques peuvent être obtenues en utilisant l'option ALL :

root@debian11:~# sar -u ALL 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:33:53 PM     CPU      %usr     %nice      %sys   %iowait    %steal      %irq     %soft    %guest    %gnice     %idle
04:33:58 PM     all      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00    100.00
04:34:03 PM     all      0.10      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00     99.90
04:34:08 PM     all      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00    100.00
Average:        all      0.03      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00     99.97

Pour consulter les statistiques d'un coeur spécifique, utilisez l'option -P :

root@debian11:~# sar -u -P 0 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:35:14 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
04:35:19 PM       0      0.00      0.00      0.00      0.00      0.00    100.00
04:35:24 PM       0      0.00      0.00      0.00      0.00      0.00    100.00
04:35:29 PM       0      0.00      0.00      0.00      0.00      0.00    100.00
Average:          0      0.00      0.00      0.00      0.00      0.00    100.00

root@debian11:~# sar -u -P 1 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:34:39 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
04:34:44 PM       1      0.00      0.00      0.00      0.00      0.00    100.00
04:34:49 PM       1      0.00      0.00      0.00      0.00      0.00    100.00
04:34:54 PM       1      0.00      0.00      0.00      0.00      0.00    100.00
Average:          1      0.00      0.00      0.00      0.00      0.00    100.00

Statistiques d'Utilisation de la Mémoire et du Swap

Utilisez l'option -r pour visualiser les statistiques concernant la mémoire :

root@debian11:~# sar -r 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:35:58 PM kbmemfree   kbavail kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
04:36:03 PM   2977608   3629252    115520      2.87     33556    789044   1645752     32.76    463612    428012       308
04:36:08 PM   2977664   3629308    115448      2.87     33556    789068   1645752     32.76    463612    428016       356
04:36:13 PM   2977664   3629332    115440      2.87     33564    789068   1645752     32.76    463636    428016       308
Average:      2977645   3629297    115469      2.87     33559    789060   1645752     32.76    463620    428015       324

HERE

Utilisez l'option -S pour visualiser les statistiques concernant le Swap :

root@debian11:~# sar -S 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:39:41 PM kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
04:39:46 PM    998396         0      0.00         0      0.00
04:39:51 PM    998396         0      0.00         0      0.00
04:39:56 PM    998396         0      0.00         0      0.00
Average:       998396         0      0.00         0      0.00

Statistiques des E/S

Utilisez l'option -b pour visualiser les statistiques concernant les E/S :

root@debian11:~# sar -b 5 3
Linux 5.10.0-13-amd64 (debian11)        04/30/2022      _x86_64_        (2 CPU)

04:40:19 PM       tps      rtps      wtps      dtps   bread/s   bwrtn/s   bdscd/s
04:40:24 PM      0.40      0.00      0.40      0.00      0.00     11.20      0.00
04:40:29 PM      0.00      0.00      0.00      0.00      0.00      0.00      0.00
04:40:34 PM      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         0.13      0.00      0.13      0.00      0.00      3.73      0.00

Statistiques des E/S par Disque

Utilisez l'option -d pour visualiser les statistiques concernant les E/S par disque :

root@debian11:~# sar -d 5 3
Linux 5.10.0-13-amd64 (debian11)        05/01/2022      _x86_64_        (2 CPU)

02:48:27 PM       DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
02:48:32 PM       sr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:32 PM       sda      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:32 PM       sdb      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:32 PM       sdc      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:32 PM      dm-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:32 PM      dm-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:32 PM       md1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

02:48:32 PM       DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
02:48:37 PM       sr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:37 PM       sda      1.80      0.00      7.20      0.00      4.00      0.05     26.44      0.56
02:48:37 PM       sdb      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:37 PM       sdc      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:37 PM      dm-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:37 PM      dm-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:37 PM       md1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

02:48:37 PM       DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
02:48:42 PM       sr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:42 PM       sda      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:42 PM       sdb      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:42 PM       sdc      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:42 PM      dm-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:42 PM      dm-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
02:48:42 PM       md1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00

Average:          DEV       tps     rkB/s     wkB/s     dkB/s   areq-sz    aqu-sz     await     %util
Average:          sr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:          sda      0.60      0.00      2.40      0.00      4.00      0.02     26.44      0.19
Average:          sdb      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:          sdc      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         dm-0      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:         dm-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
Average:          md1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.000

Dernièrement, vérifiez que le répertoire /var/log/sysstat/ contient un fichier saXX :

root@debian11:~# ls -l /var/log/sysstat/
total 16
-rw-r--r-- 1 root root 14284 Apr 30 16:44 sa30

Les options de la commande sar sont :

root@debian11:~# sar --help
Usage: sar [ options ] [ <interval> [ <count> ] ]
Main options and reports (report name between square brackets):
        -B      Paging statistics [A_PAGE]
        -b      I/O and transfer rate statistics [A_IO]
        -d      Block devices statistics [A_DISK]
        -F [ MOUNT ]
                Filesystems statistics [A_FS]
        -H      Hugepages utilization statistics [A_HUGE]
        -I { <int_list> | SUM | ALL }
                Interrupts statistics [A_IRQ]
        -m { <keyword> [,...] | ALL }
                Power management statistics [A_PWR_...]
                Keywords are:
                CPU     CPU instantaneous clock frequency
                FAN     Fans speed
                FREQ    CPU average clock frequency
                IN      Voltage inputs
                TEMP    Devices temperature
                USB     USB devices plugged into the system
        -n { <keyword> [,...] | ALL }
                Network statistics [A_NET_...]
                Keywords are:
                DEV     Network interfaces
                EDEV    Network interfaces (errors)
                NFS     NFS client
                NFSD    NFS server
                SOCK    Sockets (v4)
                IP      IP traffic      (v4)
                EIP     IP traffic      (v4) (errors)
                ICMP    ICMP traffic    (v4)
                EICMP   ICMP traffic    (v4) (errors)
                TCP     TCP traffic     (v4)
                ETCP    TCP traffic     (v4) (errors)
                UDP     UDP traffic     (v4)
                SOCK6   Sockets (v6)
                IP6     IP traffic      (v6)
                EIP6    IP traffic      (v6) (errors)
                ICMP6   ICMP traffic    (v6)
                EICMP6  ICMP traffic    (v6) (errors)
                UDP6    UDP traffic     (v6)
                FC      Fibre channel HBAs
                SOFT    Software-based network processing
        -q [ <keyword> [,...] | PSI | ALL ]
                System load and pressure-stall statistics
                Keywords are:
                LOAD    Queue length and load average statistics [A_QUEUE]
                CPU     Pressure-stall CPU statistics [A_PSI_CPU]
                IO      Pressure-stall I/O statistics [A_PSI_IO]
                MEM     Pressure-stall memory statistics [A_PSI_MEM]
        -r [ ALL ]
                Memory utilization statistics [A_MEMORY]
        -S      Swap space utilization statistics [A_MEMORY]
        -u [ ALL ]
                CPU utilization statistics [A_CPU]
        -v      Kernel tables statistics [A_KTABLES]
        -W      Swapping statistics [A_SWAP]
        -w      Task creation and system switching statistics [A_PCSW]
        -y      TTY devices statistics [A_SERIAL]

3.8 - La Commande collectd

collectd est une solution open sourceavec des plugins qui peuvent collecter des statistiques système pour une grande variété d'applications.

Le paquet collectd n'est pas installé par défaut sous Debian 11 :

root@debian11:~# apt install collectd

Vérifiez que le service collectd est en cours d'exécution :

root@debian11:~# systemctl status collectd
● collectd.service - Statistics collection and monitoring daemon
     Loaded: loaded (/lib/systemd/system/collectd.service; enabled; vendor preset: en>
     Active: active (running) since Sun 2022-10-09 19:31:24 CEST; 1min 31s ago
       Docs: man:collectd(1)
             man:collectd.conf(5)
             https://collectd.org
   Main PID: 2088 (collectd)
      Tasks: 12 (limit: 19155)
     Memory: 40.5M
        CPU: 269ms
     CGroup: /system.slice/collectd.service
             └─2088 /usr/sbin/collectd

Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "irq" successfully loade>
Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "load" successfully load>
Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "memory" successfully lo>
Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "processes" successfully>
Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "rrdtool" successfully l>
Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "swap" successfully load>
Oct 09 19:31:24 debian11 collectd[2088]: plugin_load: plugin "users" successfully loa>
Oct 09 19:31:24 debian11 collectd[2088]: Systemd detected, trying to signal readiness.
Oct 09 19:31:24 debian11 systemd[1]: Started Statistics collection and monitoring dae>
Oct 09 19:31:24 debian11 collectd[2088]: Initialization complete, entering read-loop.

Important - notez que collectd récolte des données toutes les 10 secondes.

Le fichier principal de configuration de collectd est /etc/collectd/collectd.conf :

root@debian11:~# more /etc/collectd/collectd.conf
# Config file for collectd(1).
#
# Some plugins need additional configuration and are disabled by default.
# Please read collectd.conf(5) for details.
#
# You should also read /usr/share/doc/collectd-core/README.Debian.plugins
# before enabling any more plugins.

##############################################################################
# Global                                                                     #
#----------------------------------------------------------------------------#
# Global settings for the daemon.                                            #
##############################################################################

#Hostname "localhost"
FQDNLookup true
#BaseDir "/var/lib/collectd"
#PluginDir "/usr/lib/collectd"
#TypesDB "/usr/share/collectd/types.db" "/etc/collectd/my_types.db"

#----------------------------------------------------------------------------#
# When enabled, plugins are loaded automatically with the default options    #
# when an appropriate <Plugin ...> block is encountered.                     #
# Disabled by default.                                                       #
#----------------------------------------------------------------------------#
#AutoLoadPlugin false

#----------------------------------------------------------------------------#
# When enabled, internal statistics are collected, using "collectd" as the   #
# plugin name.                                                               #
# Disabled by default.                                                       #
#----------------------------------------------------------------------------#
#CollectInternalStats false

#----------------------------------------------------------------------------#
# Interval at which to query values. This may be overwritten on a per-plugin #
# base by using the 'Interval' option of the LoadPlugin block:               #
#   <LoadPlugin foo>                                                         #
#       Interval 60                                                          #
#   </LoadPlugin>                                                            #
#----------------------------------------------------------------------------#
#Interval 10

#MaxReadInterval 86400
#Timeout         2
#ReadThreads     5
#WriteThreads    5

# Limit the size of the write queue. Default is no limit. Setting up a limit
# is recommended for servers handling a high volume of traffic.
#WriteQueueLimitHigh 1000000
#WriteQueueLimitLow   800000

##############################################################################
# Logging                                                                    #
#----------------------------------------------------------------------------#
# Plugins which provide logging functions should be loaded first, so log     #
# messages generated when loading or configuring other plugins can be        #
--More--(8%)

D'autres fichiers de configuration sont présents dans le répertoire /etc/collectd/collectd.conf.d :

root@debian11:~# tail /etc/collectd/collectd.conf

#<Plugin zookeeper>
#       Host "localhost"
#       Port "2181"
#</Plugin>

<Include "/etc/collectd/collectd.conf.d">
        Filter "*.conf"
</Include>
root@debian11:~# ls -l /etc/collectd/collectd.conf.d/
total 8
-rw-r--r-- 1 root root 656 Jun  1  2021 filters.conf
-rw-r--r-- 1 root root 836 Jun  1  2021 thresholds.conf
root@debian11:~# more /etc/collectd/collectd.conf.d/filters.conf 
# Filter configuration for collectd(1).
#
# See the section "FILTER CONFIGURATION" in collectd.conf(5) for details.

#PreCacheChain "PreCache"
#PostCacheChain "PostCache"

#LoadPlugin match_empty_counter
#LoadPlugin match_hashed
#LoadPlugin match_regex
#LoadPlugin match_timediff
#LoadPlugin match_value

#LoadPlugin target_notification
#LoadPlugin target_replace
#LoadPlugin target_scale
#LoadPlugin target_set
#LoadPlugin target_v5upgrade

#<Chain "PreCache">
#       <Rule "no_fqdn">
#               <Match "regex">
#                       Host "^[^\.]*$"
#                       Invert false
#               </Match>
#               Target "stop"
#       </Rule>
#</Chain>

# Default behavior:
#<Chain "PostCache">
#       Target "write"
#</Chain>

L'organisation de collectd se repose sur l'utilisation de plugins. Pour activer un plugin, il suffit de décommenter les lignes appropriées dans le fichier /etc/collectd/collectd.conf.

Décommentez donc les deux lignes suivantes :

Ensuite re-démarrez le service collectd :

root@debian11:~# vi /etc/collectd/collectd.conf
root@debian11:~# systemctl restart collectd
root@debian11:~# systemctl status collectd
● collectd.service - Statistics collection and monitoring daemon
     Loaded: loaded (/lib/systemd/system/collectd.service; enabled; vendor preset: en>
     Active: active (running) since Sun 2022-10-09 19:40:35 CEST; 12s ago
       Docs: man:collectd(1)
             man:collectd.conf(5)
             https://collectd.org
    Process: 10521 ExecStartPre=/usr/sbin/collectd -t (code=exited, status=0/SUCCESS)
   Main PID: 10522 (collectd)
      Tasks: 12 (limit: 19155)
     Memory: 6.5M
        CPU: 52ms
     CGroup: /system.slice/collectd.service
             └─10522 /usr/sbin/collectd

Oct 09 19:40:35 debian11 collectd[10522]: plugin_load: plugin "memory" successfully l>
Oct 09 19:40:35 debian11 collectd[10522]: plugin_load: plugin "processes" successfull>
Oct 09 19:40:35 debian11 collectd[10522]: plugin_load: plugin "rrdtool" successfully >
Oct 09 19:40:35 debian11 collectd[10522]: plugin_load: plugin "swap" successfully loa>
Oct 09 19:40:35 debian11 collectd[10522]: plugin_load: plugin "thermal" successfully >
Oct 09 19:40:35 debian11 collectd[10522]: plugin_load: plugin "users" successfully lo>
Oct 09 19:40:35 debian11 collectd[10522]: Systemd detected, trying to signal readines>
Oct 09 19:40:35 debian11 collectd[10522]: cpufreq plugin: Found 0 CPUs
Oct 09 19:40:35 debian11 systemd[1]: Started Statistics collection and monitoring dae>
root@debian11:~# 

La consultation des données collectées par collectd peut se faire à l'aide du logiciel kcollectd :

Dernièrement, les options de cette commande sont :

root@debian11:~# collectd --help
collectd: invalid option -- '-'
Usage: collectd [OPTIONS]

Available options:
  General:
    -C <file>       Configuration file.
                    Default: /etc/collectd/collectd.conf
    -t              Test config and exit.
    -T              Test plugin read and exit.
    -P <file>       PID-file.
                    Default: /var/run/collectd.pid
    -f              Don't fork to the background.
    -B              Don't create the BaseDir
    -h              Display help (this message)

Builtin defaults:
  Config file       /etc/collectd/collectd.conf
  PID file          /var/run/collectd.pid
  Plugin directory  /usr/lib/collectd
  Data directory    /var/lib/collectd

collectd 5.12.0.git, http://collectd.org/
by Florian octo Forster <octo@collectd.org>
for contributions see `AUTHORS'

Modules usb

L'USB (Universal Serial Bus) est un bus de données qui peut offrir des taux de transfert jusqu'à 480Mb/s sous la version 2.0 et jusqu'à 4.8 Gb/s sous la version 3.0. Les modules nécessaires pour les contrôleurs USB sont :

Version USB Module Nom Complet
1.0\1.1 UHCI Universal Controller Host Interface
OHCI Open Controller Host Interface
2.0 EHCI Enhanced Host Controller Interface
3.0 XHCI Extensible Host Controller Interface

Le tableau suivant liste les modules courrament chargés en fonction du périphérique utilisé :

Module Type de Périphérique
usb_storage Supports de masse
usbhid Periphériques HID (Human Interface Device)
snd-usb-audio Cartes son usb
usbvidéo Cartes vidéo et d'acquisition
irda-usb Périphériques infrarouges
usbnet Cartes réseaux usb

Les modules peuvent être chargés par un des moyens suivants :

udev

Depuis le noyau Linux 2.6 Linux est capable de détecter des périphériques branchés à chaud. Cette technologie s'appelle le hotplugging. Le hotplugging est obtenu grâce à l'utilisation de trois composants :

Les rôles de chaque composant sont les suivants :

Lors de démarrage de Linux, Udev joue un rôle important :

Udev repose sur le filesystem sysfs monté sur /sys qui permet de rendre les périphériques visibles à Udev dans l'User Space. Par exemple, lors du branchement d'une clé USB, Udev crée /dev/sdx1 automatiquement et utilise les informations contenues dans le fichier /lib/modules/`uname -r`/modules.alias pour trouver le pilote nécessaire :

Le fichier de configuration principal d'Udev est /etc/udev/udev.conf :

root@debian11:~# cat /etc/udev/udev.conf
# see udev.conf(5) for details
#
# udevd is also started in the initrd.  When this file is modified you might
# also want to rebuild the initrd, so that it will include the modified configuration.

#udev_log=info
#children_max=
#exec_delay=
#event_timeout=180
#timeout_signal=SIGKILL
#resolve_names=early

Les fichiers de règles se trouvent dans /lib/udev/rules.d/ :

root@debian11:~# ls /lib/udev/rules.d/
39-usbmuxd.rules                  70-joystick.rules                    77-mm-usb-device-blacklist.rules
40-usb_modeswitch.rules           70-mouse.rules                       77-mm-usb-serial-adapters-greylist.rules
50-firmware.rules                 70-power-switch.rules                77-mm-x22x-port-types.rules
50-udev-default.rules             70-printers.rules                    77-mm-zte-port-types.rules
55-dm.rules                       70-touchpad.rules                    78-sound-card.rules
56-lvm.rules                      70-uaccess.rules                     80-debian-compat.rules
60-autosuspend.rules              71-ipp-usb.rules                     80-drivers.rules
60-block.rules                    71-seat.rules                        80-ifupdown.rules
60-cdrom_id.rules                 73-seat-late.rules                   80-libinput-device-groups.rules
60-drm.rules                      73-special-net-names.rules           80-mm-candidate.rules
60-evdev.rules                    75-net-description.rules             80-net-setup-link.rules
60-fido-id.rules                  75-probe_mtd.rules                   80-udisks2.rules
60-input-id.rules                 77-mm-broadmobi-port-types.rules     84-nm-drivers.rules
60-libgphoto2-6.rules             77-mm-cinterion-port-types.rules     85-hdparm.rules
60-libopenni2-0.rules             77-mm-dell-port-types.rules          85-hwclock.rules
60-libsane1.rules                 77-mm-dlink-port-types.rules         85-nm-unmanaged.rules
60-persistent-alsa.rules          77-mm-ericsson-mbm.rules             90-alsa-restore.rules
60-persistent-input.rules         77-mm-fibocom-port-types.rules       90-console-setup.rules
60-persistent-storage-dm.rules    77-mm-foxconn-port-types.rules       90-libinput-fuzz-override.rules
60-persistent-storage.rules       77-mm-haier-port-types.rules         90-nm-thunderbolt.rules
60-persistent-storage-tape.rules  77-mm-huawei-net-port-types.rules    90-pipewire-alsa.rules
60-persistent-v4l.rules           77-mm-longcheer-port-types.rules     90-pulseaudio.rules
60-qemu-guest-agent.rules         77-mm-mtk-port-types.rules           95-cd-devices.rules
60-sensor.rules                   77-mm-nokia-port-types.rules         95-dm-notify.rules
60-serial.rules                   77-mm-pcmcia-device-blacklist.rules  95-upower-csr.rules
64-btrfs-dm.rules                 77-mm-qdl-device-blacklist.rules     95-upower-hidpp.rules
64-btrfs.rules                    77-mm-quectel-port-types.rules       95-upower-hid.rules
64-xorg-xkb.rules                 77-mm-sierra.rules                   95-upower-wup.rules
65-libwacom.rules                 77-mm-simtech-port-types.rules       96-e2scrub.rules
69-cd-sensors.rules               77-mm-telit-port-types.rules         99-libsane1.rules
69-lvm-metad.rules                77-mm-tplink-port-types.rules        99-systemd.rules
69-wacom.rules                    77-mm-ublox-port-types.rules

Important : Il vous est possible d'ajouter des règles si besoin est. Dans ce cas, créez un fichier 99-local.rules est éditez-le au lieu d'éditer les fichiers existants.

Comme indique le nom de chaque fichier, le contenu est composé de règles à l'attention d'udev. Le fichier des règles par défaut est le 50-udev-default.rules :

root@debian11:~# cat /lib/udev/rules.d/50-udev-default.rules | more
# do not edit this file, it will be overwritten on update

# run a command on remove events
ACTION=="remove", ENV{REMOVE_CMD}!="", RUN+="$env{REMOVE_CMD}"
ACTION=="remove", GOTO="default_end"

SUBSYSTEM=="virtio-ports", KERNEL=="vport*", ATTR{name}=="?*", SYMLINK+="virtio-ports/$attr{name}"

# select "system RTC" or just use the first one
SUBSYSTEM=="rtc", ATTR{hctosys}=="1", SYMLINK+="rtc"
SUBSYSTEM=="rtc", KERNEL=="rtc0", SYMLINK+="rtc", OPTIONS+="link_priority=-100"

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id", IMPORT{builtin}="hwdb --subsystem=usb", GOTO="default_hwdb_i
mported"
ENV{MODALIAS}!="", IMPORT{builtin}="hwdb --subsystem=$env{SUBSYSTEM}"
LABEL="default_hwdb_imported"

ACTION!="add", GOTO="default_end"

SUBSYSTEM=="tty", KERNEL=="ptmx", GROUP="tty", MODE="0666"
SUBSYSTEM=="tty", KERNEL=="tty", GROUP="tty", MODE="0666"
SUBSYSTEM=="tty", KERNEL=="tty[0-9]*", GROUP="tty", MODE="0620"
SUBSYSTEM=="tty", KERNEL=="sclp_line[0-9]*", GROUP="tty", MODE="0620"
SUBSYSTEM=="tty", KERNEL=="ttysclp[0-9]*", GROUP="tty", MODE="0620"
SUBSYSTEM=="tty", KERNEL=="3270/tty[0-9]*", GROUP="tty", MODE="0620"
SUBSYSTEM=="vc", KERNEL=="vcs*|vcsa*", GROUP="tty"
KERNEL=="tty[A-Z]*[0-9]|ttymxc[0-9]*|pppox[0-9]*|ircomm[0-9]*|noz[0-9]*|rfcomm[0-9]*", GROUP="dialout"

SUBSYSTEM=="mem", KERNEL=="mem|kmem|port", GROUP="kmem", MODE="0640"

SUBSYSTEM=="input", GROUP="input"
SUBSYSTEM=="input", KERNEL=="js[0-9]*", MODE="0664"

SUBSYSTEM=="video4linux", GROUP="video"
SUBSYSTEM=="graphics", GROUP="video"
SUBSYSTEM=="drm", KERNEL!="renderD*", GROUP="video"
SUBSYSTEM=="dvb", GROUP="video"
SUBSYSTEM=="media", GROUP="video"
SUBSYSTEM=="cec", GROUP="video"

SUBSYSTEM=="drm", KERNEL=="renderD*", GROUP="render", MODE="0660"
SUBSYSTEM=="kfd", GROUP="render", MODE="0660"

# When using static_node= with non-default permissions, also update
# tmpfiles.d/static-nodes-permissions.conf.in to keep permissions synchronized.

SUBSYSTEM=="sound", GROUP="audio", \
  OPTIONS+="static_node=snd/seq", OPTIONS+="static_node=snd/timer"

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0664"
--More--
[q]

Chaque règle prend la forme suivante :

KEY, [KEY, …] NAME [, SYMLINK]

Chaque KEY est un champ au format type=valeur qui doit correspondre à un périphérique unique. La valeur de type peut prendre plusieurs formes :

Type Description Exemples
BUS Type de bus usb, scsi, ide
KERNEL Le nom par défault du périphérique donné par le noyau hda, ttyUSB0, lp0
SUBSYSTEM Le nom noyau du sous-système, généralement identique à la valeur du BUS usb, scsi
DRIVER Le nom du pilote qui contrôle le périphérique usb-storage
ID Le numéro du périphérique sur son bus PCI bus id, USB id
PLACE Ne concerne que les périphériques USB et donne la position topologique du périphérique sur son bus S/O
SYSFS{filename} Le nom du fichier dans /sys pour le périphérique. Ce fichier contient le fabricant, le label, le numéro de série et UUID du périphérique. La vérification de jusqu'à 5 fichiers est possible par règle S/O
PROGRAM Ceci permet à Udev d'appeler un programme externe pour nommer un périphérique S/O
RESULT Valeur à comparer au résultat de PROGRAM S/O

NAME et SYMLINK sont utilisées pour stipuler ce que Udev doit faire avec le périphérique :

Type Description Exemples
NAME Le nome du nœud dans /dev S/O
SYMLINK Le ou les lien(s) symbolique(s) qui pointe(nt) vers le NAME S/O

La commande udevadm

Pour obtenir de l'information sur un périphérique il convient d'utiliser la commande udevadm :

root@debian11:~# udevadm info --query=all -n /dev/sdc
P: /devices/pci0000:00/0000:00:05.0/virtio1/host2/target2:0:0/2:0:0:1/block/sdc
N: sdc
L: 0
S: disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi1
S: disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1
E: DEVPATH=/devices/pci0000:00/0000:00:05.0/virtio1/host2/target2:0:0/2:0:0:1/block/sdc
E: DEVNAME=/dev/sdc
E: DEVTYPE=disk
E: MAJOR=8
E: MINOR=32
E: SUBSYSTEM=block
E: USEC_INITIALIZED=1712598
E: ID_SCSI=1
E: ID_VENDOR=QEMU
E: ID_VENDOR_ENC=QEMU\x20\x20\x20\x20
E: ID_MODEL=QEMU_HARDDISK
E: ID_MODEL_ENC=QEMU\x20HARDDISK\x20\x20\x20
E: ID_REVISION=2.5+
E: ID_TYPE=disk
E: ID_SERIAL=0QEMU_QEMU_HARDDISK_drive-scsi1
E: ID_SERIAL_SHORT=drive-scsi1
E: ID_BUS=scsi
E: ID_PATH=pci-0000:00:05.0-scsi-0:0:0:1
E: ID_PATH_TAG=pci-0000_00_05_0-scsi-0_0_0_1
E: ID_PART_TABLE_UUID=304308a3
E: ID_PART_TABLE_TYPE=dos
E: DEVLINKS=/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi1 /dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:1
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

Les options de la commande udevadm sont :

root@debian11:~# udevadm --help
udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]

Send control commands or test the device manager.

Commands:
  info          Query sysfs or the udev database
  trigger       Request events from the kernel
  settle        Wait for pending udev events
  control       Control the udev daemon
  monitor       Listen to kernel and udev events
  test          Test an event run
  test-builtin  Test a built-in command

See the udevadm(8) man page for details.

root@debian11:~# udevadm info --help
udevadm info [OPTIONS] [DEVPATH|FILE]

Query sysfs or the udev database.

  -h --help                   Print this message
  -V --version                Print version of the program
  -q --query=TYPE             Query device information:
       name                     Name of device node
       symlink                  Pointing to node
       path                     sysfs device path
       property                 The device properties
       all                      All values
  -p --path=SYSPATH           sysfs device path used for query or attribute walk
  -n --name=NAME              Node or symlink name used for query or attribute walk
  -r --root                   Prepend dev directory to path names
  -a --attribute-walk         Print all key matches walking along the chain
                              of parent devices
  -d --device-id-of-file=FILE Print major:minor of device containing this file
  -x --export                 Export key/value pairs
  -P --export-prefix          Export the key name with a prefix
  -e --export-db              Export the content of the udev database
  -c --cleanup-db             Clean up the udev database
  -w --wait-for-initialization[=SECONDS]
                              Wait for device to be initialized

Système de fichiers /sys

Le système de fichiers virtuel /sys a été introduit avec le noyau Linux 2.6. Son rôle est de décrire le matériel pour udev.

Saisissez la commande suivante :

root@debian11:~# ls -l /sys
total 0
drwxr-xr-x   2 root root 0 Apr 30 16:32 block
drwxr-xr-x  33 root root 0 Apr 30 16:21 bus
drwxr-xr-x  51 root root 0 Apr 30 16:21 class
drwxr-xr-x   4 root root 0 Apr 30 16:21 dev
drwxr-xr-x  14 root root 0 Apr 26 13:08 devices
drwxr-xr-x   6 root root 0 Apr 30 16:21 firmware
drwxr-xr-x  10 root root 0 Apr 26 13:08 fs
drwxr-xr-x   2 root root 0 Apr 30 16:50 hypervisor
drwxr-xr-x  15 root root 0 Apr 26 13:08 kernel
drwxr-xr-x 151 root root 0 Apr 30 16:21 module
drwxr-xr-x   3 root root 0 Apr 30 16:50 power

Chaque répertoire contient des informations :

Pour illustrer ceci, saisissez la commande suivante :

root@debian11:~# cat /sys/block/sdc/sdc1/size
204800

Ce chiffre correspond aux nombre de secteurs.

LAB #4 - Processus et Fichiers Ouverts

Présentation

Un processus est un fichier binaire ( binary file ) qui est chargé en mémoire centrale. Une fois chargé la mémoire exécute le programme en langage machine. Quand le programme est chargé, il a besoin du système d’exploitation qui lui fournit des informations pour qu’il puisse s’exécuter correctement. Ces informations sont appelées des données d’identification.

L’ensemble des données d’identification est appelé l’environnement de processus :

Ces informations sont stockés dans le répertoire /proc. Le répertoire /proc contient des fichiers et des répertoires virtuels. Le contenu de ces fichiers est créé dynamiquement lors de la consultation. Seul root peut consulter la totalité des informations dans le répertoire /proc.

Saisissez la commande suivante :

root@debian11:~# cd /proc; ls -d [0-9]*
1    128    213    21985  22049  22095  22976  23037  28304  30129  368  453  59
10   12807  21895  21989  22051  22096  22991  24     28305  30151  374  458  6
11   13     21900  21995  22052  22119  22992  244    28309  30185  375  50   60
119  15     21901  22005  22060  22122  22994  25     28310  30202  377  51   69
12   16     21916  22007  22063  22131  22995  258    29     30223  380  52   72
120  17     21917  22010  22065  22136  22996  27     29208  30227  381  53   73
121  175    21920  22024  22066  22146  23     27914  29263  31     4    536  8
122  176    21921  22027  22076  22151  23008  27915  29345  32     400  54   9
123  18     21928  22036  22084  22947  23013  28     29614  353    422  55   95
125  2      21970  22040  22093  22970  23015  28194  3      364    433  57
127  20     21980  22045  22094  22974  23033  28295  30     366    452  58

Chaque répertoire fait référence à un PID d'un processus. Les données de l’environnement de processus y sont présentes, par exemple :

root@debian11:/proc# cd 1 ; ls -l
total 0
-r--r--r--  1 root root 0 Jun  2 11:06 arch_status
dr-xr-xr-x  2 root root 0 May 10 14:37 attr
-rw-r--r--  1 root root 0 Jun  2 11:06 autogroup
-r--------  1 root root 0 Jun  2 11:06 auxv
-r--r--r--  1 root root 0 May 10 14:37 cgroup
--w-------  1 root root 0 Jun  2 11:06 clear_refs
-r--r--r--  1 root root 0 May 10 14:37 cmdline
-rw-r--r--  1 root root 0 May 10 14:37 comm
-rw-r--r--  1 root root 0 May 10 14:37 coredump_filter
-r--r--r--  1 root root 0 Jun  2 11:06 cpu_resctrl_groups
-r--r--r--  1 root root 0 Jun  2 11:06 cpuset
lrwxrwxrwx  1 root root 0 Jun  2 09:55 cwd -> /
-r--------  1 root root 0 May 10 14:37 environ
lrwxrwxrwx  1 root root 0 May 10 14:37 exe -> /usr/lib/systemd/systemd
dr-x------  2 root root 0 May 10 14:37 fd
dr-x------  2 root root 0 Jun  2 09:55 fdinfo
-rw-r--r--  1 root root 0 May 10 14:37 gid_map
-r--------  1 root root 0 Jun  2 11:06 io
-r--r--r--  1 root root 0 May 10 14:37 limits
-rw-r--r--  1 root root 0 May 10 14:37 loginuid
dr-x------  2 root root 0 Jun  2 11:06 map_files
-r--r--r--  1 root root 0 May 10 14:37 maps
-rw-------  1 root root 0 Jun  2 11:06 mem
-r--r--r--  1 root root 0 May 10 14:37 mountinfo
-r--r--r--  1 root root 0 Jun  2 11:06 mounts
-r--------  1 root root 0 Jun  2 11:06 mountstats
dr-xr-xr-x 54 root root 0 May 10 14:37 net
dr-x--x--x  2 root root 0 Jun  2 11:06 ns
-r--r--r--  1 root root 0 Jun  2 11:06 numa_maps
-rw-r--r--  1 root root 0 Jun  2 11:06 oom_adj
-r--r--r--  1 root root 0 Jun  2 11:06 oom_score
-rw-r--r--  1 root root 0 May 10 14:37 oom_score_adj
-r--------  1 root root 0 Jun  2 11:06 pagemap
-r--------  1 root root 0 Jun  2 11:06 patch_state
-r--------  1 root root 0 Jun  2 11:06 personality
-rw-r--r--  1 root root 0 Jun  2 11:06 projid_map
lrwxrwxrwx  1 root root 0 May 10 14:37 root -> /
-rw-r--r--  1 root root 0 May 10 14:37 sched
-r--r--r--  1 root root 0 Jun  2 11:06 schedstat
-r--r--r--  1 root root 0 May 10 14:37 sessionid
-rw-r--r--  1 root root 0 May 10 14:37 setgroups
-r--r--r--  1 root root 0 Jun  2 11:06 smaps
-r--r--r--  1 root root 0 Jun  2 11:06 smaps_rollup
-r--------  1 root root 0 Jun  2 11:06 stack
-r--r--r--  1 root root 0 Jun  2 09:55 stat
-r--r--r--  1 root root 0 Jun  2 11:06 statm
-r--r--r--  1 root root 0 May 10 14:37 status
-r--------  1 root root 0 Jun  2 11:06 syscall
dr-xr-xr-x  3 root root 0 May 10 14:37 task
-rw-r--r--  1 root root 0 Jun  2 11:06 timens_offsets
-r--r--r--  1 root root 0 Jun  2 11:06 timers
-rw-rw-rw-  1 root root 0 Jun  2 11:06 timerslack_ns
-rw-r--r--  1 root root 0 May 10 14:37 uid_map
-r--r--r--  1 root root 0 Jun  2 11:06 wchan

Important - Vous n'avez pas besoin de consulter le contenu des fichiers et des répertoires. Il convient tout simplement de savoir que ces données existent.

Les Types de Processus

Il existe trois types de processus :

Un processus peut être dans un de neuf états ou process states :

4.1 - La Commande ps

Cette commande affiche les processus de l’utilisateur attaché au terminal :

root@debian11:/proc/1# cd ~

root@debian11:~# ps
    PID TTY          TIME CMD
  28309 pts/1    00:00:00 su
  28310 pts/1    00:00:00 bash
  30237 pts/1    00:00:00 ps

root@debian11:~# ps --forest
    PID TTY          TIME CMD
  28309 pts/1    00:00:00 su
  28310 pts/1    00:00:00  \_ bash
  30272 pts/1    00:00:00      \_ ps

Pour plus de détails, il convient d'utiliser l'option -l :

root@debian11:~# ps -l
F S   UID     PID    PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0   28309   28305  0  80   0 -  2529 -      pts/1    00:00:00 su
4 S     0   28310   28309  0  80   0 -  2137 -      pts/1    00:00:00 bash
4 R     0   30238   28310  0  80   0 -  2405 -      pts/1    00:00:00 ps

On note dans cette sortie :

F Drapeaux du processus. La valeur 4 indique que le processus utilise les privilèges de root
S État du processus S (sleeping), R (In run queue), Z (zombie), N (low priority), D (uninterruptible sleep), T (Traced)
UID Numéro de l’Utilisateur
PID Numéro Unique de Processus
PPID PID du processus parent
C Facteur de priorité du processus
PRI Priorité du processus
NI La valeur de nice
ADDR Adresse mémoire du processus
SZ Utilisation de la mémoire virtuelle
WCHAN Nom de la fonction du noyau dans laquelle le processus est endormi
TTY Nom du terminal depuis lequel le processus a été lancé
TIME Durée d'exécution du processus
CMD Commande exécutée

Pour visualiser la table des processus, utilisez la commande ps avec les options l et x - la commande affiche tous les processus avec un affichage long :

root@debian11:~# ps lx | more
F   UID     PID    PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
4     0       1       0  20   0 165192 10516 -      Ss   ?          0:14 /sbin/init
1     0       2       0  20   0      0     0 -      S    ?          0:00 [kthreadd]
1     0       3       2   0 -20      0     0 -      I<   ?          0:00 [rcu_gp]
1     0       4       2   0 -20      0     0 -      I<   ?          0:00 [rcu_par_gp]
1     0       6       2   0 -20      0     0 -      I<   ?          0:00 [kworker/0:0H-eve
nts_highpri]
1     0       8       2   0 -20      0     0 -      I<   ?          0:00 [mm_percpu_wq]
1     0       9       2  20   0      0     0 -      S    ?          0:00 [rcu_tasks_rude_]
1     0      10       2  20   0      0     0 -      S    ?          0:00 [rcu_tasks_trace]
1     0      11       2  20   0      0     0 -      S    ?          0:00 [ksoftirqd/0]
1     0      12       2  20   0      0     0 -      I    ?          0:08 [rcu_sched]
1     0      13       2 -100  -      0     0 -      S    ?          0:12 [migration/0]
1     0      15       2  20   0      0     0 -      S    ?          0:00 [cpuhp/0]
1     0      16       2  20   0      0     0 -      S    ?          0:00 [cpuhp/1]
1     0      17       2 -100  -      0     0 -      S    ?          0:12 [migration/1]
1     0      18       2  20   0      0     0 -      S    ?          0:00 [ksoftirqd/1]
1     0      20       2   0 -20      0     0 -      I<   ?          0:00 [kworker/1:0H-eve
nts_highpri]
5     0      23       2  20   0      0     0 -      S    ?          0:00 [kdevtmpfs]
1     0      24       2   0 -20      0     0 -      I<   ?          0:00 [netns]
1     0      25       2  20   0      0     0 -      S    ?          0:00 [kauditd]
1     0      27       2  20   0      0     0 -      S    ?          0:00 [khungtaskd]
--More--

On note dans cette sortie certaines informations supplémentaires :

VSZ La même chose que SZ dans l'exemple ci-dessus
RSS La mémoire utilisée en kilobytes par le processus
STAT La même chose que S dans l'exemple ci-dessus

Avec des options a,u et x la commande affiche le résultat suivant :

root@debian11:~# ps aux | more
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.2 165192 10516 ?        Ss   May10   0:14 /sbin/init
root           2  0.0  0.0      0     0 ?        S    May10   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   May10   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   May10   0:00 [rcu_par_gp]
root           6  0.0  0.0      0     0 ?        I<   May10   0:00 [kworker/0:0H-events_hi
ghpri]
root           8  0.0  0.0      0     0 ?        I<   May10   0:00 [mm_percpu_wq]
root           9  0.0  0.0      0     0 ?        S    May10   0:00 [rcu_tasks_rude_]
root          10  0.0  0.0      0     0 ?        S    May10   0:00 [rcu_tasks_trace]
root          11  0.0  0.0      0     0 ?        S    May10   0:00 [ksoftirqd/0]
root          12  0.0  0.0      0     0 ?        I    May10   0:08 [rcu_sched]
root          13  0.0  0.0      0     0 ?        S    May10   0:12 [migration/0]
root          15  0.0  0.0      0     0 ?        S    May10   0:00 [cpuhp/0]
root          16  0.0  0.0      0     0 ?        S    May10   0:00 [cpuhp/1]
root          17  0.0  0.0      0     0 ?        S    May10   0:12 [migration/1]
root          18  0.0  0.0      0     0 ?        S    May10   0:00 [ksoftirqd/1]
root          20  0.0  0.0      0     0 ?        I<   May10   0:00 [kworker/1:0H-events_hi
ghpri]
root          23  0.0  0.0      0     0 ?        S    May10   0:00 [kdevtmpfs]
root          24  0.0  0.0      0     0 ?        I<   May10   0:00 [netns]
root          25  0.0  0.0      0     0 ?        S    May10   0:00 [kauditd]
root          27  0.0  0.0      0     0 ?        S    May10   0:00 [khungtaskd]
--More--

On note dans cette sortie certaines informations supplémentaires :

USER L'utilisateur du processus
%CPU Ressources du microprocesseur utilisées par le processus
%MEM Ressources en mémoire vive utilisées par le processus

Les options de cette commande sont :

root@debian11:~# ps --help all

Usage:
 ps [options]

Basic options:
 -A, -e               all processes
 -a                   all with tty, except session leaders
  a                   all with tty, including other users
 -d                   all except session leaders
 -N, --deselect       negate selection
  r                   only running processes
  T                   all processes on this terminal
  x                   processes without controlling ttys

Selection by list:
 -C <command>         command name
 -G, --Group <GID>    real group id or name
 -g, --group <group>  session or effective group name
 -p, p, --pid <PID>   process id
        --ppid <PID>  parent process id
 -q, q, --quick-pid <PID>
                      process id (quick mode)
 -s, --sid <session>  session id
 -t, t, --tty <tty>   terminal
 -u, U, --user <UID>  effective user id or name
 -U, --User <UID>     real user id or name

  The selection options take as their argument either:
    a comma-separated list e.g. '-u root,nobody' or
    a blank-separated list e.g. '-p 123 4567'

Output formats:
 -F                   extra full
 -f                   full-format, including command lines
  f, --forest         ascii art process tree
 -H                   show process hierarchy
 -j                   jobs format
  j                   BSD job control format
 -l                   long format
  l                   BSD long format
 -M, Z                add security data (for SELinux)
 -O <format>          preloaded with default columns
  O <format>          as -O, with BSD personality
 -o, o, --format <format>
                      user-defined format
  s                   signal format
  u                   user-oriented format
  v                   virtual memory format
  X                   register format
 -y                   do not show flags, show rss vs. addr (used with -l)
     --context        display security context (for SELinux)
     --headers        repeat header lines, one per page
     --no-headers     do not print header at all
     --cols, --columns, --width <num>
                      set screen width
     --rows, --lines <num>
                      set screen height

Show threads:
  H                   as if they were processes
 -L                   possibly with LWP and NLWP columns
 -m, m                after processes
 -T                   possibly with SPID column

Miscellaneous options:
 -c                   show scheduling class with -l option
  c                   show true command name
  e                   show the environment after command
  k,    --sort        specify sort order as: [+|-]key[,[+|-]key[,...]]
  L                   show format specifiers
  n                   display numeric uid and wchan
  S,    --cumulative  include some dead child process data
 -y                   do not show flags, show rss (only with -l)
 -V, V, --version     display version information and exit
 -w, w                unlimited output width

        --help <simple|list|output|threads|misc|all>
                      display help and exit

For more details see ps(1).

4.2 - La Commande pstree

Cette commande affiche les processus en forme d'arborescence, démontrant ainsi les processus parents en enfants :

root@debian11:~# pstree
systemd─┬─ModemManager───2*[{ModemManager}]
        ├─NetworkManager───2*[{NetworkManager}]
        ├─agetty
        ├─atd
        ├─avahi-daemon───avahi-daemon
        ├─colord───2*[{colord}]
        ├─cron
        ├─cups-browsed───2*[{cups-browsed}]
        ├─cupsd
        ├─dbus-daemon
        ├─exim4
        ├─lightdm─┬─2*[Xorg───9*[{Xorg}]]
        │         ├─lightdm─┬─xfce4-session─┬─Thunar───2*[{Thunar}]
        │         │         │               ├─applet.py
        │         │         │               ├─light-locker───3*[{light-locker}]
        │         │         │               ├─nm-applet───3*[{nm-applet}]
        │         │         │               ├─polkit-gnome-au───2*[{polkit-gnome-au}]
        │         │         │               ├─ssh-agent
        │         │         │               ├─xfce4-notifyd───2*[{xfce4-notifyd}]
        │         │         │               ├─xfce4-panel─┬─panel-10-notifi───2*[{panel-1+
        │         │         │               │             ├─panel-14-action───2*[{panel-1+
        │         │         │               │             ├─panel-6-systray───2*[{panel-6+
        │         │         │               │             ├─panel-8-pulseau───2*[{panel-8+
        │         │         │               │             ├─panel-9-power-m───2*[{panel-9+
        │         │         │               │             └─2*[{xfce4-panel}]
        │         │         │               ├─xfce4-power-man───2*[{xfce4-power-man}]
        │         │         │               ├─xfdesktop───2*[{xfdesktop}]
        │         │         │               ├─xfsettingsd───2*[{xfsettingsd}]
        │         │         │               ├─xfwm4───10*[{xfwm4}]
        │         │         │               ├─xiccd───2*[{xiccd}]
        │         │         │               └─2*[{xfce4-session}]
        │         │         └─2*[{lightdm}]
        │         ├─lightdm─┬─lightdm-gtk-gre───10*[{lightdm-gtk-gre}]
        │         │         └─2*[{lightdm}]
        │         ├─lightdm
        │         └─2*[{lightdm}]
        ├─packagekitd───2*[{packagekitd}]
        ├─polkitd───2*[{polkitd}]
        ├─rsyslogd───3*[{rsyslogd}]
        ├─rtkit-daemon───2*[{rtkit-daemon}]
        ├─sshd───sshd───sshd───bash───su───bash───pstree
        ├─systemd─┬─(sd-pam)
        │         ├─at-spi-bus-laun─┬─dbus-daemon
        │         │                 └─3*[{at-spi-bus-laun}]
        │         ├─at-spi2-registr───2*[{at-spi2-registr}]
        │         ├─dbus-daemon
        │         ├─gvfsd───2*[{gvfsd}]
        │         ├─pipewire─┬─pipewire-media-───{pipewire-media-}
        │         │          └─{pipewire}
        │         └─pulseaudio───{pulseaudio}
        ├─systemd─┬─(sd-pam)
        │         ├─at-spi-bus-laun─┬─dbus-daemon
        │         │                 └─3*[{at-spi-bus-laun}]
        │         ├─at-spi2-registr───2*[{at-spi2-registr}]
        │         ├─dbus-daemon
        │         ├─dconf-service───2*[{dconf-service}]
        │         ├─gpg-agent
        │         ├─gvfs-udisks2-vo───3*[{gvfs-udisks2-vo}]
        │         ├─gvfsd─┬─gvfsd-trash───2*[{gvfsd-trash}]
        │         │       └─2*[{gvfsd}]
        │         ├─gvfsd-metadata───2*[{gvfsd-metadata}]
        │         ├─pipewire─┬─pipewire-media-───{pipewire-media-}
        │         │          └─{pipewire}
        │         ├─pulseaudio───{pulseaudio}
        │         └─xfconfd───2*[{xfconfd}]
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-timesyn───{systemd-timesyn}
        ├─systemd-udevd
        ├─udisksd───4*[{udisksd}]
        ├─upowerd───2*[{upowerd}]
        ├─wpa_supplicant
        └─xfce4-terminal─┬─bash
                         └─2*[{xfce4-terminal}]

Les options de cette commande sont :

root@debian11:~# pstree --help
pstree: unrecognized option '--help'
Usage: pstree [-acglpsStTuZ] [ -h | -H PID ] [ -n | -N type ]
              [ -A | -G | -U ] [ PID | USER ]
   or: pstree -V

Display a tree of processes.

  -a, --arguments     show command line arguments
  -A, --ascii         use ASCII line drawing characters
  -c, --compact-not   don't compact identical subtrees
  -C, --color=TYPE    color process by attribute
                      (age)
  -g, --show-pgids    show process group ids; implies -c
  -G, --vt100         use VT100 line drawing characters
  -h, --highlight-all highlight current process and its ancestors
  -H PID, --highlight-pid=PID
                      highlight this process and its ancestors
  -l, --long          don't truncate long lines
  -n, --numeric-sort  sort output by PID
  -N TYPE, --ns-sort=TYPE
                      sort output by this namespace type
                              (cgroup, ipc, mnt, net, pid, time, user, uts)
  -p, --show-pids     show PIDs; implies -c
  -s, --show-parents  show parents of the selected process
  -S, --ns-changes    show namespace transitions
  -t, --thread-names  show full thread names
  -T, --hide-threads  hide threads, show only processes
  -u, --uid-changes   show uid transitions
  -U, --unicode       use UTF-8 (Unicode) line drawing characters
  -V, --version       display version information
  -Z, --security-context
                      show security attributes

  PID    start at this PID; default is 1 (init)
  USER   show only trees rooted at processes of this user

4.3 - La Commande top

Cette commande indique les processus en mémoire :

root@debian11:~# top

top - 09:22:03 up 26 days, 18:44,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 141 total,   1 running, 140 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.3 us,  0.2 sy,  0.0 ni, 99.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3931.2 total,   1711.3 free,    405.5 used,   1814.4 buff/cache
MiB Swap:    975.0 total,    975.0 free,      0.0 used.   3238.3 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                 
  22947 root      20   0  867344  56320  41236 S   0.3   1.4   0:11.05 Xorg                                                                    
  22994 lightdm   20   0 1168584  95868  59348 S   0.3   2.4   1:13.05 lightdm-gtk-gre                                                         
  28304 trainee   20   0   14832   5888   4616 S   0.3   0.1   0:00.10 sshd                                                                    
      1 root      20   0  165192  10516   7596 S   0.0   0.3   0:14.72 systemd                                                                 
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.71 kthreadd                                                                
      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp                                                                  
      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp                                                              
      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 kworker/0:0H-events_highpri                                             
      8 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 mm_percpu_wq                                                            
      9 root      20   0       0      0      0 S   0.0   0.0   0:00.00 rcu_tasks_rude_                                                         
     10 root      20   0       0      0      0 S   0.0   0.0   0:00.00 rcu_tasks_trace                                                         
     11 root      20   0       0      0      0 S   0.0   0.0   0:00.09 ksoftirqd/0                                                             
     12 root      20   0       0      0      0 I   0.0   0.0   0:08.85 rcu_sched                                                               
     13 root      rt   0       0      0      0 S   0.0   0.0   0:12.98 migration/0                                                             
     15 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp/0                                                                 
     16 root      20   0       0      0      0 S   0.0   0.0   0:00.00 cpuhp/1                                                                 
     17 root      rt   0       0      0      0 S   0.0   0.0   0:12.26 migration/1                                                             
     18 root      20   0       0      0      0 S   0.0   0.0   0:00.13 ksoftirqd/1                                                             
     20 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 kworker/1:0H-events_highpri                                             
     23 root      20   0       0      0      0 S   0.0   0.0   0:00.00 kdevtmpfs                                                               
     24 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 netns                                                                   
     25 root      20   0       0      0      0 S   0.0   0.0   0:00.00 kauditd                                                                 
     27 root      20   0       0      0      0 S   0.0   0.0   0:00.99 khungtaskd                                                              
     28 root      20   0       0      0      0 S   0.0   0.0   0:00.00 oom_reaper                                                              
     29 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 writeback                                                               
     30 root      20   0       0      0      0 S   0.0   0.0   1:15.18 kcompactd0                                    
...                                                                         

Pour afficher l'aide de la commande top, appuyez sur la touche h :

Help for Interactive Commands - procps-ng 3.3.17
Window 1:Def: Cumulative mode Off.  System: Delay 3.0 secs; Secure mode Off.

  Z,B,E,e   Global: 'Z' colors; 'B' bold; 'E'/'e' summary/task memory scale
  l,t,m,I   Toggle: 'l' load avg; 't' task/cpu; 'm' memory; 'I' Irix mode
  0,1,2,3,4 Toggle: '0' zeros; '1/2/3' cpu/numa views; '4' cpus two abreast
  f,F,X     Fields: 'f'/'F' add/remove/order/sort; 'X' increase fixed-width

  L,&,<,> . Locate: 'L'/'&' find/again; Move sort column: '<'/'>' left/right
  R,H,J,C . Toggle: 'R' Sort; 'H' Threads; 'J' Num justify; 'C' Coordinates
  c,i,S,j . Toggle: 'c' Cmd name/line; 'i' Idle; 'S' Time; 'j' Str justify
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u,U,o,O . Filter by: 'u'/'U' effective/any user; 'o'/'O' other criteria
  n,#,^O  . Set: 'n'/'#' max tasks displayed; Show: Ctrl+'O' other filter(s)
  V,v     . Toggle: 'V' forest view; 'v' hide/show forest view children

  k,r       Manipulate tasks: 'k' kill; 'r' renice
  d or s    Set update interval
  W,Y,!     Write config file 'W'; Inspect other output 'Y'; Combine Cpus '!'
  q         Quit
          ( commands shown with '.' require a visible task display window ) 
Press 'h' or '?' for help with Windows,
Type 'q' or <Esc> to continue  

Important - Pour revenir à l'affichage précédent, appuyez sur la touche q ou echap.

Au lancement, le temps de rafraîchissement de la liste est de 3 secondes. Pour modifier ce temps à 1 seconde, appuyez sur la touche s puis la touche 1 et validez :

root@debian11:~# top
...
top - 09:24:04 up 26 days, 18:46,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 141 total,   1 running, 140 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni, 99.8 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3931.2 total,   1711.3 free,    405.5 used,   1814.4 buff/cache
MiB Swap:    975.0 total,    975.0 free,      0.0 used.   3238.3 avail Mem 
Change delay from 3.0 to 1
    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                 
...

Pour trier la liste selon l'utilisation de la mémoire, appuyez sur la touche M :

root@debian11:~# top
...
top - 09:25:13 up 26 days, 18:48,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 141 total,   1 running, 140 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3931.2 total,   1711.1 free,    405.7 used,   1814.4 buff/cache
MiB Swap:    975.0 total,    975.0 free,      0.0 used.   3238.0 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                 
  22994 lightdm   20   0 1168584  95868  59348 S   0.0   2.4   1:13.09 lightdm-gtk-gre                                                         
    452 root      20   0  861748  78164  38060 S   0.0   1.9   1:07.28 Xorg                                                                    
  22007 trainee   20   0  973148  73384  57724 S   0.0   1.8   0:03.88 xfwm4                                                                   
  22947 root      20   0  867344  56320  41236 S   0.0   1.4   0:11.05 Xorg                                                                    
  22045 trainee   20   0  329636  53740  32396 S   0.0   1.3   0:05.50 xfdesktop                                                               
  22036 trainee   20   0  319156  40340  31788 S   0.0   1.0   0:06.02 xfce4-panel                                                             
  22146 trainee   20   0  386976  36676  28888 S   0.0   0.9   0:00.20 xfce4-terminal                                                          
  22051 trainee   20   0   62288  36480  18088 S   0.0   0.9   0:00.49 applet.py                                                               
  22096 trainee   20   0  240616  35676  28976 S   0.0   0.9   0:00.27 panel-10-notifi                                                         
  22052 trainee   20   0  355636  33224  26600 S   0.0   0.8   0:00.17 nm-applet                                                               
  22094 trainee   20   0  464892  31108  24892 S   0.0   0.8   2:42.24 panel-8-pulseau                                                         
  22095 trainee   20   0  197048  28304  22796 S   0.0   0.7   0:00.29 panel-9-power-m                                                         
    213 root      20   0   56684  28064  24908 S   0.0   0.7   0:08.07 systemd-journal                                                         
  22093 trainee   20   0  341076  24972  18016 S   0.0   0.6   0:00.25 panel-6-systray                                                         
  22040 trainee   20   0  341956  24776  17892 S   0.0   0.6   0:00.06 Thunar                                                                  
  22024 trainee   20   0  227856  24132  18852 S   0.0   0.6   0:00.17 xfsettingsd                                                             
  22119 trainee   20   0  195152  23308  18416 S   0.0   0.6   0:00.23 panel-14-action                                                         
  22063 trainee   20   0  268476  23096  18368 S   0.0   0.6   0:01.99 light-locker                                                            
  21928 trainee   20   0  267564  22348  17344 S   0.0   0.6   0:00.16 xfce4-session                                                           
  22049 trainee   20   0  264284  19340  15216 S   0.0   0.5   0:00.02 xfce4-notifyd                                                           
  12807 root      20   0  289480  18932  16368 S   0.0   0.5   0:07.01 packagekitd                                                             
  22060 trainee   20   0  190476  17604  15312 S   0.0   0.4   0:00.10 xfce4-power-man                                                         
    368 root      20   0  254628  16664  14172 S   0.0   0.4   0:46.42 NetworkManager                                                          
  22065 trainee   20   0  189472  15168  13384 S   0.0   0.4   0:00.04 polkit-gnome-au                                                         
  22122 trainee   20   0  348880  13816  10064 S   0.0   0.3   0:00.03 gvfs-udisks2-vo                                                         
  22084 colord    20   0  242896  13092   9484 S   0.0   0.3   0:00.12 colord        
...                                                        

Pour ne pas visualiser les processus zombies ou les processus en attente, appuyez sur la touche i :

root@debian11:~# top
...
top - 09:26:38 up 26 days, 18:49,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 142 total,   1 running, 141 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3931.2 total,   1711.1 free,    405.7 used,   1814.4 buff/cache
MiB Swap:    975.0 total,    975.0 free,      0.0 used.   3238.0 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                 
  30295 root      20   0   10100   3512   3016 R   1.0   0.1   0:00.51 top                                                                           

Pour quitter top, appuyez sur la touche q.

Les options de cette commande sont :

root@debian11:~# top --help
top: inappropriate '-help'
Usage:
  top -hv | -bcEeHiOSs1 -d secs -n max -u|U user -p pid(s) -o field -w [cols]

4.4 - La commande lsof

La commande lsof affiche des informations sur les fichiers ouverts par des processus :

trainee@debian11:/tmp$ su -
Password: fenestros
root@debian11:~# lsof | more
COMMAND     PID   TID TASKCMD               USER   FD      TYPE             DEVICE SIZE/OFF       NODE NAME
systemd       1                             root  cwd       DIR                8,1     4096          2 /
systemd       1                             root  rtd       DIR                8,1     4096          2 /
systemd       1                             root  txt       REG                8,1  1739200     135225 /usr/lib/systemd/systemd
systemd       1                             root  mem       REG                8,1   149576     131801 /usr/lib/x86_64-linux-gnu/libgpg-error.so
.0.29.0
systemd       1                             root  mem       REG                8,1  3076992     130845 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.
1
systemd       1                             root  mem       REG                8,1    26984     131688 /usr/lib/x86_64-linux-gnu/libcap-ng.so.0.
0.0
systemd       1                             root  mem       REG                8,1   617128     133011 /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0
.10.1
systemd       1                             root  mem       REG                8,1   149520     131529 /usr/lib/x86_64-linux-gnu/libpthread-2.31
.so
systemd       1                             root  mem       REG                8,1    18688     131516 /usr/lib/x86_64-linux-gnu/libdl-2.31.so
systemd       1                             root  mem       REG                8,1   158400     132895 /usr/lib/x86_64-linux-gnu/liblzma.so.5.2.
5
systemd       1                             root  mem       REG                8,1   890800     134187 /usr/lib/x86_64-linux-gnu/libzstd.so.1.4.
8
systemd       1                             root  mem       REG                8,1   137568     131838 /usr/lib/x86_64-linux-gnu/liblz4.so.1.9.3
systemd       1                             root  mem       REG                8,1    35280     134981 /usr/lib/x86_64-linux-gnu/libip4tc.so.2.0
.0
systemd       1                             root  mem       REG                8,1  1176248     131813 /usr/lib/x86_64-linux-gnu/libgcrypt.so.20
.2.8
systemd       1                             root  mem       REG                8,1   202680     130829 /usr/lib/x86_64-linux-gnu/libcrypt.so.1.1
.0
systemd       1                             root  mem       REG                8,1    38864     134959 /usr/lib/x86_64-linux-gnu/libcap.so.2.44
systemd       1                             root  mem       REG                8,1   326624     132627 /usr/lib/x86_64-linux-gnu/libblkid.so.1.1
.0
systemd       1                             root  mem       REG                8,1    38936     131226 /usr/lib/x86_64-linux-gnu/libacl.so.1.1.2
253
systemd       1                             root  mem       REG                8,1  1839792     130842 /usr/lib/x86_64-linux-gnu/libc-2.31.so
--More--
[q]

Les options de cette commande sont :

root@debian11:~# lsof --help
lsof: illegal option character: -
lsof: -e not followed by a file system path: "lp"
lsof 4.93.2
 latest revision: https://github.com/lsof-org/lsof
 latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ
 latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-E] [+|-e s] [+|-f[gG]]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
 [+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
  -?|-h list help          -a AND selections (OR)     -b avoid kernel blocks
  -c c  cmd c ^c /c/[bix]  +c w  COMMAND width (9)    +d s  dir s files
  -d s  select by FD set   +D D  dir D tree *SLOW?*   +|-e s  exempt s *RISKY*
  -i select IPv[46] files  -K [i] list|(i)gn tasKs    -l list UID numbers
  -n no host names         -N select NFS files        -o list file offset
  -O no overhead *RISKY*   -P no port names           -R list paRent PID
  -s list file size        -t terse listing           -T disable TCP/TPI info
  -U select Unix socket    -v list version info       -V verbose search
  +|-w  Warnings (+)       -X skip TCP&UDP* files     -Z Z  context [Z]
  -- end option scan     
  -E display endpoint info              +E display endpoint info and files
  +f|-f  +filesystem or -file names     +|-f[gG] flaGs 
  -F [f] select fields; -F? for help  
  +|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
                                        +m [m] use|create mount supplement
  +|-M   portMap registration (-)       -o o   o 0t offset digits (8)
  -p s   exclude(^)|select PIDs         -S [t] t second stat timeout (15)
  -T qs TCP/TPI Q,St (s) info
  -g [s] exclude(^)|select and print process group IDs
  -i i   select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
  +|-r [t[m<fmt>]] repeat every t seconds (15);  + until no files, - forever.
       An optional suffix to t is m<fmt>; m must separate t from <fmt> and
      <fmt> is an strftime(3) format for the marker line.
  -s p:s  exclude(^)|select protocol (p = TCP|UDP) states by name(s).
  -u s   exclude(^)|select login|UID set s
  -x [fl] cross over +d|+D File systems or symbolic Links
  names  select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.

LAB # 5 - Mesurer l'utilisation du réseau et la disponibilité du système

5.1 - La Commande netstat

Pour visualiser les statistiques réseaux, vous disposez de la commande netstat :

root@debian11:~# apt install net-tools

root@debian11:~# netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens18     1500    52060      0      0 0         41193      0      0      0 BMRU
lo       65536     1197      0      0 0          1197      0      0      0 LRU

Les options de cette commande sont :

root@debian11:~# netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vWnNcaeol] [<Socket> ...]
       netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }

        -r, --route              display routing table
        -i, --interfaces         display interface table
        -g, --groups             display multicast group memberships
        -s, --statistics         display networking statistics (like SNMP)
        -M, --masquerade         display masqueraded connections

        -v, --verbose            be verbose
        -W, --wide               don't truncate IP addresses
        -n, --numeric            don't resolve names
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -N, --symbolic           resolve hardware names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets
        -o, --timers             display timers
        -c, --continuous         continuous listing

        -l, --listening          display listening server sockets
        -a, --all                display all sockets (default: connected)
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB
        -Z, --context            display SELinux security context for sockets

  <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
           {-x|--unix} --ax25 --ipx --netrom
  <AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
    x25 (CCITT X.25) 

Copyright © 2022 Hugh Norris.