解析までいうほどじゃないが可視化
可視化といえばfluentd + elasticsearch + kibanaだったが
バージョンがどんどんあがっていきついていけなくなった
ついでに環境を作るのがめんどくさい
旧バージョンならansible化してるので動かせるけどもっと楽にみたかったので調べた
Metabase
https://www.metabase.com/
DBのログを可視化したりできるツールがあったので使ってみた
まずnginxのアクセスログはLTSVにしてあるのでそれをfluentdでmysqlに流し込む
fluentdやfluentdのプラグインやmysqlのインストールは割愛
nginxのlog_formatはこんな感じになっている
log_format ltsv 'time:$time_iso8601' '\tremote_addr:$remote_addr' '\trequest_method:$request_method' '\trequest_length:$request_length' '\trequest_uri:$request_uri' '\thttps:$https' '\turi:$uri' '\tquery_string:$query_string' '\tstatus:$status' '\tbytes_sent:$bytes_sent' '\tbody_bytes_sent:$body_bytes_sent' '\treferer:$http_referer' '\tuseragent:$http_user_agent' '\tforwardedfor:$http_x_forwarded_for' '\trequest_time:$request_time' '\tupstream_response_time:$upstream_response_time' '\tcookie_uid:$cookie_uid' ;
いろいろ出してけどDBに突っ込むのは一部とする
DB
create database nginx; CREATE TABLE `request_log` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `time` varchar(30) NOT NULL, `request_uri` varchar(500) DEFAULT NULL, `uri` varchar(500) DEFAULT NULL, `status` varchar(5) DEFAULT NULL, `useragent` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
fluentd.conf
<source> @type tail format ltsv tag nginx path /Users/astel/Desktop/fluentd/hoge.log pos_file /Users/astel/Desktop/fluentd/hoge_pos.pos </source> <match nginx> @type mysql_bulk include_time_key yes host localhost database nginx username root password root column_names id,time,request_uri,uri,status,useragent table request_log flush_interval 5s </match>
fluentd -c fluentd.conf で起動して
cat access.log >> hoge.log で流し込む
dbの中身がそれっぽくなったらMetabaseを起動する
macだったのでmac版をインストールした
jar版でも動いた
適当に名前とメールアドレスとDBをセットアップしていじってたらグラフでてきた
そんな感じ
apiのログなのでかなり細かめにでちゃったけど絞り込めば自分の好きなグラフとかデータとか出せそう
別にmysqlじゃなくてもprestoとかも見えたので色々出せそうな雰囲気はあった
簡単に使えたので今後可視化するときは使っていきたい
(DBにデータを突っ込みかたとかDBの設定とかが得意ではないのでそこらへんの設定はよしなにしてやって