8. Monitoring 2(Grafana
)
8.1 설치(Public EC2)
- Public EC2에 설치
sudo apt-get install -y apt-transport-https sudo apt-get install -y software-properties-common wget sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key ## repository 연결 echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list sudo apt-get update ## Install the latest OSS release: sudo apt-get install grafana ## reload daemon and start server, check server sudo systemctl daemon-reload sudo systemctl start grafana-server sudo systemctl status grafana-server ## Configure the Grafana server to start at boot: ## sudo systemctl enable grafana-server.service
8.2 Security Group
- Public Security Group
- Port : 3000
- Source : My IP
- 초기 id 비번 admin/admin
- 변경 함
8.3 테스트
- public ec2 ip:3000 접근
8.4 DataSource
8.4.1 PostgreSQL(Direct 연결)
- Private EC2 IP
- SSL 등록이 안되어있으니 SSL 은 Disable
- Save & Test → Connection OK 또는 Data source is working
- 매번 Pull을 진행할때마다 DB에 요청하므로 중간 매개체가 있는 것이 좋다 → Prometheus
8.4.2 Prometheus
- HTTP URL : http://privateec2ip:9090
- Save & Test → Data source is working
8.5 Dashboard
8.5.1 Template
- Dashboard Template을 보고 마음에 드는 항목을 선택하여 적용하면 됨.
PostgreSQL Database | Grafana Labs
- Template ID 복사 해서 Import 에 Template ID를 입력.
Node Exporter Full | Grafana Labs
8.5.2 부하테스트
- 1차 PostgreSQL은 Data Import를 통해 테스트(스크린샷 X)
sudo apt-get install -y stress stress --cpu 1 --timeout 600 # cpu test 100% 다 쓰도록 stress --vm 2 --vm-bytes 200m # ram test 2프로세스 메모리 200m 사용하도록\
9 . 기타(MongoDB, Redis Prometheus)
9.1 Mongo DB 참고
[Grafana]Grafana에 MongoDB 데이터 불러오기
How To Monitor MongoDB with Grafana and Prometheus on Ubuntu 20.04 | DigitalOcean
9.2 Redis 참고
10. Monitoring 3(MongoDB)
해당 내용은 진행이 안될 수 도 있음을 참고하시기 바랍니다.
mkdir mongodb-exporter cd mongodb-exporter wget https://github.com/percona/mongodb_exporter/releases/download/v0.7.1/mongodb_exporter-0.7.1.linux-amd64.tar.gz tar xvzf mongodb_exporter-0.7.1.linux-amd64.tar.gz rm mongodb_exporter-0.7.1.linux-amd64.tar.gz sudo mv mongodb_exporter /usr/local/bin/
10.2 Enabling MongoDB Authentication
mongosh use admin db.createUser({user: "test",pwd: "testing",roles: [{ role: "clusterMonitor", db: "admin" },{ role: "read", db: "local" }]})
10.3 MongoDB URI to Environment variable
vi ~/.profile export MONGODB_URI=mongodb://test:testing@localhost:27017 env | grep mongodb ## outpout PWD=/home/ubuntu/tmp_file/mongodb-exporter MONGODB_URI=mongodb://mongodb_exporter:password@localhost:27017
10.4 Creating a Service for the MongoDB exporter
cd /lib/systemd/system/ sudo vi mongodb_exporter.service [Unit] Description=MongoDB Exporter User=ubuntu [Service] Type=simple Restart=always ExecStart=/usr/local/bin/mongodb_exporter [Install] WantedBy=multi-user.target
10.5 Reload Daemon and Start Service
sudo systemctl daemon-reload sudo systemctl start mongodb_exporter.service sudo systemctl status mongodb_exporter.service
10.6 Check Metrics (Port 9216)
- Port : 9216 을 통해 Metrics 정보 확인
cd ~ sudo curl http://localhost:9216/metrics
10.7 Prometheus Configuration
- MongoDB Exporter 추가
## sudo vi /etc/prometheus/prometheus.yml vi prometheus.yml - job_name: "mongodb" static_configs: - targets: ["localhost:9216"] labels: instance: mongodb
10.8 Grafana Dashboard 추가
MongoDB Overview | Grafana Labs
11. Monitoring 4(Redis)
11.0 Redis 설정 변경
redis-cli CONFIG SET protected-mode no >OK
11.1 DOWNLOAD
wget https://github.com/oliver006/redis_exporter/releases/download/v1.24.0/redis_exporter-v1.24.0.linux-amd64.tar.gz tar -zxvf redis_exporter-v1.24.0.linux-amd64.tar.gz sudo mv redis_exporter /usr/local/bin/
11.2 Systemd 등록
sudo vi /etc/systemd/system/redis_exporter.service [Unit] Description=Redis Exporter Wants=network-online.target After=network-online.target [Service] User=ubuntu Group=ubuntu Type=simple ExecStart=/usr/local/bin/redis_exporter \ -web.listen-address ":9121" \ -redis.addr "redis://10.0.157.31:6379" \ [Install] WantedBy=multi-user.target
11.3 Systemd 실행
sudo systemctl daemon-reload sudo systemctl enable redis_exporter sudo systemctl start redis_exporter
11.4 테스트
curl http://localhost:9121/target curl http://localhost:9121/metrics
11.5 Prometheus 수정.
sudo vi /etc/prometheus/prometheus.yml - job_name: "redis" static_configs: - targets: ["localhost:9121"] labels: instance: redis-db
11.6 서비스 수정
sudo systemctl restart prometheus
11.7 Dashboard 추가
- ID : 11835 추가