{"id":13869,"date":"2019-04-06T12:33:12","date_gmt":"2019-04-06T12:33:12","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13869"},"modified":"2019-04-06T12:33:12","modified_gmt":"2019-04-06T12:33:12","slug":"ngxtop-monitor-nginx-log-files-in-real-time-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/ngxtop-monitor-nginx-log-files-in-real-time-in-linux\/","title":{"rendered":"ngxtop \u2013 Monitor Nginx Log Files in Real Time in Linux"},"content":{"rendered":"<p><strong>ngxtop<\/strong>\u00a0is a free open source, simple, flexible, fully configurable and easy-to-use real-time\u00a0<a href=\"https:\/\/www.tecmint.com\/12-top-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">top-like monitoring tool<\/a>\u00a0for nginx server. It gathers data by parsing the nginx access log (default location is always\u00a0<strong>\/var\/log\/nginx\/access.log<\/strong>) and displays useful metrics of your nginx server, thus helping you to keep an eye on your web server in real-time. It also allows you to parse Apache logs from a remote server.<\/p>\n<h3>How to Install and Use Ngxtop in Linux<\/h3>\n<p>To install\u00a0<strong>ngxtop<\/strong>, first you need to\u00a0<a href=\"https:\/\/www.tecmint.com\/install-pip-in-linux\/\" target=\"_blank\" rel=\"noopener\">install PIP in Linux<\/a>, once you have\u00a0<strong>pip<\/strong>\u00a0installed on your system, you can install\u00a0<strong>ngxtop<\/strong>\u00a0using following command.<\/p>\n<pre>$ sudo pip install ngxtop\r\n<\/pre>\n<h4>Monitor Nginx Server Requests<\/h4>\n<p>Now that you have installed\u00a0<strong>ngxtop<\/strong>, the easiest way to run it is without any arguments. This will parse the\u00a0<strong>\/var\/log\/nginx\/access.log<\/strong>\u00a0and runs in follow mode (watch for new lines as they are written to the access log) by default.<\/p>\n<pre>$ sudo ngxtop\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>running for 411 seconds, 64332 records processed: 156.60 req\/sec\r\n\r\nSummary:\r\n|   count |   avg_bytes_sent |   2xx |   3xx |   4xx |   5xx |\r\n|---------+------------------+-------+-------+-------+-------|\r\n|   64332 |         2775.251 | 61262 |  2994 |    71 |     5 |\r\n\r\nDetailed:\r\n| request_path                             |   count |   avg_bytes_sent |   2xx |   3xx |   4xx |   5xx |\r\n|------------------------------------------+---------+------------------+-------+-------+-------+-------|\r\n| \/abc\/xyz\/xxxx                            |   20946 |          434.693 | 20935 |     0 |    11 |     0 |\r\n| \/xxxxx.json                              |    5633 |         1483.723 |  5633 |     0 |     0 |     0 |\r\n| \/xxxxx\/xxx\/xxxxxxxxxxxxx                 |    3629 |         6835.499 |  3626 |     0 |     3 |     0 |\r\n| \/xxxxx\/xxx\/xxxxxxxx                      |    3627 |        15971.885 |  3623 |     0 |     4 |     0 |\r\n| \/xxxxx\/xxx\/xxxxxxx                       |    3624 |         7830.236 |  3621 |     0 |     3 |     0 |\r\n| \/static\/js\/minified\/utils.min.js         |    3031 |         1781.155 |  2104 |   927 |     0 |     0 |\r\n| \/static\/js\/minified\/xxxxxxx.min.v1.js    |    2889 |         2210.235 |  2068 |   821 |     0 |     0 |\r\n| \/static\/tracking\/js\/xxxxxxxx.js          |    2594 |         1325.681 |  1927 |   667 |     0 |     0 |\r\n| \/xxxxx\/xxx.html                          |    2521 |          573.597 |  2520 |     0 |     1 |     0 |\r\n| \/xxxxx\/xxxx.json                         |    1840 |          800.542 |  1839 |     0 |     1 |     0 |\r\n<\/pre>\n<p>To quit, press\u00a0<strong>[Ctrl + C]<\/strong>.<\/p>\n<h4>Parse Different Access Log<\/h4>\n<p>You can parse a different access log, for instance for a particular website or web app using the\u00a0<code>-l<\/code>\u00a0flag as shown.<\/p>\n<pre>$ sudo ngxtop -l \/var\/log\/nginx\/site1\/access.log\r\n<\/pre>\n<h4>List Top Source IPs of Clients<\/h4>\n<p>The following command will list all top source IP\u2019s of clients accessing the site.<\/p>\n<pre>$ sudo ngxtop remote_addr -l  \/var\/log\/nginx\/site1\/access.log\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>running for 20 seconds, 3215 records processed: 159.62 req\/sec\r\n\r\ntop remote_addr\r\n| remote_addr     |   count |\r\n|-----------------+---------|\r\n| 118.173.177.161 |      20 |\r\n| 110.78.145.3    |      16 |\r\n| 171.7.153.7     |      16 |\r\n| 180.183.67.155  |      16 |\r\n| 183.89.65.9     |      16 |\r\n| 202.28.182.5    |      16 |\r\n| 1.47.170.12     |      15 |\r\n| 119.46.184.2    |      15 |\r\n| 125.26.135.219  |      15 |\r\n| 125.26.213.203  |      15 |\r\n<\/pre>\n<h4>Use Particular Log Format<\/h4>\n<p>To use a log format as specified in\u00a0<strong>log_format<\/strong>\u00a0directive, employ the\u00a0<code>-f<\/code>\u00a0option as shown.<\/p>\n<pre>$ sudo ngxtop -f main -l \/var\/log\/nginx\/site1\/access.log\r\n<\/pre>\n<h4>Parse Apache Log From Remote Server<\/h4>\n<p>To parse Apache log file from a remote server with common format, use a command similar to the following (specify your username and remote server IP).<\/p>\n<pre>$ ssh user@remote_server tail -f \/var\/log\/apache2\/access.log | ngxtop -f common\r\n<\/pre>\n<h5>Sample Output<\/h5>\n<pre>running for 20 seconds, 1068 records processed: 53.01 req\/sec\r\n\r\nSummary:\r\n|   count |   avg_bytes_sent |   2xx |   3xx |   4xx |   5xx |\r\n|---------+------------------+-------+-------+-------+-------|\r\n|    1068 |        28026.763 |  1029 |    20 |    19 |     0 |\r\n\r\nDetailed:\r\n| request_path                             |   count |   avg_bytes_sent |   2xx |   3xx |   4xx |   5xx |\r\n|------------------------------------------+---------+------------------+-------+-------+-------+-------|\r\n| \/xxxxxxxxxx                              |     199 |        55150.402 |   199 |     0 |     0 |     0 |\r\n| \/xxxxxxxx\/xxxxx                          |     167 |        47591.826 |   167 |     0 |     0 |     0 |\r\n| \/xxxxxxxxxxxxx\/xxxxxx                    |      25 |         7432.200 |    25 |     0 |     0 |     0 |\r\n| \/xxxx\/xxxxx\/x\/xxxxxxxxxxxxx\/xxxxxxx      |      22 |          698.727 |    22 |     0 |     0 |     0 |\r\n| \/xxxx\/xxxxx\/x\/xxxxxxxxxxxxx\/xxxxxx       |      19 |         7431.632 |    19 |     0 |     0 |     0 |\r\n| \/xxxxx\/xxxxx\/                            |      18 |         7840.889 |    18 |     0 |     0 |     0 |\r\n| \/xxxxxxxx\/xxxxxxxxxxxxxxxxx              |      15 |         7356.000 |    15 |     0 |     0 |     0 |\r\n| \/xxxxxxxxxxx\/xxxxxxxx                    |      15 |         9978.800 |    15 |     0 |     0 |     0 |\r\n| \/xxxxx\/                                  |      14 |            0.000 |     0 |    14 |     0 |     0 |\r\n| \/xxxxxxxxxx\/xxxxxxxx\/xxxxx               |      13 |        20530.154 |    13 |     0 |     0 |     0 |\r\n<\/pre>\n<p>For more usage options, view the ngxtop help message using the following command.<\/p>\n<pre>$ ngxtop -h  \r\n<\/pre>\n<p><strong>ngxtop Github repository<\/strong>:\u00a0<a href=\"https:\/\/github.com\/lebinh\/ngxtop\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/lebinh\/ngxtop<\/a><\/p>\n<p>That\u2019s it for now! In this article, we have explained how to install and use ngxtop in Linux systems. If you have any questions, or extra thoughts to add to this guide, use the comment form below. In addition, if you have come across any similar tools, also let us know and we will be grateful.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/ngxtop-monitor-nginx-log-files-in-real-time-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ngxtop\u00a0is a free open source, simple, flexible, fully configurable and easy-to-use real-time\u00a0top-like monitoring tool\u00a0for nginx server. It gathers data by parsing the nginx access log (default location is always\u00a0\/var\/log\/nginx\/access.log) and displays useful metrics of your nginx server, thus helping you to keep an eye on your web server in real-time. It also allows you to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/ngxtop-monitor-nginx-log-files-in-real-time-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ngxtop \u2013 Monitor Nginx Log Files in Real Time in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13869","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13869"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13869\/revisions"}],"predecessor-version":[{"id":13870,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13869\/revisions\/13870"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}