본문 바로가기

프로젝트/여행지 오픈 API

[Kibana] Kibana 데이터시각화 구현

목차

    https://www.elastic.co/guide/en/kibana/7.11/index-patterns.html

     

    Create an index pattern | Kibana Guide [7.11] | Elastic

    If you don’t set a default time field, you will not be able to use global time filters on your dashboards. This is useful if you have multiple time fields and want to create dashboards that combine visualizations based on different timestamps.

    www.elastic.co

     

    1. 인덱스 패턴 생성

     

    Stack Management - Index patterns - Create index pattern

     

     

    2. Discover 탭

     

    'Discover' 탭에서 생성한 인덱스 패턴을 사용해 데이터를 탐색하고 필드를 확인한다. 여기서 데이터의 개요를 볼 수 있다.

     

     

    3. 시각화 생성 

    'Visualize' 탭으로 이동한다.

    새 시각화를 선택하고, 원하는 시각화 유형(예: 막대 그래프, 파이 차트, 라인 차트 등)을 선택한다.

     

    새로운 시각화 도구를 선택해보자.

     

     

    사용할 인덱스 패턴을 선택한다.

    시각화에 필요한 필드와 옵션을 설정한다. 예를 들어, 특정 필드에 대한 집계 방법, 필터, 시간 범위 등을 설정할 수 있다.

     

    맨 처음 korean nori 분석기만 적용된 모습

     

    하지만 해당 집계 값은 유의미한 수치가 나오지 않는다.

    데이터 시각화를 위해 커스텀 분석기를 사용한 필드를 재집계하였다.

    단어 최소 글자와, stop filter가 들어간 분석기를 사용하였다.

     

    유의미한 지표를 뽑아냄을 확인할 수 있다.

     

     

    Iframe을 사용한 대시보드 export

    https://www.elastic.co/guide/en/kibana/7.11/embedding.html

     

    Embed Kibana content in a web page | Kibana Guide [7.11] | Elastic

    Embedding of any other part of Kibana is also generally possible, but you might need to craft the proper HTML code manually.

    www.elastic.co

     

    Kibana 대시보드나 시각화를 다른 웹 페이지나 프론트엔드 서버에 포함할 때 iframe을 사용하는 것이 일반적인 방법이다. 각 대시보드와 시각화에 대한 고유한 URL을 사용하여 iframe 소스로 넣을 수 있다. 

     

    시각화 또는 대시보드의 'Share' 옵션을 클릭

    'Embed code'를 선택하면 iframe을 사용하기 위한 HTML 코드를 얻을 수 있다.

     

    DashBoard에 시각화를 import하고, embed code를 통해 외부의 링크로 export 할 수 있다.

     

     

    이 HTML 코드를 웹 페이지의 HTML에 복사하여 붙여넣는다.

     

    정말 간단한 테스팅 코드

     

     

    kibana 자동 로그인 설정

    물론 당연히 인증이 필요하다. 이 부분을 확장해보자.

     

     

    방법은 크게 두 가지가 존재한다.

    1. Guest 계정을 생성하여 조회 권한만 주고, 이를 입력하여 자동 로그인을 하게 하는 방법

    2. Reverse proxy 서버를 구성하여 인증을 처리하고, 이를 통해 인증된 요청만 Kibana로 전달하는 방법.

     

    이번 서버 구축에서는 1번 방법을 사용하도록 하겠다.

    https://m.blog.naver.com/xomyjoung/221710608723

     

    [자기개발/엘라스틱서치(elasticsearch)-#17] Kibana 무인증 환경으로 사용하기!(대시보드 Share-Embed Iframe

    안녕하세요? 지난 포스팅에서는 오픈소스 키바나에서 로그인 기능을 활성화하고.. 인증서를 발급한 뒤에 S...

    blog.naver.com

     

    해당 게시글을 참조하였다. 

    기존 kibana에 진입하던 포트에 리버스 프록시를 걸어두고자 한다.

     

    리버스 프록시 설정 변경(계정 설정)

     

      GNU nano 4.8                                                               httpsettings.conf                                                                         
    # HTTP 트래픽을 HTTPS로 리디렉션
    server {
        listen 80;
        server_name k9b205a.p.ssafy.io;
    
        location / {
            return 301 https://$host$request_uri;
        }
    }
    
    # HTTPS 설정
    server {
        listen 443 ssl;
        server_name k9b205a.p.ssafy.io;
    
        ssl_certificate /etc/letsencrypt/live/k9b205a.p.ssafy.io/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/k9b205a.p.ssafy.io/privkey.pem;
    
        # kibana 리버스 프록시 설정
        location /kibana/ {
            proxy_pass http://localhost:5601;
            proxy_http_version 1.1;
            proxy_set_header Authorization "Basic bXl1c2VybmFtZTpteXBhc3N3b3Jk";
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    
        # Elasticsearch 리버스 프록시 설정
        location / {
            proxy_pass http://localhost:9201;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }

     

    여기서 proxy_set_header Authorization "Basic [encoded_string]"; 문구는 Nginx 설정에서 사용되어, 리버스 프록시를 통해 특정 HTTP 요청 헤더를 설정하는 방법이다.

    여기서 [encoded_string]은 사용자 이름과 비밀번호를 콜론(:)으로 결합하고 Base64로 인코딩한 문자이다.

     

    ex : myId:myPassword 를 인코딩 -> bXl1c2VybmFtZTpteXBhc3N3b3Jk

    https://www.base64encode.org/ 해당 사이트를 통해 인코딩하여 적용하도록 하자.

     

     

    게스트 계정 만들기 

    단, 여기 있는 계정은 조회 권한만 있는 게스트 계정이어야 한다.

    계정 설정 방법은 해당 게시글을 참조할 것.

    https://pacloud.tistory.com/23

     

    Kibana 대시보드 및 캔버스 Public으로 공유하는 법, 게스트용 인증 사용하는 법(Kibana Anonymous access se

    Kibana로 생성한 대시보드 및 캔버스를 공유 혹은 웹사이트에 임베딩을 하려고 하면 계정 인증 없이는 접근이 불가능하다고 한다. 대시보드 및 캔버스를 보기 위해 모든 사람에게 Kibana 계정 정보

    pacloud.tistory.com

    https://soobysu.tistory.com/113

     

    [Elastic] 유저 추가

    키바나를 접속해서 데이터를 생성 수정 삭제를 하려면 계정을 추가 해주어야 한다. 1. 컨테이너에서 생성방법 2. 키바나에서 생성방법 엘라스틱 서치 설정파일에 들어가서 /etc/elasticsearch/elasticsea

    soobysu.tistory.com

    kibana console의 roles에서 읽기 권한만 만들어 주자. 이를 user 계정을 만들고 적용한다.

     

    등록한 Role을 통해 바로 계정을 생성했다.

    키바나.yml 변경

    기본 리버스 프록시 도메인에 /kibana/가 추가되었으므로, basePath를 추가해주어야 한다.

    # Kibana is served by a back end server. This setting specifies the port to use.
    server.port: 5601
    
    # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
    # The default is 'localhost', which usually means remote machines will not be able to connect.
    # To allow connections from remote users, set this parameter to a non-loopback address.
    server.host: "0.0.0.0"
    
    # Enables you to specify a path to mount Kibana at if you are running behind a proxy.
    # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
    # from requests it receives, and to prevent a deprecation warning at startup.
    # This setting cannot end in a slash.
    # 리버스 프록시에 따른 기본 주소 적용
    server.basePath: "/kibana"
    server.rewriteBasePath: true
    
    
    # Specifies whether Kibana should rewrite requests that are prefixed with
    # `server.basePath` or require that they are rewritten by your reverse proxy.
    # This setting was effectively always `false` before Kibana 6.3 and will
    # default to `true` starting in Kibana 7.0.
    #server.rewriteBasePath: false
    
    # Specifies the public URL at which Kibana is available for end users. If
    # `server.basePath` is configured this URL should end with the same basePath.
    #server.publicBaseUrl: ""
    
    # The maximum payload size in bytes for incoming server requests.
    #server.maxPayloadBytes: 1048576
    
    # The Kibana server's name.  This is used for display purposes.
    #server.name: "your-hostname"
    
    # The URLs of the Elasticsearch instances to use for all your queries.
    elasticsearch.hosts: ["http://localhost:9201"]
    
    # Kibana uses an index in Elasticsearch to store saved searches, visualizations and
    # dashboards. Kibana creates a new index if the index doesn't already exist.
    #kibana.index: ".kibana"
    
    # The default application to load.
    #kibana.defaultAppId: "home"
    
    # If your Elasticsearch is protected with basic authentication, these settings provide
    # the username and password that the Kibana server uses to perform maintenance on the Kibana
    # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
    # is proxied through the Kibana server.
    elasticsearch.username: "당신의 아이디"
    elasticsearch.password: "당신의 비밀번호"
    
    # Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
    # These settings enable SSL for outgoing requests from the Kibana server to the browser.
    #server.ssl.enabled: false
    #server.ssl.certificate: /path/to/your/server.crt
    #server.ssl.key: /path/to/your/server.key
    
    # Optional settings that provide the paths to the PEM-format SSL certificate and key files.
    # These files are used to verify the identity of Kibana to Elasticsearch and are required when
    # xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
    #elasticsearch.ssl.certificate: /path/to/your/client.crt
    #elasticsearch.ssl.key: /path/to/your/client.key
    
    # Optional setting that enables you to specify a path to the PEM file for the certificate
    # authority for your Elasticsearch instance.
    #elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
    
    # To disregard the validity of SSL certificates, change this setting's value to 'none'.
    #elasticsearch.ssl.verificationMode: full
    
    # Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
    # the elasticsearch.requestTimeout setting.
    #elasticsearch.pingTimeout: 1500
    
    # Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
    # must be a positive integer.
    #elasticsearch.requestTimeout: 30000
    
    # List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
    # headers, set this value to [] (an empty list).
    #elasticsearch.requestHeadersWhitelist: [ authorization ]
    
    # Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
    # by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
    #elasticsearch.customHeaders: {}
    
    # Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
    #elasticsearch.shardTimeout: 30000
    
    # Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
    #elasticsearch.logQueries: false
    
    # Specifies the path where Kibana creates the process ID file.
    #pid.file: /run/kibana/kibana.pid
    
    # Enables you to specify a file where Kibana stores log output.
    #logging.dest: stdout
    
    # Set the value of this setting to true to suppress all logging output.
    #logging.silent: false
    
    # Set the value of this setting to true to suppress all logging output other than error messages.
    #logging.quiet: false
    
    # Set the value of this setting to true to log all events, including system usage information
    # and all requests.
    logging.verbose: true
    
    # Set the interval in milliseconds to sample system and process performance
    # metrics. Minimum is 100ms. Defaults to 5000.
    #ops.interval: 5000
    
    # Specifies locale to be used for all localizable strings, dates and number formats.
    # Supported languages are the following: English - en , by default , Chinese - zh-CN .
    #i18n.locale: "en"

     

    결과

    테스트용 html에 import가 된 모습을 확인할 수 있다.