How to use CloudWatch to monitor the number of active connections to a Lightsail server

0

Is there any way to use CloudWatch to monitor the number of active connections to a Lightsail/EC2 server? I know there's such an indicator for the Application Load Balancer, however, there's no load balancer in my infrastructure. The number of active web users/connections is one of the most popular indicators and we want to find out more about it. Thank you.

asked a year ago783 views
1 Answer
2

Hello,

LightSail comes with limited set of features and currently there is no direct way to monitor number of active web connections to LightSail web server using CloudWatch. However LightSail can intergrate with CloudWatch and CloudWatch provides some netstat related metrics that can come handy to get information related to TCP/UDP connection state like :

  • netstat_tcp_established : The number of TCP connections established.
  • netstat_tcp_close : The number of TCP connections with no state.
  • netstat_tcp_syn_sent : The number of TCP connections waiting for a matching connection request after having sent a connection request.

For a complete list of metrics provided by CloudWatch to intergrate with LightSail, please refer [1] and [2].

The steps to configure a LightSail instance to send data to Amazon CloudWatch is available in following article:

[+] https://aws.amazon.com/blogs/compute/monitoring-memory-usage-lightsail-instance/

This article has steps to collect memory related data, however for collecting netstat data you can change the cloudwatch configuration file mentioned in Step 5 of the article with netstat values.

For your reference I have provided a sample Cloudwatch configuration file to collect the three netstat metrics (tcp_established, tcp_close and tcp_syn_sent).

Configuration file for collecting tcp_established, tcp_sync_sent and tcp_close:

	{
	  "agent": {
	    "metrics_collection_interval": 10,
	    "run_as_user": "root"
	  },
	  "metrics": {
	    "namespace" : "MyCustomNamespace",
	    "metrics_collected": {
	      "netstat": {
	        "measurement": [
	          "tcp_established",
	          "tcp_syn_sent",
	          "tcp_close"
	        ],
	        "metrics_collection_interval": 10
	      }
	    }
	  }
	}

The above netstat metric will provide approximate count of the web connection. In case you need the exact count of web connection then you can consider using EC2, as it provide additional features which allows to create and use custom CloudWatch metrics. So, basically you can create a script which collects data of active connection and then report it to amazon-cloudwatch. For more details you can refer [3] and [4].

Note: AWS does not endorse any third party articles. These links are researched and provided as a best effort attempt to help you.

Hope it helps!!

Resources:

  1. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html
  2. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/metrics-collected-by-CloudWatch-agent.html
  3. https://aws.amazon.com/premiumsupport/knowledge-center/cloudwatch-push-custom-metrics/
  4. https://www.techtarget.com/searchcloudcomputing/tutorial/How-to-create-EC2-custom-metrics-with-Amazon-CloudWatch
AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions