[모니터링] 1. InfluxDB + Telegraf + Grafana 설치(CentOS7)

 

1. InfluxDB 설치


 

Influxdata에서 제공하는 influxdb.repo 저장소를 Yum Repository에 추가합니다.

(influxdb.repo 정보는 influxdata 홈페이지에서 가져왔습니다.)

cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

 

저장소 리스트를 확인하여 정상적으로 추가된 것을 확인했습니다.

InfluxDB 설치 및 구동

# yum install influxdb # 설치
# systemctl start influxdb # 구동
# systemctl enable influxdb # 활성화(부팅시 자동으로 구동이 되도록)

 

InfluxDB는 8086, 8088 포트를 사용합니다.

8086 포트 : InfluxDB의 HTTP API 통신을 위한 용도

8088 포트 : 백업과 리스토어를 위한 RPC 서비스 용도

[root@linux-1 ~]# netstat  -lntup | grep influx
tcp        0      0 127.0.0.1:8088          0.0.0.0:*               LISTEN      1729/influxd
tcp6       0      0 :::8086                 :::*                    LISTEN      1729/influxd

 

DB에 접속하여 'test1' 계정을 하나 생성하겠습니다

[root@linux-1 ~]# influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
> show users
user  admin
----  -----
admin true
> CREATE USER test1 WITH PASSWORD 'test1' WITH ALL PRIVILEGES
> show users
user  admin
----  -----
admin true
test1 true

 

 

2. Telegraf 설치


 

Telegraf는 1번의 influxdb.repo를 통해 설치할 수 있습니다.

# yum install telegraf

 

 

telegraf.conf 파일은 3가지 설정으로 나뉩니다.

agent - 수집 및 전송 주기 관련 설정

outputs - 수집된 데이터를 어디로 보낼지 지정

inputs - 수집할 항목에 대한 상세 설정

 

/etc/telegraf/telegraf.conf 설정파일을 아래 내용으로 바꿔줍니다.

[global_tags]

# Configuration for telegraf agent
[agent]
    interval = "10s"
    debug = false
    hostname = "server-hostname"
    round_interval = true
    flush_interval = "10s"
    flush_jitter = "0s"
    collection_jitter = "0s"
    metric_batch_size = 1000
    metric_buffer_limit = 10000
    quiet = false
    logfile = ""
    omit_hostname = false

###############################################################################
#                                  OUTPUTS                                    #
###############################################################################

[[outputs.influxdb]]
    urls = ["http://localhost:8086"] # InfluxDB가 설치된 서버의 IP를
    database = "telegraf" # 데이터바에스 이름, 생성이 되어있지 않으면 자동 생성됨
    timeout = "10s"
    username = "admin" # InflusXDB 기본 계정
    password = "admin"
    retention_policy = ""

###############################################################################
#                                  INPUTS                                     #
###############################################################################

[[inputs.cpu]]
    percpu = true
    totalcpu = true
    collect_cpu_time = false
    report_active = false
[[inputs.disk]]
    ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
[[inputs.io]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.system]]
[[inputs.swap]]
[[inputs.netstat]]
[[inputs.processes]]
[[inputs.kernel]]

 

Telegraf 구동

# systemctl start telegraf
# systemctl enable telegraf

 

 

데이터가 정삭적으로 DB에 쌓이고 있는지 간단히 확인해 볼수 있습니다.

[root@linux-1 telegraf]# influx  # InfluxDB접속
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
> use telegraf # telegraf Database 접속 
Using database telegraf 
> SELECT * FROM disk WHERE time > now() - 30s;  # disk 정보 확인
name: disk
time                device free        fstype host            inodes_free inodes_total inodes_used mode path  total                                 used       used_percent
----                ------ ----        ------ ----            ----------- ------------ ----------- ---- ----  -----                                 ----       ------------
1588342680000000000 sda1   915038208   xfs    server-hostname 523961      524288       327         rw   /boot 1063256                          064  148217856  13.939996301775148
1588342680000000000 sda3   15089336320 xfs    server-hostname 8264164     8300544      36380       rw   /     1698902                          8352 1899692032 11.181875694358721
1588342690000000000 sda1   915038208   xfs    server-hostname 523961      524288       327         rw   /boot 1063256                          064  148217856  13.939996301775148
1588342690000000000 sda3   15089225728 xfs    server-hostname 8264164     8300544      36380       rw   /     1698902                          8352 1899802624 11.182526655659796

 

 

 

 

3. Grafana 설치


 

grafana.repo 저장소를 Yum Repository에 추가합니다.

cat <<EOF | sudo tee /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

 

Grafana 설치 및 구동

# yum install grafana # 설치
# systemctl start grafana-server # 구동
# systemctl enable grafana-server # 활성화

 

Grafana는 3000포트를 사용합니다.

이제 웹브라우저에서  "[서버IP]:3000" 입력하여 Grafana 대시보드에 접속합니다.

[root@linux-1 ~]# netstat -lntup | grep grafana
tcp6       0      0 :::3000                 :::*                    LISTEN      866/grafana-server

 

 

(Defalt ID/PW : admin/admin)

 

Data Source를 추가할 차례입니다, 어떤 DB로에서 데이터를 가져올지에 대한 설정입니다.

"Add Data Source"를 선택합니다.

 

InfluxDB를 선택합니다.

 

InfluxDB 정보를 입력합니다.

Name : 이름을 지정합니다

URL : DB 접속 URL 입력합니다

InfluxDB Details : Database 이름을 입력합니다(별도 새성을 안 했으면 telegraf가 기본으로 생성됩니다.)

계정 정보는 위에서 생성한 'test1' 계정 정보를 입력합니다.

 

 

이번엔 대시보드 생성 차례입니다. 다시 홈 화면으로 와서 "New dashboard"를 선택합니다

 

Add Query 선택하시면 쿼리문을 작성할수 있는 화면이 보입니다.

 

저는 sda3 "/" 파티션 사용률을 한번 설정해 보았습니다, 

 

그래프 확인!!!

 

왼쪽 메뉴의 Visualization에서는 그래프 모양, 색깔, X, Y 축등 원하는 대로 수정을 할 수 있습니다.

 

처음 진행 하시는 분들은 쿼리문 작성이 익숙하지 않으실 텐데요, 

그런 분들은 우선 Grafana 홈페이지에 접속하셔서

다른 사람들이 올려둔 대시보드를 그대로 가져다 사용하시는것을 추천드립니다.

원하시는 컨셉과 비슷한 대시보드를 적용하시고

이후에 하나씩 수정해 나가시면서 파악하시는 게 훨씬 더 수월하실 겁니다.

 

저는 아래 대시보드를 가져왔습니다. 아래 주소에 접속해서 JSON형식 파일을 다운로드합니다.

그리고 telegraf.conf 내용을 그대로 복사해서

/etc/telegref/telegref.conf 파일에 덮어쓰고 telegref 서비스를 재구 동합니다.

 

Host Dashboard dashboard for Grafana

Data visualization & monitoring with support for Graphite, InfluxDB, Prometheus, Elasticsearch and many more databases

grafana.com

 

대시보드 -> Import -> 다운로드한 JSON 파일을 적용합니다.

 

적용 확인!! 

이제 좀 있어 보이는? 모니터링 시스템 구축이 완료되었습니다.

.

댓글

Designed by JB FACTORY

loading