Network, WEB 상태 간단 모니터링

SYSTEM/TECH / /
반응형

간혹 영역별(구간별) 네트워크 끊김 현상이 발생하여 아래와 같은 방법으로 실시간 모니터링중
목적은 예를들어 A,B,C,D 와 같이 ZONE(영역) 별로 네트워크 상태를 파악하는것

grafana 그래프를 보안 관제 모니터링 대시보드에 추가하여 사용중

개발 핵심 포인트

telegraf 로 5s 단위로 대상 웹사이트를 선정 HTTP 상태, TCP PORT 체크
influxdb 에 지속적으로 데이타 저장
grafana 로 시각화
script 로 임계치나 특정값에 부합되면 slack, mail 알람 통보

telegraf 환경 설정 포인트 / telegraf.conf

HTTP 상태 체크 환경 설정 일부

[[inputs.http_response]]
urls = [ "https://naver.com/", "https://daum.net/" ]
response_timeout = "5s"
method = "GET"
follow_redirects = false
[inputs.http_response.tags]
zone = "외부망"

[[inputs.http_response]]
urls = [ "https://aa.website.com/", "https://bb.website.com/" ]
response_timeout = "5s"
method = "GET"
follow_redirects = false
[inputs.http_response.tags]
zone = "SK ZONE"

[[inputs.http_response]]
urls = [ "https://www.abcd1234.com/", "https://www.abcd5678.com/" ]
response_timeout = "5s"
method = "GET"
follow_redirects = false
[inputs.http_response.tags]
zone = "KT ZONE"

HTTP 상태 모니터링


TCP PORT 체크 환경 설정 일부

[[inputs.net_response]]
protocol = "tcp"
address = "www.coupang.com:443"
timeout = "5s"
[inputs.net_response.tags]
zone = "외부망"

[[inputs.net_response]]
protocol = "tcp"
address = "www.abcd.com:443"
timeout = "5s"
[inputs.net_response.tags]
zone = "DMZ"

[[inputs.net_response]]
protocol = "tcp"
address = "website.com:443"
timeout = "5s"
[inputs.net_response.tags]
zone = "클라우드"

PORT 상태 모니터링


HTTP 상태 체크 알람 스크립트 일부...
알람부분은 grafana 자체 기능을 사용해도 됩니다.

포인트만 ...
influxdb 데이타 값을 쿼리하여 CHECK 변수에 넣고 IF 문을 사용하여 부합하면 슬랙, 메일 발송
아래 쿼리는 result_type 이 success가 아닌것이 1개라도 있으면... 알람

CHECK=`influx -database telegraf -execute 'SELECT last("result_type") FROM "http_response" WHERE "server" =~ /^(http:*)/ AND time >= now() - 30s and time <= now() and "result_type" !~ /success/ GROUP BY time(5s),zone, "server" fill(none) order by desc' | wc -l`

if [ "$CHECK" -gt "1" ]
then

STATUS=`influx -database telegraf -execute 'SELECT last("result_type") FROM "http_response" WHERE "server" =~ /^(http:*)/ AND time >= now() - 30s and time <= now() and "result_type" !~ /success/ GROUP BY time(5s),zone, "server" fill(none) order by desc'`

echo "$STATUS" | mutt -s "HTTP 모니터링문제 발생" aaa@abcd.com

# /usr/sbin/sendmail -oQ/var/spool/mqueue -oT1d -q -v <-메일 큐 쌓일때 처리

/usr/bin/curl -X POST --data-urlencode "payload={\"channel\": \"#monitoring\", \"username\": \"\n\n\", \"text\": \" ▶HTTP 모니터링 문제 발생◀ \n\n $STATUS \", \"icon_emoji\": \":ghost:\"}" https://hooks.slack.com/services/xxxxxxxxxxxxLDGNCHa0F0M

echo " " >> $DIRLOG/http.log
echo "============================== $TIMEs ===========================" >> $DIRLOG/http.log
echo " " >> $DIRLOG/http.log
echo $STATUS >> $DIRLOG/http.log

else

echo " " > /dev/null 2>&1

fi

간단하게 모니터링 하는 방법에 대하여 포스팅 해보았습니다.
한가지 장점은 원하는대로 뽀대나게? 시각화를 할수있다는 것...
굳이 귀찮다면 사용중인 모니터링 솔루션에 대상등록...

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기