|
8 | 8 |
|
9 | 9 | - name: install packages for kvm
|
10 | 10 | 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'] |
12 | 12 | state: present
|
13 | 13 | ignore_errors: yes
|
14 | 14 | tags: [be_pkg]
|
|
264 | 264 | value: '16777216'
|
265 | 265 | reload: yes
|
266 | 266 | 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] |
0 commit comments