embulk-parser-regexのエラー対応
Embulkプラグインのembulk-parser-regexで、regexのキーに、_(アンダースコア)を含めるとエラーになる。
regexを使う時は、キーに_を使わないようにしよう。
エラーメッセージ
Error: java.util.regex.PatternSyntaxException: named capturing group is missing trailing '>' near index 125 ^(?<from>[^%]+)%(?<uid>[^%]+)%(?<did>[^%]+)%(?<mid>[^%]+)%(?<type>[^%]+)%(?<to>[^%]+)%(?<status>[^%]+)%(?<ts>[^%]+)%(?<status_desc>[^%]+)%(?<host>[^%]+)%(?<uuid>[^%]+)$ ^
confg.ymlのサンプル
parser: type: regex # エラーが出る。 # regex: ^(?<from>[^%]+)%(?<uid>[^%]+)%(?<did>[^%]+)%(?<mid>[^%]+)%(?<type>[^%]+)%(?<to>[^%]+)%(?<status>[^%]+)%(?<ts>[^%]+)%(?<status_desc>[^%]+)%(?<host>[^%]+)%(?<uuid>[^%]+)$ # アンダースコアを消すとうまくいく。 regex: ^(?<from>[^%]+)%(?<uid>[^%]+)%(?<did>[^%]+)%(?<mid>[^%]+)%(?<type>[^%]+)%(?<to>[^%]+)%(?<status>[^%]+)%(?<ts>[^%]+)%(?<statusdesc>[^%]+)%(?<host>[^%]+)%(?<uuid>[^%]+)$ columns: (snip) # regex_nameもアンダースコアを修正 # - {name: status_desc, type: string, regex_name: status_desc} - {name: status_desc, type: string, regex_name: statusdesc} (snip)
Raspberry Pi 3でPhantomJSを使う
これをcloneすれば、すぐ使える。
parallel-slurpで、ファイルを並列で取得する
複数のホストから、ファイルをダウンロードする必要があったので、方法を調べた。
parallel-slurp(pslurp)という便利なものがあったので、使うことにした。
インストール
# apt install pssh
manを読むと、やりたことが書かれてる。
PARALLEL-SLURP(1) PARALLEL-SLURP(1) NAME parallel-slurp - copy files from listed hosts SYNOPSIS parallel-slurp [OPTIONS] -h hosts.txt -L destdir remote local DESCRIPTION pssh provides a number of commands for executing against a group of computers, using SSH. It´s most useful for operating on clusters of homogenously-configured hosts. parallel-slurp gathers specified files from hosts you listed. (snip)
使い方
対象ホストのリストを用意する。
$ cd /home/admin/ $ cat file_list a.example.com b.example.com c.example.com
ダウンロードしたファイル用のディレクトリを作成する。
$ mkdir downloads
parallel-slurpを実行する。
$ parallel-slurp -ladmin -h file_list -p 3 -L /home/admin/downloads /var/log/http_access.log http_access.log
引数の説明を簡単にする。
- -lは、作業ユーザ
- -hは、対象ホストのリスト
- -pは、並列処理数
- -Lは、ダウンロードしたファイルを置くディレクトリ
そのあとの引数は
- ダウンロードするファイルの絶対パス
- ダウンロードした際のファイルの名前
実行するとディレクトリは次のようになる。
$ tree downloads/ downloads/ ├── a.example.com │ └── http_access.log ├── b.example.com │ └── http_access.log └── c.example.com └── http_access.log 3 directories, 3 files
browsertimeで、Webページの描画過程を録画する
browsertimeを使い、Webページのロード時間を計測しながら、描画過程を録画する。
うまくいくとこんな感じで、録画できる。
browsertimeで生成されたmp4ファイル、HTMLの記述例などは、GitHubに置いた。
https://github.com/kentatogashi/example-browsertime
browsertimeの実行方法
OSは、Ubuntu16.04を使う。
Dockerを入れる。
# apt update # apt install -y docker.io
browsertimeを実行する
# docker run --privileged --shm-size=1g --rm -v "$(pwd)":/browsertime-results sitespeedio/browsertime -n 1 -c cable --video --speedIndex 'https://www.yahoo.com'
実行すると、ディレクトリが生成され、動画や画像が格納される。
$ tree www.yahoo.com www.yahoo.com └── 2017-02-14T043457+0000 ├── browsertime.har ├── browsertime.json └── video ├── 0.mp4 └── images └── 0 ├── ms_000000.jpg (snip) └── ms_007950.jpg 4 directories, 78 files
HTTP/1.1とHTTP/2の比較計測をする際に、はかどりそう。
あと、日本語サイトに対して、実行すると文字化けするので、ちょっと残念なところはある。
参考 - GitHub - sitespeedio/browsertime: Your browser, your page, your scripts!
外部サーバにSquid3でプロキシを立てる
プロキシを設定したときの走り書きです。
環境は、Ubuntu14.04.3 LTSです。
インストール
# apt-get install -y squid3
設定ファイル
/etc/squid3/squid.confをコピーして使う。特定のACLからの80と443ポートへのアクセスをフォワードするように 最低限の設定をする。
acl localnet src ***.***.***.***/23 acl SSL_ports port 443 acl Safe_ports port 80 acl Safe_ports port 443 acl CONNECT method CONNECT http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access allow localhost http_access allow localnet http_access deny all http_port 3128 cache_dir ufs /var/spool/squid3 600 16 256 coredump_dir /var/spool/squid3 refresh_pattern . 0 20% 4320 access_log /var/log/squid3/access.log common
再起動する。
# restart squid3
curlで、動作確認する。
ACLで許可したサーバからプロキシ経由でアクセスした場合
$ curl -I -x proxy.example.com:3128 -L blog.hatena.ne.jp HTTP/1.1 302 Moved Temporarily Cache-Control: private Content-Type: text/html; charset=utf-8 Date: Sun, 08 Jan 2017 04:25:05 GMT Location: https://www.hatena.ne.jp/login?location=http%3A%2F%2Fblog.hatena.ne.jp%2F P3P: CP="OTI CUR OUR BUS STA" Server: nginx Set-Cookie: b=$1$hgANMQcX$tV164HRhox4dVoyOz9eGh1; expires=Sat, 03-Jan-2037 04:25:05 GMT; domain=hatena.ne.jp; path=/ Set-Cookie: sk=99c1e798a67850410e453590e89a8cc9025ffb7f; path=/ Vary: Accept-Language, Cookie X-Content-Type-Options: nosniff X-Dispatch: Hatena::Epic::Admin::Index#default X-Frame-Options: DENY X-Revision: 81eb8b22d9cef6ded0b861732d7ed075 X-Runtime: 0.007440 X-XSS-Protection: 1 X-Cache: MISS from *********** X-Cache-Lookup: MISS from ***********:3128 Via: 1.1 **********(squid/3.3.8) Connection: keep-alive HTTP/1.1 200 Connection established HTTP/1.1 200 OK Server: nginx Date: Sun, 08 Jan 2017 04:25:06 GMT Content-Type: text/html; charset=utf-8 Content-Length: 8393 Connection: keep-alive Vary: Accept-Encoding Cache-Control: no-cache Pragma: no-cache Vary: Accept-Language,Accept-Encoding,User-Agent X-Frame-Options: SAMEORIGIN X-Framework: Ridge/0.11 Plack/0.9982 X-Ridge-Dispatch: Hatena::WWW::Engine::Login#default X-Runtime: 79ms X-View-Runtime: 54ms Set-Cookie: b=$1$nniOFGW0$4HjT61d1E1yqllw58ss1o/; path=/; expires=Sat, 03-Jan-37 04:25:05 GMT; domain=.hatena.ne.jp
ACLで許可しないサーバからプロキシ経由でアクセスした場合
$ curl -I -x proxy.example.com:3128 -L blog.hatena.ne.jp HTTP/1.1 403 Forbidden Server: squid/3.3.8 Mime-Version: 1.0 Date: Sun, 08 Jan 2017 04:31:45 GMT Content-Type: text/html Content-Length: 3186 X-Squid-Error: ERR_ACCESS_DENIED 0 Vary: Accept-Language Content-Language: en X-Cache: MISS from ****** X-Cache-Lookup: NONE from ******:3128 Via: 1.1 ****** (squid/3.3.8) Connection: keep-alive