hetemlにMackerelをいれてみたかったけどだめだった

hetemlみたいなrootをくれないレンタルサーバーの監視がしたかったので
MackerelエージェントがGo言語でかかれてバイナリおいたら監視できるようなので試してみました

hetemlにはcurlコマンドがないので、ローカルでダウンロードしておきます

$ curl -O http://file.mackerel.io/agent/tgz/mackerel-agent-latest.tar.gz

scpであげます
$ scp mackerel-agent-latest.tar.gz (hetemlのサーバー)

以下、sshでつないでhetemlサーバーでの作業
$ cd mackerel-agent/

自分のapikeyを記載
$ vim mackerel-agent.conf
apikey = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”

起動
$ ./mackerel-agent –conf=./mackerel-agent.conf

エラー!

runtime: panic before malloc heap initialized
fatal error: runtime: cannot reserve arena virtual address space

runtime stack:
runtime.throw(0x843ed32)
        /opt/local/go/src/runtime/panic.go:491 +0x83 fp=0xff958f3c sp=0xff958f24
runtime.mallocinit()
        /opt/local/go/src/runtime/malloc.c:223 +0xef fp=0xff958f78 sp=0xff958f3c
runtime.schedinit()
        /opt/local/go/src/runtime/proc.c:137 +0x3a fp=0xff958f90 sp=0xff958f78
runtime.rt0_go(0xff959024, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /opt/local/go/src/runtime/asm_386.s:100 +0xf9 fp=0xff958f94 sp=0xff958f90

諦めました
まー、だめですよね..

vagrant内のmysqlにworkbenchでアクセスする

sshを使ってやるのがいいと思います
vagrant内のmysqlは外からつながるようにしておいて

参考)mysqlに外からアクセスする

workbenchの設定はこんな感じ

workbench

Connection Method: Standard TCP/IP over SSH
SSH Hostnam : 127.0.0.1:2222
SSH username : vagrant
MySQL Hostn : 127.0.0.1
MySQL Server : 3306
Username : user

ユーザーとパスワードは環境に合わせてください

Workbenchでつなぐときに
known_hostsを消せ、とかエラーが出たら

$ ssh-keygen -R [127.0.0.1]:2222

で回避できます

mysqlに外からアクセスする

mysql入のサーバーへ外からmysqlにつないでみました
mysqlにログインしてユーザーを見てみます

$ mysql -u root -p
とかではいってまずは確認

mysql> select user, host from mysql.user;

+------------------+--------------------------+
| user             | host                     |
+------------------+--------------------------+
| root             | 127.0.0.1                |
| root             | ::1                      |
| root             | localhost                |
+------------------+--------------------------+

hostがつなぐとことができるものです
そとからつなげるユーザーを増やしてみます

mysql> grant all privileges on . to user@”%” identified by ‘password’ with grant option;

確認

mysql> select user, host from mysql.user;

+------------------+--------------------------+
| user             | host                     |
+------------------+--------------------------+
| user             | %                        |
| root             | 127.0.0.1                |
| root             | ::1                      |
| root             | localhost                |
+------------------+--------------------------+

これでuserというユーザーが外からつなげます

192.168.0.2のサーバーにつなぐとしたら
$ mysql -h 192.168.0.2 -u user -p
とコマンドをたたいてつながるか確認できます

Cakephpのコントローラーでpaginateをトップページに飛ばす

ページ制御 — CakePHP Cookbook 2.x ドキュメント
であるように存在しないページにアクセスされた時の処理を書いてみました

試行錯誤した結果、これで..

$this->Paginator->settings = $paginate;
try {
    $companies =  $this->Paginator->paginate($mainModel);
} catch (NotFoundException $e) {
    $whiteList = $this->Paginator->whitelist;
    $key = array_search('page', $whiteList);
    if ($key !== false) {
        unset($whiteList[$key]);
    }
    $this->Paginator->whitelist = $whiteList;
    $companies =  $this->Paginator->paginate();
}

whiteListからpageを外してpageの指定を無視させてます
アドレスが
http://sample.net/page:2
とか残ったままですが、最初のページ(page:1)が表示されます

うーん、もっといいやりかたがあるような気がします