1. 新增下列到/etc/bashrc中
export PROMPT_COMMAND='RETRN_VAL=$?;logger -p local6.debug "$(whoami) [$$]: $(history 1 | sed "s/^[ ]*[0-9]\+[ ]*//" ) [$RETRN_VAL]"'
若您使用的是ubuntu,則檔案為/etc/bash.bashrc。若使用centos,檔案為/etc/profile
ps. /etc/profile或/etc/bashrc等檔案要視順序設定,可參考http://www.51testing.com/?uid-225738-action-viewspace-itemid-216622
2. 新增下列到/etc/syslog.conf
local6.* /var/log/commands
3. 若需要log rotate,則新增/var/log/commands這行到/etc/logrotate.d/rsyslog中 (以ubuntu為例,若您使用centos則是/etc/logrotate.d/syslog)
4. 參考資料
http://blog.kxr.me/view/classic
http://efreedom.com/Question/6-93566/Log-Bash-Commands-Users-Server
2012年8月7日 星期二
2012年6月22日 星期五
Pylons profiling工具 -- repoze.profile
repoze.profile可以針對WSGI進行完整的profiling,本文特別針對Pylons的使用做簡單說明
1. 安裝
只要使用
http://pypi.python.org/pypi/repoze.profile
http://docs.repoze.org/profile/#viewing-the-profile-statistics
http://nickmurdoch.livejournal.com/392632.html
1. 安裝
只要使用
$ easy_install repoze.profile
下完指令即可安裝完成
2. 設定
直接在pylons的middleware.py修改如下
from repoze.profile.profiler import AccumulatingProfileMiddleware
# ...
def make_app(.....):
load_environment(global_conf, app_conf)
app = PylonsApp()
app = AccumulatingProfileMiddleware(
app,
log_filename='/tmp/profiling.log',
cachegrind_filename='/tmp/cachegrind.out',
discard_first_request=True,
flush_at_shutdown=True,
path='/__profile__'
)
app = RoutesMiddleware(app, config['routes.map'])
app = SessionMiddleware(app, config)
app = CacheMiddleware(app, config)
#.....
log_filename代表profiling log檔案存放位置
cachegrind_filename代表要給KCachegrind工具觀看的profiling log檔案存放位置
discard_first_request代表要不要忽略第一次檢視的結果,因為通常第一次的數據都會比較不正常而影響了整體的結果
flush_at_shutdown代表middleware instance不存在時是否要將profiling結果刪掉
path顧名思義就是利用browser檢視profile結果的URI
設定完成後重起httpd server
3. 確認結果
確認 http://localhost/__profile__ 能否存取
理論上可以看到畫面如下
4. 使用KCachegrind檢視
5. 參考資料
http://pypi.python.org/pypi/repoze.profile
http://docs.repoze.org/profile/#viewing-the-profile-statistics
http://nickmurdoch.livejournal.com/392632.html
訂閱:
文章 (Atom)

