0Pricing
Linux Command Line Mastery · Lekcja

Narzędzia do monitorowania pamięci i procesora

Wykorzystają Państwo narzędzia takie jak `vmstat`, `sar` i `mpstat` do diagnozowania problemów z wydajnością procesora i pamięci.

Narzędzia do monitorowania pamięci i procesora to bezpłatna lekcja Linux Command Line Mastery na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Linux Command Line Mastery, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Linux Command Line Mastery zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

Diagnose Performance Issues

Understanding system performance is key to troubleshooting slow applications or an unresponsive server. CPU and memory are often the first resources to check.

In this lesson, we'll explore powerful command-line tools to monitor and diagnose issues related to your system's CPU and memory usage.

Meet `vmstat`

The vmstat (virtual memory statistics) command provides a quick, real-time snapshot of your system's activity. It reports on processes, memory, paging, block I/O, traps, and CPU activity.

It's excellent for observing current system behavior and identifying immediate bottlenecks.

`vmstat` Memory Overview

Let's run vmstat 1 1 to see a single report, then we'll break down the memory-related output. This command shows a report every 1 second, for 1 iteration.

  • swpd: amount of virtual memory used.
  • free: amount of idle memory.
  • buff: memory used as buffers.
  • cache: memory used as cache.
vmstat 1 1

`vmstat` CPU Details

Now, let's look at the CPU section of vmstat. Run the command again if you like, and focus on the 'cpu' columns:

  • us (user): time spent running non-kernel code.
  • sy (system): time spent running kernel code.
  • id (idle): time spent idle.
  • wa (wait): time spent waiting for I/O.

High wa often indicates disk bottlenecks.

vmstat 1 1

Introducing `sar`

The sar (System Activity Reporter) command is part of the sysstat package. Unlike vmstat, sar can collect and report historical system activity data.

This makes it invaluable for long-term analysis, identifying trends, and diagnosing intermittent problems that might not be visible with real-time tools.

`sar` for CPU Usage

To view CPU utilization with sar, we use the -u option. Run sar -u 1 1 to get a single report.

  • %user: CPU usage by user-level applications.
  • %system: CPU usage by kernel-level tasks.
  • %iowait: Time CPU spent waiting for I/O.
  • %idle: Time CPU was idle.
sar -u 1 1

`sar` for Memory Usage

To get detailed memory utilization reports with sar, use the -r option. Try sar -r 1 1.

  • kbmemfree: Amount of free memory.
  • kbmemused: Amount of used memory.
  • %memused: Percentage of used memory.
  • kbbuffers: Memory used by kernel buffers.
  • kbcached: Memory used by page cache.
sar -r 1 1

Understanding `mpstat`

The mpstat (multi-processor statistics) command is also part of the sysstat package. Its main advantage is providing per-processor or per-core CPU activity.

This is crucial for systems with multiple CPU cores, as it helps identify if a specific core is overloaded while others are idle.

`mpstat` Per-Core Activity

To see statistics for all individual CPU cores, use mpstat -P ALL 1 1. You'll see a separate line for each core (CPU 0, CPU 1, etc.) and an 'all' line for the average.

This helps pinpoint if a single-threaded application is maxing out one core, even if overall CPU usage seems low.

mpstat -P ALL 1 1

Performance Tool Check

Which of the following statements about Linux performance tools are TRUE?

Recap: CPU & Memory Tools

In this lesson, you learned about three essential tools for monitoring CPU and memory performance:

  • vmstat: For real-time system activity snapshots.
  • sar: For collecting and reporting historical system activity data.
  • mpstat: For detailed per-processor/per-core CPU usage.

Mastering these commands will significantly boost your ability to diagnose and troubleshoot Linux system performance issues.

Często zadawane pytania

Czy lekcja „Narzędzia do monitorowania pamięci i procesora” jest bezpłatna?

Tak — pełny tekst „Narzędzia do monitorowania pamięci i procesora” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Linux Command Line Mastery, przejdź na CoddyKit PRO. Kurs Linux Command Line Mastery zawiera 4 lekcji w sumie.

Co nauczysz się w „Narzędzia do monitorowania pamięci i procesora”?

Wykorzystają Państwo narzędzia takie jak `vmstat`, `sar` i `mpstat` do diagnozowania problemów z wydajnością procesora i pamięci. Ćwiczysz Linux Command Line Mastery z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Linux Command Line Mastery?

Nie wymagamy żadnego doświadczenia. Linux Command Line Mastery w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Narzędzia do monitorowania pamięci i procesora”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Linux Command Line Mastery?

Tak. Każda lekcja Linux Command Line Mastery zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Monitorowanie operacji wejścia/wyjścia dysku: `iostat`, `iotop`
  2. Narzędzia do monitorowania pamięci i procesora
  3. Zaawansowane techniki logowania i rozwiązywania problemów
  4. Śledzenie wywołań systemowych za pomocą strace i ltrace
← Powrót do Linux Command Line Mastery