-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws-cloudwatch-boomi-monitor-amazon-linux-2.sh
200 lines (176 loc) · 6.44 KB
/
aws-cloudwatch-boomi-monitor-amazon-linux-2.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/sh
# Script must be ran as root
# Developed for Amazon Linux 2
# Varibles
BOOMI_INSTALL_DIR=/home/ec2-user/Boomi_AtomSphere/Molecule/Molecule_cloudwatch_molecule
CLOUDWATCH_LOG_GROUP_NAME=boomi-molecule-cloudwatch-02
# Install collectd
echo "Installing collectd ..."
yum install -y amazon-linux-extras
amazon-linux-extras install -y java-openjdk11
amazon-linux-extras install -y collectd
yum install -y collectd-java
yum install -y collectd-generic-jmx
# Disable SELinux for collectd
echo "Disabling SELinux..."
setenforce 0
sed -i "s%SELINUX=enforcing%SELINUX=disabled%g" /etc/selinux/config
# Looking for libjvm.so from the java-openjdk11 package that was installed
LIBJVM_SYMLINK=/usr/lib64/libjvm.so
if [ -L ${LIBJVM_SYMLINK} ] && [ -e ${LIBJVM_SYMLINK} ]; then
echo "Synlink to libjvm.so already exists. Skipping..."
else
libjvm_location=$(sudo find / -name libjvm.so | grep -m 1 'java-11-openjdk')
echo "libjvm_location: $libjvm_location"
sudo ln -s $libjvm_location /usr/lib64/libjvm.so
fi
# Load collectd config file
HOST_NAME=$(hostname | xargs)
echo "LoadPlugin logfile
LoadPlugin java
LoadPlugin network
LoadPlugin write_log
<Plugin logfile>
LogLevel warning
File \"/var/log/collectd.log\"
Timestamp true
PrintSeverity false
</Plugin>
<Plugin \"java\">
# required JVM argument is the classpath
# JVMArg \"-Djava.class.path=/installpath/collectd/share/collectd/java\"
# Since version 4.8.4 (commit c983405) the API and GenericJMX plugin are
# provided as .jar files.
JVMARG \"-Djava.class.path=/usr/share/collectd/java/collectd-api.jar:/usr/share/collectd/java/generic-jmx.jar\"
LoadPlugin \"org.collectd.java.GenericJMX\"
<Plugin \"GenericJMX\">
# Memory usage by memory pool.
<MBean \"memory\">
ObjectName \"java.lang:type=Memory,*\"
InstancePrefix \"memory-heap\"
#InstanceFrom \"name\"
<Value>
Type \"memory\"
#InstanceFrom \"\"
Table false
Attribute \"HeapMemoryUsage.max\"
InstancePrefix \"HeapMemoryUsage.max\"
</Value>
<Value>
Type \"memory\"
#InstanceFrom \"\"
Table false
Attribute \"HeapMemoryUsage.used\"
InstancePrefix \"HeapMemoryUsage.used\"
</Value>
</MBean>
<MBean \"garbage_collector\">
ObjectName \"java.lang:type=GarbageCollector,*\"
InstancePrefix \"gc-\"
InstanceFrom \"name\"
<Value>
Type \"invocations\"
#InstancePrefix \"\"
#InstanceFrom \"\"
Table false
Attribute \"CollectionCount\"
</Value>
<Value>
Type \"total_time_in_ms\"
InstancePrefix \"collection_time\"
#InstanceFrom \"\"
Table false
Attribute \"CollectionTime\"
</Value>
</MBean>
<MBean \"os\">
ObjectName \"java.lang:type=OperatingSystem\"
InstancePrefix \"os-\"
InstanceFrom \"name\"
<Value>
Type \"guage\"
InstancePrefix \"os-open-file-\"
Attribute \"OpenFileDescriptorCount\"
</Value>
<Value>
Type \"guage\"
InstancePrefix \"os-load-average\"
Attribute \"SystemLoadAverage\"
</Value>
</MBean>
<Connection>
Host \"${HOST_NAME}\"
ServiceURL \"service:jmx:rmi://localhost:5002/jndi/rmi://localhost:5002/jmxrmi\"
Collect \"memory\"
Collect \"garbage_collector\"
</Connection>
</Plugin>
</Plugin>
<Plugin \"write_log\">
Format JSON
</Plugin>
<Plugin network>
<Server \"127.0.0.1\" \"25826\">
SecurityLevel None
</Server>
</Plugin>
" | tee /etc/collectd.conf
# Install Amazon Cloudwatch Agent
echo "Installing Amaon Cloudwatch Agent ..."
yum install -y amazon-cloudwatch-agent
AWS_CLOUDWATCH_AGENT_HOME="/opt/aws/amazon-cloudwatch-agent/bin"
INTERNAL_IP_ADDRESS=$(hostname -I | sed 's/\./_/g' | xargs)
echo "{
\"agent\": {
\"metrics_collection_interval\": 30,
\"run_as_user\": \"root\"
},
\"logs\": {
\"logs_collected\": {
\"files\": {
\"collect_list\": [
{
\"file_path\": \"${BOOMI_INSTALL_DIR}/logs/*.container.${INTERNAL_IP_ADDRESS}.log\",
\"log_group_name\": \"${CLOUDWATCH_LOG_GROUP_NAME}\",
\"log_stream_name\": \"{instance_id}\",
\"timestamp_format\": \"%b %d, %Y %I:%M:%S %p %Z\",
\"multi_line_start_pattern\": \"{datetime_format}\"
}
]
}
}
},
\"metrics\": {
\"metrics_collected\": {
\"collectd\": {
\"metrics_aggregation_interval\": 60,
\"service_address\": \"udp://127.0.0.1:25826\",
\"collectd_security_level\": \"none\"
},
\"disk\": {
\"measurement\": [
\"used_percent\"
],
\"metrics_collection_interval\": 30,
\"resources\": [
\"*\"
]
},
\"mem\": {
\"measurement\": [
\"mem_used_percent\"
],
\"metrics_collection_interval\": 30
}
}
}
}" | tee $AWS_CLOUDWATCH_AGENT_HOME/amazon-cloudwatch-agent.json
$AWS_CLOUDWATCH_AGENT_HOME/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:$AWS_CLOUDWATCH_AGENT_HOME/amazon-cloudwatch-agent.json
echo "Setting up systemd for collectd and amazon-cloudwatch-agent"
systemctl enable collectd
systemctl stop collectd
systemctl start collectd
systemctl enable amazon-cloudwatch-agent
systemctl stop amazon-cloudwatch-agent
systemctl start amazon-cloudwatch-agent
echo "Installation complete!"