Monitoring Instances OpenStack Menggunakan Prometheus dan Grafana

Ach.Chusnul Chikam
4 min readSep 7, 2020

--

==== Instalasi Prometheus Server ====

useradd -m -s /sbin/nologin prometheus
mkdir /etc/prometheus
mkdir /var/lib/prometheus
chown prometheus /var/lib/prometheus/
yum -y install wget
wget https://github.com/prometheus/prometheus/releases/download/v2.20.0/prometheus-2.20.0.linux-amd64.tar.gz -P /tmp
cd /tmp/
tar -zxpvf prometheus-2.20.0.linux-amd64.tar.gz
cd /tmp/prometheus-2.20.0.linux-amd64/
cp prometheus /usr/local/bin
cp promtool /usr/local/bin
cp prometheus.yml /etc/prometheus/
vi /etc/prometheus/prometheus.yml
-------
- job_name: 'openstack-sd'
openstack_sd_configs:
- identity_endpoint:
http://keystone_url:5000/v3
username: admin
project_name: admin
password: password
role: instance
region: RegionOne
domain_name: Default
port: 9100
-------

./promtool check config /etc/prometheus/prometheus.yml
cd
systemctl start firewalld
firewall-cmd --add-port=9090/tcp --permanent
firewall-cmd --reload

cat << EOF >/etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Time Series Collection and Processing Server
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries \

--web.external-url=http://ip_prometheus_server:9090

[Install]
WantedBy=default.target

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload
systemctl start prometheus
systemctl enable prometheus
systemctl status prometheus
netstat -tunlp | grep 9090

==== Instalasi Node Exporter pada Host ====

useradd -m -s /sbin/nologin node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar -zxpvf node_exporter-0.18.1.linux-amd64.tar.gz
tree node_exporter-0.18.1.linux-amd64
cp node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin
chown node_exporter:node_exporter /usr/local/bin/node_exporter

cat << EOF >/etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=default.target

EOF

firewall-cmd --add-port=9100/tcp --permanent
firewall-cmd --reload
systemctl daemon-reload
systemctl start node_exporter
systemctl enable node_exporter
systemctl status node_exporter
vi /etc/prometheus/prometheus.yml
---
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']

---
systemctl restart prometheus
netstat -tunlp | grep 9100

==== Instalasi Grafana ====

cat << EOF >/etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF

yum repolist
yum -y install grafana
rpm -qi grafana
firewall-cmd --add-port=3000/tcp --permanent
firewall-cmd --reload
systemctl daemon-reload
systemctl start grafana-server
systemctl enable grafana-server
systemctl status grafana-server
netstat -tunlp | grep 3000

==== Menanamkan Node Exporter ke Dalam Image ====

# wget http://cloud.centos.org/centos/8/x86_64/images/CentOS-8-GenericCloud-8.2.2004-20200611.2.x86_64.qcow2 -O ~/CentOS-8-x86_64.qcow2
# yum -y install libguestfs-tools-c.x86_64
# export LIBGUESTFS_BACKEND=direct
# virt-customize -a CentOS-8-x86_64.qcow2 --root-password password:root
# guestfish -i --network -a CentOS-8-x86_64.qcow2
><fs> command "yum -y install wget"
><fs> command "cd /"
><fs> command "wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz"
><fs> command "useradd -m -s /sbin/nologin node_exporter"
><fs> command "tar -zxpvf node_exporter-0.18.1.linux-amd64.tar.gz"
><fs> command "cp node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin"
><fs> command "chown node_exporter:node_exporter /usr/local/bin/node_exporter"
><fs> vi /etc/systemd/system/node_exporter.service
---
[Unit]
Description=Prometheus Node Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target

---
><fs> command "systemctl daemon-reload"
><fs> command "systemctl enable node_exporter.service"
><fs> command "systemctl start node_exporter.service"
><fs> selinux-relabel /etc/selinux/targeted/contexts/files/file_contexts /
><fs> exit

Setelah menanamkan node exporter ke dalam sebuah image, selanjutnya upload image tersebut ke Glance. Selanjutnya buat instance menggunakan image custom tadi. Ketika instance sudah berjalan, maka otomatis metrics dari instance akan terbaca oleh prometheus server dan akan terlihat pada grafana.

Sekian panduan Monitoring Instances OpenStack Menggunakan Prometheus dan Grafana. Selamat mencoba.
Good Luck! :)

Lihat panduan lainnya

Terima kasih,
#s0mprett0_tenan

--

--

Ach.Chusnul Chikam

Cloud Consultant | RHCSA | CKA | AWS SAA | OpenStack | OpenShift Certified | Google Cloud ACE | LinkedIn: https://www.linkedin.com/in/achchusnulchikam