Getting System Information
Collection of commands to fetch system related information.
Statistics about CPU, Memory, Network and Disk (I/O operations)
Section titled “Statistics about CPU, Memory, Network and Disk (I/O operations)”To get general statistics about main components of Linux family of stat commands are extremely useful
To get processors related statistics you can use mpstat command but with some options it will provide better visibility:
$ mpstat 2 10Memory
Section titled “Memory”We all know command free to show amount of (remaining) RAM but to see all statistic including I/O operations:
$ vmstat 2 10To get general information about your disk operations in real time you can utilise iostat.
$ iostat -kx 2Network
Section titled “Network”To be able to see what is happening with your network services you can use netstat
$ netstat -ntlp # open TCP sockets$ netstat -nulp # open UDP sockets$ netstat -nxlp # open Unix socketsBut you can find useful monitoring to see network traffic in real time:
$ sudo iftopOptional
Section titled “Optional”To generate statistics in real time related to I/O operations across all components you can use dstat. That tool that is a versatile replacement for vmstat, iostat and ifstat
List Hardware
Section titled “List Hardware”Ubuntu:
lshw is a small tool to extract detailed information on the hardware configuration of the machine. It can report exact memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc.
$ sudo lshw | less (or more)$ sudo lshw -html > myhardware.html$ sudo lshw -xml > myhardware.xmlTo show PCI info
$ lspci -tvTo see USB info
$ lsusb -tvTo display BIOS informations
$ dmidecode -q | lessTo see specific information about disk (disk sda in example) you can use:
$ hdparm -i /dev/sdaFew additional utilities/commands will help gather some extra information:
$ smartctl -A /dev/sda | grep Power_On_Hours # How long has this disk (system) been powered on in total$ hdparm -tT /dev/sda # Do a read speed test on disk sda$ badblocks -s /dev/sda # Test for unreadable blocks on disk sdaFind CPU model/speed information
Section titled “Find CPU model/speed information”Ubuntu:
$ cat /proc/cpuinfoSample Output:
processor : 0vendor_id : GenuineIntelcpu family : 6model : 15model name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHzstepping : 11cpu MHz : 1596.000cache size : 4096 KBphysical id : 0siblings : 4core id : 0cpu cores : 4apicid : 0initial apicid : 0fpu : yesfpu_exception : yescpuid level : 10wp : yesflags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexprioritybogomips : 4800.18clflush size : 64cache_alignment : 64address sizes : 36 bits physical, 48 bits virtualpower management:......processor : 3vendor_id : GenuineIntelcpu family : 6model : 15model name : Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHzstepping : 11cpu MHz : 1596.000cache size : 4096 KBphysical id : 0siblings : 4core id : 3cpu cores : 4apicid : 3initial apicid : 3fpu : yesfpu_exception : yescpuid level : 10wp : yesflags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm lahf_lm tpr_shadow vnmi flexprioritybogomips : 4800.30clflush size : 64cache_alignment : 64address sizes : 36 bits physical, 48 bits virtualpower management:count processor (including cores):
$ grep -c processor /proc/cpuinfoProcess monitoring and information gathering
Section titled “Process monitoring and information gathering”Overall you have two ways to monitor processes at linux host
Static monitoring
Section titled “Static monitoring”Most widely used command is ps (i.e., process status) command is used to provide information about the currently running processes, including their process identification numbers (PIDs).
Here few useful options to gather specific informations.
List processes in a hierarchy
$ ps -e -o pid,args --forestList processes sorted by % cpu usage
$ ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'List processes sorted by mem (KB) usage.
$ ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNSList all threads for a particular process (“firefox-bin” process in example )
$ ps -C firefox-bin -L -o pid,tid,pcpu,stateAfter finding specific process you can gather information related to it using lsof to list paths that process id has open
$ lsof -p $$Or based on path find out list processes that have specified path open
$ lsof ~Interactive monitoring
Section titled “Interactive monitoring”Most commonly known tool for dynamic monitoring is:
$ topThat mostly default command that have huge amount options to filter and represent information in real time (in comparison to ps command.
Still there are more advance options that can be considered and installed as top replacement
$ htop -d 5or
$ atopWhich has ability to log all the activities into log file (default atop will log all the activity on every 600 seconds)
To this list there are few specialised commands as iotop or iftop
$ sudo iotopUsing tools like lscpu and lshw
Section titled “Using tools like lscpu and lshw”By using tools like lscpu as lscpu is an easy way to get CPU information.
$ lscpuArchitecture: x86_64CPU op-mode(s): 32-bit, 64-bitByte Order: Little EndianCPU(s): 4On-line CPU(s) list: 0-3Thread(s) per core: 1Core(s) per socket: 4Socket(s): 1NUMA node(s): 1Vendor ID: GenuineIntelCPU family: 6Model: 23Stepping: 10CPU MHz: 1998.000BogoMIPS: 5303.14Virtualization: VT-xL1d cache: 32KL1i cache: 32KL2 cache: 2048KNUMA node0 CPU(s): 0-3By using tool lshw
$ lshw | grep cpu
df1-ws-5084 description: Computer width: 64 bits capabilities: vsyscall32 *-core description: Motherboard physical id: 0 *-memory description: System memory physical id: 0 size: 5881MiB *-cpu product: Intel(R) Pentium(R) CPU G3220 @ 3.00GHz vendor: Intel Corp. physical id: 1 bus info: cpu@0 size: 3GHz capacity: 3GHz width: 64 bits