cat > /etc/yum.repos.d/prometheus.repo <<'EOF'
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300
EOF
dnf -y install node_exporter
INSTALLED_APPS = [
...
'django_prometheus',
]
MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
# All your other middlewares go here, including the default
# middlewares like SessionMiddleware, CommonMiddleware,
# CsrfViewmiddleware, SecurityMiddleware, etc.
'django_prometheus.middleware.PrometheusAfterMiddleware',
]
DATABASES = {
'default': {
'ENGINE': 'django_prometheus.db.backends.mysql',
...
},
}
urlpatterns = [
...
path('monitor/', include('django_prometheus.urls')),
]
systemctl restart httpd
systemctl restart node_exporter
cat > /etc/yum.repos.d/prometheus.repo <<'EOF'
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300
EOF
dnf -y install node_exporter
systemctl restart mysqld
systemctl restart node_exporter
다른 vm에 haproxy 설치
setenforce 0 (로컬 방화벽 중단)
systemctl stop firewalld (방화벽 중단)
설정
vi /etc/haproxy/haproxy.cfg
가장 아랫줄에 위의 그림처럼 작성해주자.
분산 처리해주는 알고리즘 RR 알고리즘을 사용했는데 운영체제때 다루었던 알고리즘이기에 넘어가겠다.
option mysql-check user 뒤에 비밀번호를 제거한 mysql 사용자 명인 remote를 써주자(만약 remote가 아니라면 본인이 설정한 이름)
그 밑에 server (django 서버명) (그 서버의 ip):80 check
systemctl restart haproxy 로 haproxy 서비스 재시작.
현재 haproxy를 설치한 vm의 ip주소:9000/haproxy_stats로 접속해보자.
cat > /etc/yum.repos.d/prometheus.repo <<'EOF'
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300
EOF
dnf -y install node_exporter
systemctl restart haproxy
systemctl restart node_exporter
레포지토리 추가
cat > /etc/yum.repos.d/prometheus.repo <<'EOF'
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300
EOF
설치 파일
설정 파일 수정
- job_name: node
static_configs:
- targets: ['[네이밍한 이름]:9100', '[네이밍한 이름]:9100', '[네이밍한 이름]:9100', '[네이밍한 이름]:9100', '[네이밍한 이름]:9100']
- job_name: django
metrics_path: /monitor/metrics
static_configs:
- targets: ['장고1IP:80', '장고2IP:80']
labels:
app: 'myblog'
vi /etc/grafana/grafana.ini
35번 라인의 http_addr를 0.0.0.0 으로 수정해주자.
위의 그림처럼 각 노드들 별로 가상 컴퓨터 사용량을 확인할 수 있다.
그리고 다시 import 클릭 후 9528번 import
This article was incredibly helpful! I was struggling to integrate Prometheus and Grafana with Django, and the step-by-step instructions here made it a lot easier to set up. I was having a hard time with configuring the settings.py
and urls.py
files, but the guide provided clear instructions that helped me understand exactly what I needed to do.
It was also nice to see the details on setting up Prometheus, MySQL, and HAProxy, which were crucial to the entire setup. It definitely saved me a lot of time, and I now have a fully working monitoring system in place!
Also, while looking for more setup guides, I came across this useful guide on how to install Tomcat on Ubuntu 24.04. If you're working on similar setups, it might help you out too!
Thanks again for sharing this article! It truly helped me a lot!
This article was incredibly helpful! I was struggling to integrate Prometheus and Grafana with Django, and the step-by-step instructions here made it a lot easier to set up. I was having a hard time with configuring the
settings.py
andurls.py
files, but the guide provided clear instructions that helped me understand exactly what I needed to do.It was also nice to see the details on setting up Prometheus, MySQL, and HAProxy, which were crucial to the entire setup. It definitely saved me a lot of time, and I now have a fully working monitoring system in place!
Also, while looking for more setup guides, I came across this useful guide on how to install Tomcat on Ubuntu 24.04. If you're working on similar setups, it might help you out too!
Thanks again for sharing this article! It truly helped me a lot!