Skip to content

Latest commit

 

History

History
138 lines (103 loc) · 4.66 KB

ELK-with-Seoul-Metro.md

File metadata and controls

138 lines (103 loc) · 4.66 KB

ELK를 이용해서 서울시 지하철 대시보드 만들기

동영상 참조문서

Elastic Search 설치(2.4.x)

Kibana 설치(4.x)

Elastic Search Index 생성

https://github.com/kimjmin/elastic-demo매핑 정보 입력을 참고하여 아래와 같이 curl 명령 실행

~/lib/elk/kibana-4.6.2-darwin-x86_64 $ curl -XPUT 'http://127.0.0.1:9200/seoul-metro-2014' -d '
  {
    "mappings" : {
      "seoul-metro" : {
        "properties" : {
          "time_slot" : { "type" : "date" },
          "line_num" : { "type" : "string", "index" : "not_analyzed" },
          "line_num_en" : { "type" : "string", "index" : "not_analyzed" },
          "station_name" : { "type" : "string", "index" : "not_analyzed" },
          "station_name_kr" : { "type" : "string", "index" : "not_analyzed" },
          "station_name_en" : { "type" : "string", "index" : "not_analyzed" },
          "station_name_chc" : { "type" : "string", "index" : "not_analyzed" },
          "station_name_ch" : { "type" : "string", "index" : "not_analyzed" },
          "station_name_jp" : { "type" : "string", "index" : "not_analyzed" },
          "station_geo" : { "type" : "geo_point" },
          "people_in" : { "type" : "integer" },
          "people_out" : { "type" : "integer" }
        }
      }
    }
  }'
{"acknowledged":true}%

아래와 같이 GET 명령을 통해 인덱스 생성 상태를 확인

~/lib/elk/kibana-4.6.2-darwin-x86_64 $ curl -XGET 'http://127.0.0.1:9200/seoul-metro-2014/_search'
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}%

Logstash 설치(2.4.x)

  • https://www.elastic.co 에서 download
  • 압축 해제. ~/lib/elk $ tar xvfz ~/Downloads/logstash-2.4.0.tar.gz

FileBeat(1.3.x)

  • https://www.elastic.co 에서 download
  • 압축 해제. ~/lib/elk $ tar xvfz ~/Downloads/filebeat-1.3.1-darwin.tgz

Data Loading하기

  • https://github.com/kimjmin/elastic-demo 에서 맨 마지막의 1.4 추출된 데이터 링크에서 파일을 다운받고, 압축을 푼다(ex. 여기서는 ~/lib/elk/data 디렉토리에 저장)

  • filebeats.yml 수정

    • paths 수정해서 /Users/msbaek/lib/elk/data/*.log 를 사용하도록 변경
    • output: 섹션에서 elasticsearch를 comment out
    • output: 섹션에서 logstash를 enable(hosts도 enable)
  • ~/lib/elk/logstash-2.4.0/logstash.conf 파일을 아래와 같이 작성

    input {
      beats {
        codec => json
        port => 5044
      }
    }
    
    filter {
      mutate {
        remove_field => [ "@version", "@timestamp", "host", "path" ]
      }
    }
    
    output {
      stdout {
        codec => json
      }
      elasticsearch {
        hosts => ["127.0.0.1"]
        index => "seoul-metro-2014"
        document_type => "seoul-metro"
      }
    }
    
  • logstash 실행: ~/lib/elk/logstash-2.4.0 $ bin/logstash -f logstash.conf

  • filebeat 실행: ~/lib/elk/filebeat-1.3.1-darwin $ ./filebeat -c filebeat.yml

Kibana Visualize

Line Chart

visualize / new visualization / line chart / from a new search

Pie Chart

Tile Map

Data

Options

Time Lion

https://github.com/elastic/timelion

설치: ~/lib/elk/kibana-4.6.2-darwin-x86_64 $ ./bin/kibana plugin --install elastic/timelion

기간 설정

쿼리에 .es(index="seoul-metro*", timefield="time_slot")

.es(index="seoul-metro*", timefield="time_slot", metric="sum:people_in"), .es(index="seoul-metro*", timefield="time_slot", metric="sum:people_out")