Skip to content

Commit 4bd340b

Browse files
committed
add monitor service and configuration to cland by following operation: 1. install packages. 2. generate configuration file. 3.update firewall rules. 4. CL api mapping.
Signed-off-by: zhesmart <[email protected]> modify some add steps to hyber, add service to fix memory useage cannot get correct value. Signed-off-by: zhesmart <[email protected]>
1 parent c7d6e1e commit 4bd340b

File tree

11 files changed

+1730
-8
lines changed

11 files changed

+1730
-8
lines changed

deploy/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ $hname ansible_host=$myip ansible_ssh_private_key_file=$cland_ssh_dir/cland.key
101101
102102
[database]
103103
$hname ansible_host=$myip ansible_ssh_private_key_file=$cland_ssh_dir/cland.key
104+
105+
[monitor]
106+
$hname ansible_host=$myip ansible_ssh_private_key_file=$cland_ssh_dir/cland.key
104107
EOF
105108
}
106109

deploy/cloudland.yml

+7
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@
4343
become_user: root
4444
roles:
4545
- {role: wds, become: yes, tags: [wds]}
46+
47+
# deploy monitor
48+
- name: install monitor
49+
hosts: monitor
50+
become_user: root
51+
roles:
52+
- {role: monitor, become: yes, tags: [monitor]}

deploy/roles/cland/tasks/main.yml

-3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,3 @@
9292
state: started
9393
tags: [fe_srv]
9494

95-
- name: allow cloudland necessary ports
96-
script: firewall.sh
97-
tags: [firewall]

deploy/roles/hyper/files/firewall.sh

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
iptables -D FORWARD -j REJECT --reject-with icmp-host-prohibited
44
iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited
55

6+
# Open the Prometheus port (default 9100), allowing inbound TCP traffic to port 9100
7+
iptables -A INPUT -p tcp --dport 9100 -j ACCEPT
8+
# Open the Grafana port (default 9177), allowing inbound TCP traffic to port 9177
9+
iptables -A INPUT -p tcp --dport 9177 -j ACCEPT
10+
611
for chain in $(iptables -S | grep secgroup | awk '{print $2}'); do
712
iptables -X $chain
813
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
while true; do
3+
echo '# HELP guest_kvm_vm_memory_usage_bytes Memory usage of KVM VMs in bytes'
4+
echo '# TYPE guest_kvm_vm_memory_usage_bytes gauge'
5+
for uuid in $(virsh list --uuid); do
6+
mem_usage=$(virsh dommemstat "$uuid" | awk '/rss/ {print $2}')
7+
if [[ ! -z "$mem_usage" ]]; then
8+
echo "guest_kvm_vm_memory_usage_bytes{uuid=\"$uuid\"} $((mem_usage * 1024))"
9+
fi
10+
done > /var/lib/node_exporter/guest_kvm_vm_memory_usage.prom
11+
sleep 15
12+
done

deploy/roles/hyper/tasks/main.yml

+96-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- name: install packages for kvm
1010
apt:
11-
name: ['qemu-system-x86', 'qemu-utils', 'bridge-utils', 'ipcalc', 'ipset', 'keepalived', 'iputils-arping', 'libvirt-daemon', 'libvirt-daemon-system', 'libvirt-daemon-system-systemd', 'libvirt-clients', 'dnsmasq', 'dnsmasq-utils', 'conntrack']
11+
name: ['qemu-system-x86', 'qemu-utils', 'bridge-utils', 'ipcalc', 'ipset', 'keepalived', 'iputils-arping', 'libvirt-daemon', 'libvirt-daemon-system', 'libvirt-daemon-system-systemd', 'libvirt-clients', 'dnsmasq', 'dnsmasq-utils', 'conntrack', 'prometheus-libvirt-exporter', 'prometheus-node-exporter']
1212
state: present
1313
ignore_errors: yes
1414
tags: [be_pkg]
@@ -264,3 +264,98 @@
264264
value: '16777216'
265265
reload: yes
266266
tags: [sysctl]
267+
268+
- name: Create directory for monitor scripts
269+
file:
270+
path: /opt/cloudland/scripts/monitor
271+
state: directory
272+
owner: root
273+
group: root
274+
mode: '0755'
275+
tags: [monitor]
276+
277+
- name: Copy guest VM memory exporter script
278+
copy:
279+
src: files/guest_kvm_vm_memory_export.sh
280+
dest: /opt/cloudland/scripts/monitor/guest_kvm_vm_memory_export.sh
281+
mode: '0755'
282+
owner: root
283+
group: root
284+
tags: [monitor]
285+
286+
287+
- name: Ensure systemd override directory exists
288+
file:
289+
path: /etc/systemd/system/prometheus-node-exporter.service.d
290+
state: directory
291+
owner: root
292+
group: root
293+
mode: '0755'
294+
tags: [monitor]
295+
296+
297+
- name: Create directory for node_exporter textfile
298+
file:
299+
path: /var/lib/node_exporter
300+
state: directory
301+
owner: root
302+
group: root
303+
mode: '0755'
304+
tags: [monitor]
305+
306+
- name: Configure Node Exporter with textfile directory
307+
become: true
308+
copy:
309+
dest: /etc/systemd/system/prometheus-node-exporter.service.d/override.conf
310+
content: |
311+
[Service]
312+
ExecStart=
313+
ExecStart=/usr/bin/prometheus-node-exporter --collector.textfile.directory=/var/lib/node_exporter
314+
mode: '0644'
315+
owner: root
316+
group: root
317+
tags: [monitor]
318+
319+
- name: Create systemd service for guest VM memory export
320+
copy:
321+
dest: /etc/systemd/system/guest_kvm_vm_memory_usage.service
322+
mode: '0644'
323+
owner: root
324+
group: root
325+
content: |
326+
[Unit]
327+
Description=Guest VM Memory Exporter Service
328+
After=network.target
329+
330+
[Service]
331+
Type=simple
332+
ExecStart=/opt/cloudland/scripts/monitor/guest_kvm_vm_memory_export.sh
333+
Restart=always
334+
User=root
335+
336+
[Install]
337+
WantedBy=multi-user.target
338+
tags: [monitor]
339+
340+
- name: Reload systemd to recognize new service
341+
systemd:
342+
daemon_reload: yes
343+
tags: [monitor]
344+
345+
- name: Enable guest VM memory exporter service
346+
systemd:
347+
name: guest_kvm_vm_memory_usage
348+
enabled: yes
349+
state: started
350+
tags: [monitor]
351+
352+
353+
- name: Reload and restart prometheus services
354+
systemd:
355+
name: "{{ item }}"
356+
daemon_reload: yes
357+
state: restarted
358+
with_items:
359+
- 'prometheus-libvirt-exporter'
360+
- 'prometheus-node-exporter'
361+
tags: [monitor]
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# Open the Node Exporter port (default 9100), allowing inbound TCP traffic to port 9100
4+
iptables -A INPUT -p tcp --dport 9100 -j ACCEPT
5+
6+
# Open the Libvirt Exporter port (default 9177), allowing inbound TCP traffic to port 9177
7+
iptables -A INPUT -p tcp --dport 9177 -j ACCEPT
8+
9+
# Open the Prometheus port (default 9090), allowing inbound TCP traffic to port 9090
10+
iptables -A INPUT -p tcp --dport 9090 -j ACCEPT
11+
12+
# Open the Grafana port (default 3000), allowing inbound TCP traffic to port 3000
13+
iptables -A INPUT -p tcp --dport 3000 -j ACCEPT
14+
# Allow outbound Node Exporter traffic (port 9100)
15+
iptables -A OUTPUT -p tcp --dport 9100 -j ACCEPT
16+
17+
# Allow outbound Libvirt Exporter traffic (port 9177)
18+
iptables -A OUTPUT -p tcp --dport 9177 -j ACCEPT
19+
20+
# Allow outbound Prometheus traffic (port 9090)
21+
iptables -A OUTPUT -p tcp --dport 9090 -j ACCEPT
22+
23+
# Allow outbound Grafana traffic (port 3000)
24+
iptables -A OUTPUT -p tcp --dport 3000 -j ACCEPT
25+
26+
/sbin/iptables-save -c > /etc/iptables.rules
27+

0 commit comments

Comments
 (0)