{"id":1003,"date":"2018-06-23T14:10:58","date_gmt":"2018-06-23T08:40:58","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=1003"},"modified":"2019-04-30T10:35:05","modified_gmt":"2019-04-30T05:05:05","slug":"log-for-noconnections-from-an-ip","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/log-for-noconnections-from-an-ip\/","title":{"rendered":"Making log entries for total no of connections to a Port From an IP Address."},"content":{"rendered":"<h3>About connections:<\/h3>\n<p>Number of connections is not number of users. Each user browser can open multiple connections at the same time. On the opposite, while more rare, multiple users using the same proxy could appear only through one connection.<\/p>\n<p>In some high connection high load servers, this log would be helpful to monitor and tune the server with number of connections on it.<\/p>\n<p>We can simply sort out the total number of connections in a port by using the command netstat.<\/p>\n<p>There isn\u2019t any log entries with total number of connections. But, we will get the history of resource usage information by installing sar (Systat) on the server.<\/p>\n<p>Then, we can create a cronjob to monitor the server connections. In this post I am explaining the method to create a log for total number of connection to server. Before creating a script and setting cron, you must have the idea to use the command \u201cnetstat\u201d to list total number of connections in server.<\/p>\n<p>By considering the service Apache, we can sort it by using the port 80.<\/p>\n<pre>netstat -ntlp|grep :80|wc -l<\/pre>\n<p><strong>Example:<\/strong><\/p>\n<pre>netstat -ntlp|grep :80|wc -l\r\n110<\/pre>\n<p>If you want to monitor the total connection to your Apache service at times, create a cronjob to save this to a file as a log. Here I am using the command \u201cdate\u201d to get the time details when the \u201cnetstat\u201d taking the connection log. Please do follow these steps to create a log with <a  href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/how-to-secure-website-with-ssl\/\" title=\"connection details\" alt=\"connection details\">connection details<\/a>.<strong><br \/>\n<\/strong><\/p>\n<p><strong>Step 1 :<\/strong>\u00a0Create a file to get the log.<\/p>\n<pre>touch connection.txt\r\n<\/pre>\n<p><strong>Step 2 :<\/strong>\u00a0Create a script for the same.<\/p>\n<p>2.1 \u2013&gt; Use the command \u2018date\u2019 for time details.<br \/>\n2.2 \u2013&gt; Use \u2018echo\u2019 to print your instructions.<br \/>\n2.3 \u2013&gt; Use \u2018netstat\u2019 for connection details.<\/p>\n<p>Simply;<\/p>\n<pre>echo \"Time\"\r\ndate\r\necho \"Total no: of connection in port 80\"\r\nnetstat -ntlp|grep :80|wc -l\r\necho <strong>\"\"\r\n<\/strong><\/pre>\n<p><strong>Step 3 :<\/strong>\u00a0Change the <a  href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/ftp-passive-ports-range-cpanel\/\" title=\"file\" alt=\"file\">file<\/a> permission as executable.<\/p>\n<pre>chmod 755 connections.log\r\n<\/pre>\n<p><strong>Step 4 :<\/strong>\u00a0Test the script from the location.<\/p>\n<pre>.\/connection.txt\r\nTime\r\nWed Jun 20 10:42:02 MSD 2018\r\nTotal no: of connection in port 80\r\n1\r\n<\/pre>\n<p><strong>Step 5 :<\/strong>\u00a0Create a file to log the connection information.<\/p>\n<pre>touch connections.log\r\n<\/pre>\n<p><strong>Step 6 :<\/strong>\u00a0Create a cronjob to execute this periodically.<\/p>\n<pre>crontab -e\r\n\r\n*\/30 * * * * \/root\/connection.txt &gt;&gt; connections.log\r\n<\/pre>\n<p>DONE!!<\/p>\n<p>This will save the total number of connections to the file connections.log.<\/p>\n<p>If you like the above post <a href=\"https:\/\/www.coimbatorewebhosting.com\/blog\/how-to-monitor-the-centos7-apache-server-using-cacti\/\">click<\/a> here to know the process how to monitor the centos <a href=\"https:\/\/httpd.apache.org\/\" rel=\"nofollow noopener\" target=\"_blank\">Apache serve<\/a> using cacti.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About connections: Number of connections is not number of users. Each user browser can open multiple connections at the same time. On the opposite, while more rare, multiple users using the same proxy could appear only through one connection. In some high connection high load servers, this log would be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1018,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[17,3],"tags":[74,75,76],"class_list":["post-1003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","category-linux","tag-high-connection","tag-high-load-servers","tag-resource-usage"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2018\/06\/logentries-1.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-gb","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1003"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1003\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/1018"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}