Skip to content

Instantly share code, notes, and snippets.

@tetsun
Created April 13, 2017 08:40
Show Gist options
  • Save tetsun/58e485c1b6c1a2883b122db66f04569a to your computer and use it in GitHub Desktop.
Save tetsun/58e485c1b6c1a2883b122db66f04569a to your computer and use it in GitHub Desktop.

TICK stack

ではなくTIG stackな何かを構築

  1. Telegraf
  2. InfluxDB
  3. Grafana

環境

centos7 検証なのでホストは分けず

telegraf

Install

cf. https://github.com/influxdata/telegraf

yum -y install https://dl.influxdata.com/telegraf/releases/telegraf-1.0.0.x86_64.rpm

Start

systemctl start telegraf
systemctl enable telegraf

parse log

/etc/telegraf/telegraf.d/nginx_access_log.conf

# Stream and parse log file(s).
[[inputs.logparser]]
  ## Log files to parse.
  ## These accept standard unix glob matching rules, but with the addition of
  ## ** as a "super asterisk". ie:
  ##   /var/log/**.log     -> recursively find all .log files in /var/log
  ##   /var/log/*/*.log    -> find all .log files with a parent dir in /var/log
  ##   /var/log/apache.log -> only tail the apache log file
  files = ["/var/log/nginx/access.log"]
  ## Read file from beginning.
  from_beginning = false

  ## Parse logstash-style "grok" patterns:
  ##   Telegraf built-in parsing patterns: https://goo.gl/dkay10
  [inputs.logparser.grok]
    ## This is a list of patterns to check the given log file(s) for.
    ## Note that adding patterns here increases processing time. The most
    ## efficient configuration is to have one pattern per logparser.
    ## Other common built-in patterns are:
    ##   %{COMMON_LOG_FORMAT}   (plain apache & nginx access logs)
    ##   %{COMBINED_LOG_FORMAT} (access logs + referrer & agent)
    patterns = ["%{COMBINED_LOG_FORMAT}"]
    ## Name of the outputted measurement name.
    measurement = "nginx_access_log"
    ## Full path(s) to custom pattern files.
    custom_pattern_files = []
    ## Custom patterns can also be defined here. Put one pattern per line.
    custom_patterns = '''
    '''

influxdb

Install

cf. introduction

cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

yum -y install influxdb

Start

systemctl start influxdb
systemctl enable influxdb

Manage

  • Admin Panel: TCP port 8083
  • HTTP API I/F: TCP port 8086

Create Auth

cf. authentication

Create admin user

influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.0.0
InfluxDB shell version: 1.0.0
> CREATE USER admin WITH PASSWORD '********' WITH ALL PRIVILEGES
> SHOW USERS
user    admin
admin   true

> EXIT

Edit /etc/influxdb/influxdb.conf

auth-enabled = true

Restart influxdb

systemctl restart influxdb

grafana

Install

cf. http://grafana.org/download/

yum -y install https://grafanarel.s3.amazonaws.com/builds/grafana-3.1.1-1470047149.x86_64.rpm

Start

systemctl start grafana-server
systemctl enable grafana-server

Manage

  • ブラウザでport: 3000番にアクセス
    • user: admin
    • password: admin

Change auth

  • 左上のgrafanaアイコン > admin > Profile へと進む
  • Change Password
  • 新しい admin password を設定する

Insert iframe

  • 前段にnginxを想定
  • 適当なview userを作成しておく(ex. webauth)

grafana.ini

[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = false

nginx.conf

        location / {
            proxy_pass http://localhost:3000;
        }

        location /dashboard-solo/db {
            proxy_pass http://localhost:3000;
            proxy_set_header X-WEBAUTH-USER webauth;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment