-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.sh
31 lines (27 loc) · 1.07 KB
/
monitor.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/bash
#
# Some basic monitoring functionality; Tested on Amazon Linux 2
#
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
INSTANCE_TYPE=$(curl -s http://169.254.169.254/latest/meta-data/instance-type)
AVAILABILITY_ZONE=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
AMI_ID=$(curl -s http://169.254.169.254/latest/meta-data/ami-id)
SECURITY_GROUP=$(curl -s http://169.254.169.254/latest/meta-data/security-groups)
IPV4=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)
MEMORYUSAGE=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
PROCESSES=$(expr $(ps -A | grep -c .) - 1)
HTTPD_PROCESSES=$(ps -A | grep -c httpd)
echo "Instance ID: $INSTANCE_ID"
echo "Memory utilisation: $MEMORYUSAGE"
echo "No of processes: $PROCESSES"
echo "IPV4 Address: $IPV4"
echo "Instance Type: $INSTANCE_TYPE"
echo "AMI id: $AMI_ID"
echo "Availability Zone: $AVAILABILITY_ZONE"
echo "Security group: $SECURITY_GROUP"
if [ $HTTPD_PROCESSES -ge 1 ]
then
echo "Web server is running"
else
echo "Web server is NOT running"
fi