{"id":123,"date":"2018-07-25T14:33:15","date_gmt":"2018-07-25T10:33:15","guid":{"rendered":"http:\/\/kidds.co.za\/?p=123"},"modified":"2018-07-25T14:43:15","modified_gmt":"2018-07-25T10:43:15","slug":"16-linux-server-monitoring-commands-you-really-need-to-know","status":"publish","type":"post","link":"https:\/\/kidds.co.za\/index.php\/2018\/07\/25\/16-linux-server-monitoring-commands-you-really-need-to-know\/","title":{"rendered":"16 Linux server monitoring commands you really need to know"},"content":{"rendered":"<h1 class=\"headline\">16 Linux server monitoring commands you really need to know<\/h1>\n<div class=\"color-stripe\"><a href=\"https:\/\/www.hpe.com\/us\/en\/insights\/articles\/16-linux-server-monitoring-commands-you-really-need-to-know-1703.html\">Original Article hpe.com<\/a><\/div>\n<p><span class=\"teaser\">If you want to know what&#8217;s going on with your Linux server, start with these Linux monitoring commands.<\/span><\/p>\n<div class=\"article-body kapost-article-body nxt-button-placeholder\">\n<p>Want to know what\u2019s really going on with your server? Then you need to know these essential commands. Once you\u2019ve mastered them, you\u2019ll be well on your way to being an expert Linux system administrator.<\/p>\n<p>Sure, you can use a GUI program to pull up much of the information that these shell commands can give you, depending on the Linux distribution. <a href=\"https:\/\/www.suse.com\/products\/server\/\">SUSE Linux Enterprise Server<\/a> and <a href=\"https:\/\/www.opensuse.org\/\">openSUSE<\/a>, for example, have an excellent graphical configuration and management tool, <a href=\"http:\/\/en.opensuse.org\/Portal:YaST\">YaST<\/a>. And there are universal tools, such as <a href=\"http:\/\/www.webmin.com\/\">Webmin<\/a> and <a href=\"https:\/\/cpanel.com\/\">cPanel<\/a>, which can be used on any Linux server.<\/p>\n<p>However, it\u2019s a Linux administrator truism that you should run a GUI on a server only when you absolutely must. That\u2019s because Linux GUIs take up system resources that could be better used elsewhere. So, while using a GUI program is fine for basic server health checkups, if you want to know what\u2019s really happening, turn off the GUI and use these tools from the Linux command shell.<\/p>\n<p>This also means you should start a GUI on a server only when it\u2019s required; don\u2019t leave it running. For optimum performance, a Linux server should run at runlevel 3, which fully supports networking and multiple users but doesn\u2019t start the GUI when the machine boots. If you really need a graphical desktop, you can always get one by running startx from a shell prompt.<\/p>\n<p>If your server starts by booting into a graphical desktop, you need to change this. To do so, head to a terminal window, su to the root user, and use your favorite editor on <code>\/etc\/inittab.<\/code><\/p>\n<p>Once there, find the <code>initdefault<\/code> line and change it from:<\/p>\n<pre>id:5:initdefault:<\/pre>\n<p>to<\/p>\n<pre>id:3:initdefault:<\/pre>\n<p>If there is no inittab file, create it and add the id:3 line. Save and exit. The next time you boot into your server, it will boot into runlevel 3. If you don\u2019t want to reboot after this change, you can also set your server\u2019s run level immediately with the command:<\/p>\n<pre>init 3<\/pre>\n<p>Once your server is running at init 3, you can start using the following shell programs to see what\u2019s happening inside your server.<\/p>\n<h3>iostat<\/h3>\n<p>The <code><a href=\"http:\/\/www.cyberciti.biz\/tips\/linux-disk-performance-monitoring-howto.html\">iostat<\/a><\/code> command shows in detail what your storage subsystem is up to. You usually use iostat\u00a0to monitor how well your storage subsystems are working in general and to spot slow I\/O problems before your clients notice that the server is running slowly. Trust me, you want to spot these problems before your users do!<\/p>\n<h3>meminfo and free<\/h3>\n<p><code><a href=\"https:\/\/www.centos.org\/docs\/5\/html\/5.2\/Deployment_Guide\/s2-proc-meminfo.html\">Meminfo<\/a><\/code> gives you a detailed list of what\u2019s going on in memory. Typically you access <code>meminfo<\/code>\u2019s data by using another program such as <code>cat<\/code> or <code>grep<\/code>. For example,<\/p>\n<pre>cat \/proc\/meminfo<\/pre>\n<p>gives you the details of what\u2019s going on in your server\u2019s memory at any given moment.<\/p>\n<p>For a quick \u201cjust the facts\u201d look at memory, you can use the <code>free<\/code> command. In short, <code>free<\/code> gives you the overview; <code>meminfo<\/code> gives you the details.<\/p>\n<h3>mpstat<\/h3>\n<p>The <code><a href=\"http:\/\/linuxcommand.org\/man_pages\/mpstat1.html\">mpstat<\/a><\/code> command reports on the activities of each of the available CPUs on a multi-processor server. These days, thanks to multi-core processors, that\u2019s almost all servers. Mpstat also reports on the average activities of all your server\u2019s CPUs. It enables you to display overall CPU statistics per system or per processor. This overview can alert you to possible application problems before they get to the point of annoying users.<\/p>\n<div class=\"button\">\n<div class=\"button-description\">\n<p>Keep up with the latest in IT-driven business innovation with our weekly newsletter.<\/p>\n<\/div>\n<div class=\"button-wrapper\"><a class=\"btn btn-primary\" href=\"https:\/\/www.hpe.com\/us\/en\/insights\/newsletter-registration.html?jumpid=in_510384402_linuxserver0317\" target=\"_blank\" rel=\"noopener\">Subscribe today<\/a><\/div>\n<\/div>\n<h3>netstat<\/h3>\n<p><code><a href=\"http:\/\/www.thegeekstuff.com\/2010\/03\/netstat-command-examples\/\">Netstat<\/a><\/code>, like <code>ps<\/code>, is a Linux tool that administrators use every day. It displays a lot of network-related information, such as socket usage, routing, interface, protocol, network statistics, and more. Some of the most commonly used options are:<\/p>\n<pre>-a Show all socket information -r Show routing information -i Show network interface statistics<\/pre>\n<pre>-s Show network protocol statistics<\/pre>\n<h3>nmon<\/h3>\n<p><code><a href=\"http:\/\/nmon.sourceforge.net\/pmwiki.php\">Nmon<\/a><\/code>, short for Nigel\u2019s Monitor, is a popular open-source tool to monitor Linux system performance. <code>Nmon<\/code> watches the performance information for several subsystems, such as processor utilization, memory utilization, run queue information, disk I\/O statistics, network I\/O statistics, paging activity, and process metrics. You can then view <code>nmon<\/code>\u2019s real-time system measurements via its <code>curses<\/code>\u00a0&#8220;graphical&#8221; interface.<\/p>\n<p>To run <code>nmon<\/code>, you start the tool from the shell. Once up, you select the subsystems to monitor by typing in its one-key commands. For example, to get CPU, memory, and disk statistics, you type <code>c<\/code>, <code>m<\/code>, and <code>d<\/code>. You can also use <code>nmon<\/code> with the <code>-f<\/code> flag to save performance statistics to a CSV file for later analysis.<\/p>\n<p>For day-to-day server monitoring, I find <code>nmon<\/code> to be the single most useful program in my Linux system management toolkit.<\/p>\n<h3>pmap<\/h3>\n<p>The <code><a href=\"https:\/\/linux.die.net\/man\/1\/pmap\">https:\/\/linux.die.net\/man\/1\/pmap<\/a><\/code> command reports the amount of memory that your server\u2019s processes are using. You can use this tool to determine which processes on the server are being allocated memory and whether any of these processes are being piggy with RAM.<\/p>\n<h3>ps and pstree<\/h3>\n<p>The <code><a href=\"http:\/\/linuxcommand.org\/man_pages\/ps1.html\">ps<\/a><\/code> and <code><a href=\"http:\/\/www.linfo.org\/pstree.html\">pstree<\/a><\/code> commands are two of the Linux administrator\u2019s best friends. They both provide a list of all currently running processes. The\u00a0<code>ps<\/code>\u00a0command tells you how much memory and processor time the server\u2019s programs are using; <code>pstree<\/code> shows less information but highlights which processes are the children of other processes. Armed with this information, you can spot out-of-control processes and kill them off with Linux\u2019s &#8220;take no prisoners&#8221;\u00a0<code><a href=\"http:\/\/linux.about.com\/library\/cmd\/blcmdl_kill.htm\">kill<\/a><\/code> command.<\/p>\n<h3>sar<\/h3>\n<p>The <code><a href=\"http:\/\/www.thegeekstuff.com\/2011\/03\/sar-examples\/\">sar<\/a><\/code> program is the Swiss Army knife of system monitoring tools. The <code>sar<\/code> command is actually made up of three separate programs: <code>sar<\/code>, which displays the data, and <code>sa1<\/code> and <code>sa2<\/code>, which collect and store it. Once installed, <code>sar<\/code> creates a detailed overview of CPU utilization, memory paging, network I\/O and transfer statistics, process creation activity, and storage device activity. The big difference between <code>sar<\/code> and <code>nmon<\/code> is that the former is better at long-term system monitoring; I find <code>nmon<\/code> to be better at giving me a quick read on my server\u2019s status.<\/p>\n<h3>strace<\/h3>\n<p><code><a href=\"http:\/\/www.hokstad.com\/5-simple-ways-to-troubleshoot-using-strace.html\">Strace<\/a><\/code> is often thought of as a programmer\u2019s debugging tool, but it\u2019s more than that. It intercepts and records the system calls that are called by a process. This makes it a useful diagnostic, instructional, and debugging tool. For example, you can use <code>strace<\/code> to find out which configuration file a program is actually using when it starts up.<\/p>\n<p><code>Strace<\/code> does have one flaw, though. When it\u2019s checking out a specific process, that process\u2019 performance falls through the floor. Thus, I use <code>strace<\/code>\u00a0only when I already have a darned good reason to think that that program is causing trouble.<\/p>\n<h3>tcpdump<\/h3>\n<p><code><a href=\"http:\/\/danielmiessler.com\/study\/tcpdump\/\">Tcpdump<\/a><\/code> is a simple, robust network monitoring utility. Its basic protocol analyzing capability enables you to get a rough view of what is happening on your network. To really dig into what\u2019s going on with your network, however, you want to use <code><a href=\"http:\/\/www.wireshark.org\/\">Wireshark<\/a><\/code> (see below).<\/p>\n<h3>top<\/h3>\n<p>The <code><a href=\"http:\/\/adminlinux.blogspot.com\/2009\/06\/how-do-i-use-linux-top-command.html\">top<\/a><\/code> command shows what\u2019s going on with your active processes. By default, it displays the most CPU-intensive tasks running on the server and updates the list every five seconds. You can sort the processes by PID (Process ID); age, newest first; time, by cumulative time; and resident memory usage and total time it\u2019s been using the CPU since startup. I find this a fast and easy way to see if any process is starting to lurch out of control and into trouble.<\/p>\n<h3>uptime<\/h3>\n<p>Use <code><a href=\"http:\/\/www.computerhope.com\/unix\/uptime.htm\">uptime<\/a><\/code> to see how long the server has been running and how many users are logged on. It also gives you an overview of the average server load. The optimal value of the load is 1 or less, which means that each process has immediate access to the CPU and there are no CPU cycles lost.<\/p>\n<h3>vmstat<\/h3>\n<p>For the most part, you use <code><a href=\"http:\/\/www.linuxjournal.com\/article\/8178\">vmstat<\/a><\/code> to monitor what\u2019s going on with virtual memory. Linux constantly uses virtual memory to get the best possible storage performance.<\/p>\n<p>If your applications are taking up too much memory, you get excessive page-outs\u2014programs moving from RAM to your system\u2019s swap space, which is on the hard drive. Your server can reach a point where it\u2019s spending more time managing memory paging than running your applications, a condition called <em>thrashing<\/em>. When your computer is thrashing, its performance falls through the floor. <code>Vmstat<\/code>, which can display either average data or actual samples, can help you spot memory pig programs and processes before they bring your server to a crawl.<\/p>\n<h3>Wireshark<\/h3>\n<p><code><a href=\"http:\/\/www.wireshark.org\/\">Wireshark<\/a><\/code>, formerly known as Ethereal (and still often referred to that way), is <code>tcpdump<\/code>\u2019s big brother, though more sophisticated and with far more advanced protocol analysis and reporting. <code>Wireshark<\/code> has both a GUI interface and a shell interface. If you do any serious network administration, you must use <code>ethereal<\/code>. And, if you\u2019re using <code>Wireshark\/ethereal<\/code>, I highly recommend Chris Sander\u2019s <em><a href=\"https:\/\/www.amazon.com\/Practical-Packet-Analysis-Wireshark-Real-World\/dp\/1593272669\/ref=la_B001JPCBQ6_1_1?s=books&amp;ie=UTF8&amp;qid=1487033253&amp;sr=1-1\">Practical Packet Analysis<\/a><\/em>, a great book on how to get the most out of this useful program.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>16 Linux server monitoring commands you really need to know Original Article hpe.com If you want to know what&#8217;s going on with your Linux server, start with these Linux monitoring commands. Want to know what\u2019s really going on with your server? Then you need to know these essential commands. Once you\u2019ve mastered them, you\u2019ll be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[],"class_list":["post-123","post","type-post","status-publish","format-standard","hentry","category-general-commands","category-linux"],"_links":{"self":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":1,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/posts\/123\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kidds.co.za\/index.php\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}