LoginSignup
20
21

More than 5 years have passed since last update.

ログをGUIでtail -F的に見ることができる rtail について簡単に調べてみた(js, node)

Last updated at Posted at 2015-07-31

この間rtailというログをguiでみるツールを見つけてしまったので、うっかりインストールと簡単な紹介をしてみたいと思います。

環境

  • node
    • v0.10.36
  • CentOS
    • Linux release 7.1.1503 (Core)

インストール

nodeのインストール

npmが必要なのでnode.jsをインストールします
(※epelが参照できればyumで簡単にインストールが可能なようです。)


$ sudo yum install nodejs
=======================================================================================================================
 Package                   Arch                 Version                                       Repository          Size
=======================================================================================================================
Installing:
 nodejs                    x86_64               0.10.36-3.el7                                 epel               391 k
Installing for dependencies:
 c-ares                    x86_64               1.10.0-3.el7                                  base                78 k
 http-parser               x86_64               2.0-4.20121128gitcd01361.el7                  epel                23 k
 libuv                     x86_64               1:0.10.34-1.el7                               epel                62 k
 v8                        x86_64               1:3.14.5.10-17.el7                            epel               3.0 M

Transaction Summary
=======================================================================================================================
Install  1 Package (+4 Dependent packages)

$ node -v
v0.10.36

npmのインストール

npmもyumで入ります。epelですね。
依存パッケージ多いな・・・

$ sudo yum install npm
Dependencies Resolved

=======================================================================================================================
 Package                                 Arch             Version                                 Repository      Size
=======================================================================================================================
Installing:
 npm                                     noarch           1.3.6-5.el7                             epel           333 k
Installing for dependencies:
 c-ares-devel                            x86_64           1.10.0-3.el7                            base            72 k
 gyp                                     noarch           0.1-0.11.1617svn.el7                    epel           403 k
 http-parser-devel                       x86_64           2.0-4.20121128gitcd01361.el7            epel           9.2 k
 libuv-devel                             x86_64           1:0.10.34-1.el7                         epel            41 k
 node-gyp                                noarch           0.10.6-2.el7                            epel            26 k
 nodejs-abbrev                           noarch           1.0.4-6.el7                             epel           7.4 k
 nodejs-ansi                             noarch           0.2.1-1.el7                             epel            13 k
 nodejs-archy                            noarch           0.0.2-8.el7                             epel           6.7 k
 nodejs-asn1                             noarch           0.1.11-3.el7                            epel            11 k
 nodejs-assert-plus                      noarch           0.1.4-1.el7                             epel           7.3 k
 nodejs-async                            noarch           0.2.10-1.el7                            epel            21 k
 nodejs-aws-sign                         noarch           0.3.0-1.el7                             epel           5.7 k
 nodejs-block-stream                     noarch           0.0.7-1.el7                             epel           8.7 k
 nodejs-boom                             noarch           0.4.2-2.el7                             epel            37 k
 nodejs-child-process-close              noarch           0.1.1-2.el7                             epel           6.1 k
 nodejs-chmodr                           noarch           0.1.0-4.el7                             epel           5.9 k
 nodejs-chownr                           noarch           0.0.1-9.el7                             epel           6.4 k
 nodejs-cmd-shim                         noarch           1.1.0-3.el7                             epel           7.7 k
 nodejs-combined-stream                  noarch           0.0.4-3.el7                             epel           7.9 k
 nodejs-config-chain                     noarch           1.1.7-1.el7                             epel            10 k
 nodejs-cookie-jar                       noarch           1:0.3.0-1.el7                           epel           6.1 k
 nodejs-cryptiles                        noarch           0.2.2-1.el7                             epel           6.9 k
 nodejs-ctype                            noarch           0.5.3-3.el7                             epel            31 k
 nodejs-delayed-stream                   noarch           0.0.5-5.el7                             epel           7.9 k
 nodejs-devel                            x86_64           0.10.36-3.el7                           epel           329 k
 nodejs-editor                           noarch           0.0.4-2.el7                             epel           6.4 k
 nodejs-forever-agent                    noarch           0.5.0-1.el7                             epel           5.6 k
 nodejs-form-data                        noarch           0.1.1-1.el7                             epel            11 k
 nodejs-fstream                          noarch           0.1.24-1.el7                            epel            25 k
 nodejs-fstream-ignore                   noarch           0.0.7-1.el7                             epel           8.9 k
 nodejs-fstream-npm                      noarch           0.1.5-1.el7                             epel            11 k
 nodejs-github-url-from-git              noarch           1.1.1-2.el7                             epel           6.0 k
 nodejs-glob                             noarch           3.2.6-1.el7                             epel            16 k
 nodejs-graceful-fs                      noarch           2.0.0-2.el7                             epel            11 k
 nodejs-hawk                             noarch           1.0.0-1.el7                             epel           105 k
 nodejs-hoek                             noarch           0.9.1-1.el7                             epel            51 k
 nodejs-http-signature                   noarch           0.10.0-3.el7                            epel            17 k
 nodejs-inherits                         noarch           2.0.0-4.el7                             epel           8.6 k
 nodejs-ini                              noarch           1.1.0-3.el7                             epel           8.3 k
 nodejs-init-package-json                noarch           0.0.10-1.el7                            epel           9.5 k
 nodejs-json-stringify-safe              noarch           5.0.0-1.el7                             epel           6.6 k
 nodejs-lockfile                         noarch           0.4.2-1.el7                             epel            11 k
 nodejs-lru-cache                        noarch           2.3.0-3.el7                             epel           9.6 k
 nodejs-mime                             noarch           1.2.11-1.el7                            epel            22 k
 nodejs-minimatch                        noarch           0.2.12-2.el7                            epel            18 k
 nodejs-mkdirp                           noarch           0.3.5-3.el7                             epel           7.5 k
 nodejs-mute-stream                      noarch           0.0.4-1.el7                             epel           7.5 k
 nodejs-node-uuid                        noarch           1.4.1-1.el7                             epel            10 k
 nodejs-nopt                             noarch           2.1.2-1.el7                             epel            15 k
 nodejs-normalize-package-data           noarch           0.2.1-1.el7                             epel            13 k
 nodejs-npm-registry-client              noarch           0.2.28-3.el7                            epel            21 k
 nodejs-npm-user-validate                noarch           0.0.3-1.el7                             epel           6.1 k
 nodejs-npmconf                          noarch           0.1.3-1.el7                             epel            17 k
 nodejs-npmlog                           noarch           0.0.4-3.el7                             epel           9.6 k
 nodejs-oauth-sign                       noarch           0.3.0-1.el7                             epel           4.9 k
 nodejs-once                             noarch           1.1.1-5.el7                             epel           6.0 k
 nodejs-opener                           noarch           1.3.0-7.el7                             epel           6.9 k
 nodejs-osenv                            noarch           0.0.3-5.el7                             epel           7.1 k
 nodejs-packaging                        noarch           7-1.el7                                 epel            11 k
 nodejs-promzard                         noarch           0.2.0-6.el7                             epel            12 k
 nodejs-proto-list                       noarch           1.2.2-5.el7                             epel           6.7 k
 nodejs-qs                               noarch           0.6.6-3.el7                             epel           8.7 k
 nodejs-read                             noarch           1.0.5-1.el7                             epel           8.7 k
 nodejs-read-installed                   noarch           0.2.4-1.el7                             epel           9.5 k
 nodejs-read-package-json                noarch           1.1.3-1.el7                             epel            12 k
 nodejs-request                          noarch           2.25.0-1.el7                            epel            27 k
 nodejs-retry                            noarch           0.6.0-5.el7                             epel            11 k
 nodejs-rimraf                           noarch           2.2.2-1.el7                             epel           8.1 k
 nodejs-semver                           noarch           2.1.0-3.el7                             epel            16 k
 nodejs-sha                              noarch           1.2.1-1.el7                             epel           7.6 k
 nodejs-sigmund                          noarch           1.0.0-5.el7                             epel           8.3 k
 nodejs-slide                            noarch           1.1.5-1.el7                             epel           9.9 k
 nodejs-sntp                             noarch           0.2.4-1.el7                             epel            10 k
 nodejs-tar                              noarch           0.1.18-1.el7                            epel            23 k
 nodejs-tunnel-agent                     noarch           0.3.0-1.el7                             epel           6.3 k
 nodejs-uid-number                       noarch           0.0.3-7.el7                             epel           7.1 k
 nodejs-which                            noarch           1.0.5-8.el7                             epel           8.0 k
 v8-devel                                x86_64           1:3.14.5.10-17.el7                      epel            71 k

Transaction Summary
=======================================================================================================================
Install  1 Package (+78 Dependent packages)

$ npm -v
1.3.6

rtailのインストール

本題のrtailのインストールです。

$ sudo npm install -g rtail

...
※けっこう長い感じなので省略します。
...

rtail@0.2.1 /lib/node_modules/rtail
├── moniker@0.1.2
├── strip-ansi@3.0.0 (ansi-regex@2.0.0)
├── debug@2.2.0 (ms@0.7.1)
├── split@1.0.0 (through@2.3.8)
├── json5@0.4.0
├── yargs@3.16.1 (camelcase@1.2.0, decamelize@1.0.0, window-size@0.1.2, y18n@3.0.0, cliui@2.1.0)
├── through2-map@2.0.0 (xtend@4.0.0, through2@2.0.0)
├── update-notifier@0.5.0 (is-npm@1.0.0, string-length@1.0.1, chalk@1.1.0, repeating@1.1.3, configstore@1.2.0, semver-diff@2.0.0, latest-version@1.0.1)
├── express@4.13.1 (escape-html@1.0.2, merge-descriptors@1.0.0, array-flatten@1.1.0, cookie@0.1.3, path-to-regexp@0.1.6, utils-merge@1.0.0, cookie-signature@1.0.6, methods@1.1.1, fresh@0.3.0, range-parser@1.0.2, vary@1.0.1, content-type@1.0.1, etag@1.7.0, parseurl@1.3.0, content-disposition@0.5.0, serve-static@1.10.0, depd@1.0.1, qs@4.0.0, on-finished@2.3.0, finalhandler@0.4.0, send@0.13.0, proxy-addr@1.0.8, type-is@1.6.5, accepts@1.2.12)
├── request@2.60.0 (aws-sign2@0.5.0, forever-agent@0.6.1, caseless@0.11.0, stringstream@0.0.4, oauth-sign@0.8.0, tunnel-agent@0.4.1, isstream@0.1.2, json-stringify-safe@5.0.1, extend@3.0.0, node-uuid@1.4.3, qs@4.0.0, mime-types@2.1.4, combined-stream@1.0.5, bl@1.0.0, form-data@1.0.0-rc3, tough-cookie@2.0.0, http-signature@0.11.0, hawk@3.1.0, har-validator@1.8.0)
├── chrono-node@1.0.6 (moment@2.10.6)
└── socket.io@1.3.6 (has-binary-data@0.1.3, debug@2.1.0, socket.io-adapter@0.3.1, socket.io-parser@2.2.4, engine.io@1.5.2, socket.io-client@1.3.6)

結構たくさんパッケージ入りましたな。

$ rtail -v
0.2.1

これでインストールは完了です。

使用方法

githubのページをみるかぎり超カンタンです。見たいログをパイプで流してあげるだけなようです。例えば以下の様な感じです。

$ tail -F /var/log/httpd/access_log |rtail

準備としてPORTの解放が私はありました。通常では8888を使用するようです、
もしportが開いてないのであれば開けてください(別なポートの指定も可能です。)

$ sudo firewall-cmd --add-port=8888/tcp --zone=public --permanent
success
]$ sudo firewall-cmd --reload
success
$ sudo firewall-cmd --list-all |grep 8888
  ports: ... 8888/tcp ...略

ログをrtailに流す

私がやったのはこんなかんじです。

$ tail -F /var/log/httpd/access_log |rtail
※コンソールはtailの画面が続きます

rtail-serverを立ち上げる

--webhostを指定して起動します(必要な人はportも)

以下を実行しました。

$ rtail-server --webhost 0.0.0.0(自身のアドレスを設定してください)
※ --id name で画面に表示するログの名前を任意の名前にすることが出来ます。

するとサーバが起動しているので http://0.0.0.0:8888/ にアクセスしてください

rTail_after.png

こんなかんじに表示がされていると思います。画面キレイ!
私の環境では、アクセスするとリアルタイムに画面が更新されるのを確認しました。

その他

initスクリプト

githubのページでinitスクリプトを書くなら的なものもあるので、デーモン化も出来そうですね。
果たしてCentOS7は・・・

簡単な設定の変更

config.png

右上の歯車マークを選択すると白背景やフォント周りが調整出来ます。

オプション

ヘルプだと以下のオプションがコマンドで使えるみたいです。

rtail

$ rtail --help
Usage: cmd | rtail [OPTIONS]

Options:
  --host, -h     The server host                 [string] [default: "127.0.0.1"]
  --port, -p     The server port                        [string] [default: 9999]
  --id, --name   The log stream id                 [string] [default: (moniker)]
  --mute, -m     Don't pipe stdin with stdout                          [boolean]
  --tty          Keeps ansi colors                     [boolean] [default: true]
  --parse-date   Looks for dates to use as timestamp   [boolean] [default: true]
  --help         Show help                                             [boolean]
  --version, -v  Show version number                                   [boolean]

Examples:
  server | rtail > server.log         localhost + file
  server | rtail --id api.domain.com  Name the log stream
  server | rtail --host example.com   Sends to example.com
  server | rtail --port 43567         Uses custom port
  server | rtail --mute               No stdout
  server | rtail --no-tty             Strips ansi colors
  server | rtail --no-date-parse      Disable date parsing/stripping

rtail-server

$ rtail-server -h
Usage: rtail-server [OPTIONS]

Options:
  --udp-host, --uh  The listening UDP hostname            [default: "127.0.0.1"]
  --udp-port, --up  The listening UDP port                       [default: 9999]
  --web-host, --wh  The listening HTTP hostname           [default: "127.0.0.1"]
  --web-port, --wp  The listening HTTP port                      [default: 8888]
  --web-version     Define web app version to serve                     [string]
  --help, -h        Show help                                          [boolean]
  --version, -v     Show version number                                [boolean]

Examples:
  rtail-server --web-port 8080         Use custom HTTP port
  rtail-server --udp-port 8080         Use custom UDP port
  rtail-server --web-version stable    Always uses latest stable webapp
  rtail-server --web-version unstable  Always uses latest develop webapp
  rtail-server --web-version 0.1.3     Use webapp v0.1.3

活用

一歩進んで活用されている記事を見つけたのでリンクします。ぜひご覧ください。
rTail が良い感じだったので npm scripts を駆使してログを集約したら捗った

今後調べたいこと

表示させているログをキャッシュしている部分

常時起動かつ大量にロゴを吐くものの場合、ファイルがやばいことにならないかなとかが心配なので、そちらを調べたい。
解説があればいいんだけど英語読めないし、ソース読まないとダメかなー。でもjs読めないしnodeもわからないので時間かかりそうー。

CentOS7でのデーモン的に動かす方法

systemdになってから、initスクリプトの代わりになるserviceのファイルを書いていないので、こちらも調べる必要がありそう。
具体的には

  • そもそもserviceでつかうファイルの書き方
  • rtailがstop,startに使う部分のお作法の調査。

調べる時間ができましたら追記でご報告したいと思います。
だれかjsな人ご教授いただけますと幸いでございます。

※参考URL
github rtail: https://github.com/kilianc/rtail

追記

  • 2015/08/03
    • 指摘頂いた -f より ーF の方がというものについて調べたら確かにその通りだったのでそれを変更しました。
    • --idのオプションについてメモで記載しました
    • rtailの素敵な記事をみつけたのでリンクさせてもらいました。
20
21
1

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
20
21