1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

DockerでPromtail + Loki + Grafana(WordCloud plugin)でログ可視化をする

Posted at

目的

NOCのタスクで、DNSクエリログの可視化をする必要が出来た。今回は、Kibanaで言うところのtagcloudの様な可視化をGrafana pluginのWordcloudを用いる事でpromtheusスタックでtagcloud環境を実装する。

システム概要図

image.png

設定

送信側

Unboundの設定

Rsyslogの設定

受信側

docker-compose

docker-compose.yml
version: '3'
services:
  grafana:
#    image: grafana/grafana:latest
    build: ./grafana
    container_name: grafana
    hostname: grafana
    ports:
      - 3000:3000
    user: "$PID:$GID"
    volumes:
      - ./grafana:/var/lib/grafana

  rsyslog:
    build: ./syslog
    container_name: rsyslog
    ports:
      - 514:514
    volumes:
      - ./syslog/log/:/var/log/
    privileged: true


  loki:
    image: grafana/loki:latest
    container_name: loki
    ports:
      - 3100:3100
    command: -config.file=/etc/loki/local-config.yaml


  promtail:
    image: grafana/promtail:2.7.5
    volumes:
      - /var/log:/var/log
      - ./promtail/config.yml:/etc/promtail/config.yml
      - ./syslog/log/syslog:/etc/syslog
    command: -config.file=/etc/promtail/config.yml
    container_name: promtail
    ports:
      - 9080:9080
    restart: always

Dockerfile

grafana

FROM grafana/grafana
RUN grafana-cli plugins install magnesium-wordcloud-panel

rsyslog

FROM shomaigu/ubuntu-base:latest
RUN apt -y install rsyslog
ADD ./rsyslog.conf /etc/rsyslog.conf

RUN touch /var/log/syslog
RUN chmod 777 /var/log/syslog

ENTRYPOINT ["/usr/sbin/rsyslogd", "-n", "-iNONE"]

各サービスのconfig

rsyslog

rsyslog.conf
# /etc/rsyslog.conf configuration file for rsyslog
#
# For more information install rsyslog-doc and see
# /usr/share/doc/rsyslog-doc/html/configuration/index.html
#
# Default logging rules can be found in /etc/rsyslog.d/50-default.conf


#################
#### MODULES ####
#################

module(load="imuxsock") # provides support for local system logging
#module(load="immark")  # provides --MARK-- message capability

# provides UDP syslog reception
#module(load="imudp")
#input(type="imudp" port="514")

# provides TCP syslog reception
module(load="imtcp")
input(type="imtcp" port="514")

# provides kernel logging support and enable non-kernel klog messages
module(load="imklog" permitnonkernelfacility="on")

###########################
#### GLOBAL DIRECTIVES ####
###########################

#
# Use traditional timestamp format.
# To enable high precision timestamps, comment out the following line.
#
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Filter duplicated messages
$RepeatedMsgReduction on

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
#$PrivDropToUser syslog
#$PrivDropToGroup syslog

$PrivDropToUser root
$PrivDropToGroup root



#
# Where to place spool and state files
#
$WorkDirectory /var/spool/rsyslog

#
# Include all config files in /etc/rsyslog.d/
#
$IncludeConfig /etc/rsyslog.d/*.conf

promtail

config.yml
server:
  # 9080 ポートで HTTP でリッスンする
  # ブラウザで開くとログのディスカバリの状態が見れます
  http_listen_port: 9080

  # grpc のリッスンポート、0 ならランダムに決定される・・・これなにに使っている の?
  grpc_listen_port: 0


clients:
  # Loki の URL を指定
  - url: http://loki:3100/loki/api/v1/push

# ログのディスカバリの設定
scrape_configs:

  # Apache のアクセスログを収集
  - job_name: access_log
    static_configs:
      - targets:
          # targets は localhost または自ホスト名のどちらかを指定する必要がある
          # とドキュメントに書いてた気がするけど何でも通る? というかこれ指定で きる意味あるの?
          - localhost
        labels:
          # __path__ ラベルでファイル名を指定する、ワイルドカードも指定可能
          __path__: /etc/syslog

Grafana上で、データソースにLokiを選択し、wordcloudの選択後、CountfieldにTimeと入力し、クエリを実行すると
image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?