More Related Content
Similar to Norikraで作るPHPの例外検知システム YAPC::Asia Tokyo 2015 LT (20)
More from Masahiro Nagano (20)
Norikraで作るPHPの例外検知システム YAPC::Asia Tokyo 2015 LT
- 5. Try-Catch
try {
throw new MyAppException('Boofy');
} catch (Exception $e ) {
$msg = json_encode(array(
'message' => $e->getMessage(),
'_exception' => array(
'class' => get_class($e),
'message' => $e->getMessage(),
'trace' => ..
),
)). "n";
error_log($msg, 3, '/path/to/app_error_log');
}
- 15. fluentd
<source>
type tail
format json
path /path/to/app_error_log
tag nohostname.error_app_log
</source>
<source>
type tail
format /^[(?<time>[^]]*)] (?<message>.*)$/
time_format %d-%b-%Y %H:%M:%S
path /path/to/php_log
tag nohostname.apache_error
</source>
<source>
type tail
format /^[[^ ]* (?<time>[^]]*)] [(?<level>[^]]*)](?: [pid (?<pid>[^]]*)])? [client (?<client>[^]]*)] (?<message>.*?)(?:, referer: (?
<referer>.*))?$/
path /path/to/error_log
tag nohostname.apache_error
</source>
<source>
type tail
format /^[[^ ]* (?<time>[^]]*)] [(?<level>[^]]*)](?: [pid (?<pid>[^]]*)])? [client (?<client>[^]]*)] (?<message>.*?)(?:, referer: (?
<referer>.*))?$/
path /var/log/httpd/error_log
tag nohostname.apache_error
</source>
<match nohostname.**>
type record_reformer
tag ${tag_suffix[1]}
hostname ${hostname}
</match>
<match {error_app_log,apache_error}>
type forward
<server>
name cep
host cep
</server>
</match>
in_tail x 4
hostname追加
集約サーバへの送信
- 17. Norikra Query
SELECT
"alert-channel" as channel,
"[..][" || hostname || "] Detect *"
|| CAST(COUNT(*), string)
|| "* PDOException in this 1min: ```" || message
|| "``` action: `"
|| COALESCE(NULLABLE(action),"-") || "`" AS msg
FROM error_app_log.win:time_batch(1 min)
WHERE exception.class = "PDOException"
OR ( _exception.class = "ErrorException"
AND _exception.message LIKE "PDOStatement%" )
GROUP BY hostname, message, action
HAVING COUNT(*) > 0