본문 바로가기
Zabbix

Elastic stack zabbix 연동





Zabbix는 기본적으로 rdbms 에 모든 metric, log 등을 타입에 따라서 
history 형태로 저장 하고 있음
ES 에 저장 하기 위해서 아래 표와 같은 형태로 index 를 생성 해줘야 한다.
Item value type
Database table
Elasticsearch type
Numeric (unsigned)
history_uint
uint
Numeric (float)
history
dbl
Character
history_str
str
Log
history_log
log
Text
history_text
text

Crul을 이용 하여  위 표에 지정된 index 생성
# curl -X  \
-H 'content-type:application/json' \
-d '{
"settings" : {
    "index" : {
       "number_of_replicas" : 1,
       "number_of_shards" : 5
    }
},
"mappings" : {
    "values" : {
       "properties" : {
          "itemid" : {
             "type" : "long"
          },
          "clock" : {
             "format" : "epoch_second",
             "type" : "date"
          },
          "value" : {
             "fields" : {
                "analyzed" : {
                   "index" : true,
                   "type" : "text",
                   "analyzer" : "standard"
                }
             },
             "index" : false,
             "type" : "text"
          }
       }
    }
}
}'

#  curl -X  \
-H 'content-type:application/json' \
-d '{
"settings" : {
    "index" : {
       "number_of_replicas" : 1,
       "number_of_shards" : 5
    }
},
"mappings" : {
    "values" : {
       "properties" : {
          "itemid" : {
             "type" : "long"
          },
          "clock" : {
             "format" : "epoch_second",
             "type" : "date"
          },
          "value" : {
             "fields" : {
                "analyzed" : {
                   "index" : true,
                   "type" : "text",
                   "analyzer" : "standard"
                }
             },
             "index" : false,
             "type" : "text"
          }
       }
    }
}
}'

#  curl -X  \
-H 'content-type:application/json' \
-d '{
"settings" : {
    "index" : {
       "number_of_replicas" : 1,
       "number_of_shards" : 5
    }
},
"mappings" : {
    "values" : {
       "properties" : {
          "itemid" : {
             "type" : "long"
          },
          "clock" : {
             "format" : "epoch_second",
             "type" : "date"
          },
          "value" : {
             "fields" : {
                "analyzed" : {
                   "index" : true,
                   "type" : "text",
                   "analyzer" : "standard"
                }
             },
             "index" : false,
             "type" : "text"
          }
       }
    }
}
}'

#  curl -X  \
-H 'content-type:application/json' \
-d '{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "type" : "double"
            }
         }
      }
   }
}
'


#  curl -X  \
-H 'content-type:application/json' \
-d '{
   "settings" : {
      "index" : {
         "number_of_replicas" : 1,
         "number_of_shards" : 5
      }
   },
   "mappings" : {
      "values" : {
         "properties" : {
            "itemid" : {
               "type" : "long"
            },
            "clock" : {
               "format" : "epoch_second",
               "type" : "date"
            },
            "value" : {
               "type" : "double"
            }
         }
      }
   }
}
생성되 index 확인 
yellow open str  PHNHjXGgQzig6Wg5AA686Q 5 1 0 0 1.1kb 1.1kb
yellow open text i_i5q-T7TH6KuM1YedytCQ 5 1 0 0 1.1kb 1.1kb
yellow open uint BuxVaDPRRQ6PJqX1r-NgCw 5 1 0 0 1.1kb 1.1kb
yellow open dbl  blO6vdeaT5GKAf4Woj4PIw 5 1 0 0  460b  460b
yellow open log  nQ6-_Fe_QKa1PYyE3FB_4g 5 1 0 0 1.1kb 1.1kb

웹상에서 기존의 history 를 ES 를 이용 할 수 있도록 기존 설정에 아래 부분 추가 
# vi /etc/zabbix/web/zabbix.conf.php
..생략...
global $DB, $HISTORY;
$HISTORY['url']   = [
        'uint' => 'http://127.0.0.1:9200',
        'text' => 'http://127.0.0.1:9200',
        'str' => 'http://127.0.0.1:9200',
        'log' => 'http://127.0.0.1:9200',
        'dbl' => 'http://127.0.0.1:9200'
];
// Value types stored in Elasticsearch.
$HISTORY['types'] = ['uint', 'text', 'str', 'log', ‘dbl’ ];

Zabbix server 데몬이 agent 부터 수신된 데이터를 ES 로 저장 할 수 있도록 설정 변경 
#vi /etc/zabbix/zabbix_server.conf
HistoryStorageURL=http://localhost:9200
HistoryStorageTypes=str,log,text,dbl,uint
# systemctl restart zabbix-agent

테스트를 위하여 agent설치 

# yum install zabbix-agent -y
# systemctl enable zabbix-agent && systemctl start zabbix-agent

Zabbix 대쉬보드에서 Configuration->Hosts 에서 설정된 hosts 들중 기본 적용 되는 zabbixserver 호스트 status를 enable 로 변경
Zabbix 대쉬보드에서 Monitoring -> Latest data 에서 최신 수집한 데이터 확인 하기 위해 Hosts 필드에  Zabbix server 기입후 apply 클릭
하면 last value 에 데이터가 나오는지 확인 



Kibana 에서 store된 index 를 Index Patterns 적용후 확인 하면 실제 저장된 메트릭을 확인 할 수 있음




실제 RDBMS 에서 데이터 없는 것을 확인
#  mysql -e’select count(*) from history ' -uroot -p'password’ zabbix
+----------+
| count(*) |
+----------+
|        0 |
+----------+
#  #  mysql -e'select count(*) from history_uint' -uroot -p'password' zabbix
+----------+
| count(*) |
+----------+
|        0 |

+----------+ 


반응형