monit on ubuntu error connecting to the monit daemon

Install

sudo apt-get install monit

Start

sudo service monit start

When i tried monit status, i got the error message:

monit: error connecting to the monit daemon

Solution

vi /etc/monit/monitrc

uncomment the follow lines

set httpd port 2812 and
use address localhost
allow localhost

Save and restart

service monit restart

Check port netstat -lpn | grep 2812

tcp        0      0 127.0.0.1:2812          0.0.0.0:*               LISTEN      16331/monit

Run monit status

The Monit daemon 5.3.2 uptime: 0m

System 'system_AY1404211138578652eaZ'
  status                            Running
  monitoring status                 Monitored
  load average                      [0.00] [0.01] [0.05]
  cpu                               0.0%us 0.0%sy 0.0%wa
  memory usage                      1779196 kB [86.7%]
  swap usage                        0 kB [0.0%]
  data collected                    Mon, 08 Dec 2014 11:35:57

更改默认的mysql和mongodb数据dbpath

修改mysql

sudo /etc/init.d/mysql stop
sudo cp -R -p /var/lib/mysql /newpath
sudo chown mysql:mysql /newpath
vi /etc/mysql/my.cnf
#####Look for lines beginning with /var/lib/mysql. Change /var/lib/mysql in the lines with the new path.
sudo /etc/init.d/mysql restart

修改mongodb

sudo service mongod stop
vi /etc/mongodb.conf

####
Change this:
dbpath=/var/lib/mongo

With:
dbpath=/home/myuser/data/mongo
###

cp -ra /var/lib/mongo  /home/myuser/data/mongo

chown mongodb:mongodb /home/myuser/data/mongo

sudo service mongod start

Mavericks mac 10.9 gem install json 1.8.1 error failed

升级到最新的mac os Mavericks。装json出现错误:

gem install json -v '1.8.1'


Building native extensions.  This could take a while...
ERROR:  Error installing json:
  ERROR: Failed to build gem native extension.

    /usr/local/var/rbenv/versions/2.0.0-p247/bin/ruby extconf.rb
creating Makefile

make "DESTDIR="
compiling generator.c
In file included from /usr/local/var/rbenv/versions/2.0.0-p247/include/ruby-2.0.0/ruby.h:33,
                 from ../fbuffer/fbuffer.h:5,
                 from generator.c:1:
/usr/local/var/rbenv/versions/2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:51:21: error: string.h: No such file or directory
/usr/local/var/rbenv/versions/2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:61:21: error: stdint.h: No such file or directory
/usr/local/var/rbenv/versions/2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:64:23: error: inttypes.h: No such file or directory
/usr/local/var/rbenv/versions/2.0.0-p247/include/ruby-2.0.0/ruby/ruby.h:68:19: error: stdio.h: No such file or directory

解决办法:

xcode-select --install

需要重新安装Command Line Developer Tools

参考链接installing-rails-on-mavericks

[2013-11-29]修改:
如果这个办法还是不行,mac下需要安装下apple-gcc42

brew install apple-gcc42

注意brew 0.9.4应该是不带apple-gcc42的源的,可以使用brew doctor检查下是否和Mavericks兼容,这里需要升级

brew update

one line log parser

ruby-one-liners

ruby global variables

log文件形如:

method=GET path=/v1/foods/near_by_want1 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want2 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want3 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want  format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want4 format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20
method=GET path=/v1/foods/near_by_want  format=html controller=api/v1/foods action=near_by_want status=200 duration=2005.69 view=0.20

得到near_by_want的平均处理时间

grep 'near_by_want' production.log-20130827 | awk '{print $7}' | ruby -n -e '@sum ||= 0; $_ =~ /^duration=(.+)/; @sum += $1.to_f; END { puts @sum / $. }'

unix bash 重定向到文件

# 重定向到file.txt,覆盖原来的
cmd > file.txt
# 重定向到file.txt,不覆盖,从最后开始添加
cmd >> file.txt
# 重定向 stdout 和 stderr 到file.txt,覆盖原来的
cmd &> file.txt
# 重定向 stdout 和 stderr 到file.txt,不覆盖,从最后开始添加
cmd >>file.txt 2>&1

1和2是什么?

`1` is the default file descriptor for stdout.
`2` is the default file descriptor for stderr.

in-the-shell-what-is-21