ã®è¨äºã®ããã«ãFluentdãGrowthForecastã使ã£ããã®ã³ã°ã£ã¦é¢ç½ããã ãªã¼ã¨æã£ã¦èªåã§ããã£ã¦ã¿ãã
ã¢ããªã±ã¼ã·ã§ã³æ¯ã®ã¢ã¯ãã£ããªæéãåã
ã¾ãèããã®ã¯ããããã¼ã¤ãã³ãçºç«åæ°ã»ã©ç´°ãããªãã¦ãããã¢ã¯ãã£ãã«ãã¦ããæéã®å²åããåãããããã¯ããã§è¯ãããªãã¨ã
1ç§ãã¨ã«ã¢ã¯ãã£ããªã¢ããªã調ã¹ã¦ãã®ã³ã°ãã¦ãããMac OS Xã«ããã¦ã¢ã¯ãã£ããªã¢ããªã±ã¼ã·ã§ã³ã調ã¹ããªãAppleScriptãç°¡åã
name of (info for (path to frontmost application))
ããã ãã§ã¢ã¯ãã£ãã«ãã¦ããã¢ããªã±ã¼ã·ã§ã³åãåããã
ãããã¯
tell application "System Events" name the first process whose frontmost is true end tell
ã¨ãã£ãå½¢ã§ããã»ã¹åã¨ãã¦åããã¨ãã§ãããããã以ä¸ã®ããã«å¤å½¢ãããã¨ãã§ããã
tell application "System Events" to name of first process whose frontmost is true
ãªãã«ããAppleScriptä¸è¡ã§åããã®ã§ãã¯ã³ã©ã¤ãã¼ã®ã³ãã³ãã§æ¸ãããfluentdã®configã§
<source>
type exec
command osascript -e 'name of (info for (path to frontmost application))'
keys application
tag application
run_interval 1s
</source>
ã®ããã«æ¸ãã°1ç§ãã¨ã«AppleScriptçµç±ã§ã¢ã¯ãã£ããªã¢ããªã±ã¼ã·ã§ã³åãemitãããããããdatacounterã§1åãã¨ã«éè¨ã
<match application> type datacounter count_key application count_interval 1m aggregate all tag counted.apps pattern1 iTerm iTerm.app pattern2 Emacs Emacs.app pattern3 Chrome Google Chrome.app pattern4 Twitter Twitter.app </match>
ããã§ä¸»è¦ãªã¢ããªãã©ããããã¢ã¯ãã£ãã«ãªã£ã¦ããããã ãããåãããã®ã§ããã®ã¾ã¾growthforecastã«æãã¦ãã¾ãã
<match counted.apps> type growthforecast gfapi_url http://gf.*****.my.server/api/ service sugyan section apps name_keys iTerm_percentage,Emacs_percentage,Chrome_percentage,Twitter_percentage,unmatched_percentage </match>
ãããªãããã§ããããã®ã¢ããªã®åä½æéãããã®ã¢ã¯ãã£ãçã®å¤åãã°ã©ãã§åãã¦ãè¤åã°ã©ãã«ããã¨
ã¨ãããããã§ãããããã®ã¸ãã¯ãã£ã¨Emacsã§ä½ãæ¸ãã¦ã¦ããã®ã¸ãã¯ãã£ã¨Twitterè¦ã¦ããªãã¨ããåããã
Emacsã®æåå ¥åæ°ãåã
Emacsã§è²ã
ä½æ¥ããå ´åã«ãã©ããªè¨èªãã©ããããæ¸ãã¦ãããâ¦ãããªãã¦ããmajor-modeãã¨ã«éè¨ã§ãããè¯ãããªãã¨ã
post-self-insert-hook
ã§æåå
¥åããéã«hookãã¦éåæããã»ã¹ããfluentdã«éä¿¡ããã
(defun my-insert-hook () (start-process "post-fluent" nil "curl" "-X" "POST" "-d" (concat "json={\"mode\":\"" (symbol-name major-mode) "\"}") "localhost:9880/emacs")) (add-hook 'post-self-insert-hook 'my-insert-hook)
ä¸è¨ã®ãããªelispãEmacsã®è¨å®ã«æ¸ãã¦ããã°ãæåãå
¥åããããã¨ã«ãã®ãããã¡ã®major-modeåãcurl
ã使ã£ã¦HTTPçµç±ã§emitãããã
start-process
é¢æ°ã¯éåæã«ã³ãã³ãå®è¡ãããã®ã§é£æãã¦ãã¦ãåä½ãéããªã£ããããªããã¨æãã
fluentdã®configã¯
<source> type http </source> <match emacs> type datacounter count_key mode count_interval 1m aggregate all tag counted.emacs pattern1 perl cperl-mode pattern2 ruby ruby-mode pattern3 javascript js2-mode pattern4 minibuffer minibuffer-inactive-mode </match> <match counted.emacs> type growthforecast gfapi_url http://gf.*****.my.server/api/ service sugyan section emacs name_keys perl_count,ruby_count,javascript_count,minibuffer_count,unmatched_count </match>
ã¨ãã£ãæãã§ã1åéãããã«æåå
¥åãèµ·ãã£ãåæ°ãmajor-modeæ¯ã«éè¨ãã¦ã°ã©ãåã§ããã
zshã®å®è¡ã³ãã³ããåã
zshã§ãã·ã§ã«ã³ãã³ãå®è¡åå¾ã«å¦çãæããã¨ãã§ããã®ã§ãå®è¡ããã³ãã³ãã§éè¨ãããã§ããã
function preexec_fluent() { curl -X POST -d 'json={"command":"'${1%% *}'"}' localhost:9880/zsh } preexec_functions=(preexec_fluent)
ã®ãããªãã®ã~/.zshrc
ã«æ¸ãã¦ããã°ãã³ãã³ãå®è¡ãããã³ã«ãã®ã³ãã³ãåãemitãããã(ããã«ã¯ã©ã¼ãã®ã¨ã¹ã±ã¼ãã¨ãããã¾ãèãã¦ããªããã©)
<source> type http </source> <match zsh> type datacounter count_key command count_interval 1m aggregate all tag counted.zsh pattern1 ls ls pattern2 cd cd </match> <match counted.zsh> type growthforecast gfapi_url http://gf.*****.my.server/api/ service sugyan section zsh name_keys ls_count,cd_count,unmatched_count </match>
ã³ãã³ããã¨ã«éè¨ããæå³ã¯ãã¾ãç¡ããããããªããã©ãç¹å®ã®ã³ãã³ãããã使ããã¨ããå ´åã¯å²åãç¥ããã¨ãã§ãã¦è¯ãããï¼
åè¨å¤ãåãã°1åãããã©ããããzshã§ã³ãã³ãå©ãã¦ããããã®æ¨ç§»ã¯åããã¨æãã
ãã®ä»
ã»ãã«ä½ãé¢ç½ããã¼ã¿åããããªã