fluentd에서 가장 까다로운 것이 로그를 정규표현식으로 분석하는 것이다.

잘못하면 로그가 drop될 수 있기 때문에.. 신중하게 써야 하는데.


헤로쿠의 다음 url에서 fluent의 정규 표현식을 테스트해볼 수 있다. 


http://fluentular.herokuapp.com/




예를 들어 다음 로그를


"192.168.6.118 - - [25/May/2014:23:44:21 +0000]  GET /images/templates/main/favicon_16_24_32.ico HTTP/1.1 \"200\" 1811 \"-\" \"test-domain.com\" test-domain.com \"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36\" \"-\" upstream_response_time 0.028 upstream_addr 192.168.6.7:8017 msec 1401061461.752 request_time 0.028"



다음과 같은 regex로 파싱할 수 있다. 


^(?<remote_addr>[^ ]*) - (?<remote_user>[^ ]*) \[(?<time>[^\]]*)\]\s+(?<request_type>[^ ]*) (?<request_url>[^ ]*) (?<request_http_protocol>[^ ]*) "(?<status>[^"]*)" (?<body_bytes_sent>[^ ]*) "(?<http_referer>[^"]*)" "(?<http_host>[^"]*)" (?<host>[^ ]*) "(?<http_user_agent>[^"]*)" "(?<http_x_forwarded_for>[^"]*)" upstream_response_time (?<upstream_response_time>[^ ]*) upstream_addr (?<upstream_addr>[^ ]*) msec (?<msec request_time>[^ ]*) request_time (?<request_time>[^ ]*)



url은 get으로 볼 수 있다.


http://fluentular.herokuapp.com/parse?regexp=%5E%28%3F%3Cremote_addr%3E%5B%5E+%5D*%29+-+%28%3F%3Cremote_user%3E%5B%5E+%5D*%29+%5C%5B%28%3F%3Ctime%3E%5B%5E%5C%5D%5D*%29%5C%5D%5Cs%2B%28%3F%3Crequest_type%3E%5B%5E+%5D*%29+%28%3F%3Crequest_url%3E%5B%5E+%5D*%29+%28%3F%3Crequest_http_protocol%3E%5B%5E+%5D*%29+%22%28%3F%3Cstatus%3E%5B%5E%22%5D*%29%22+%28%3F%3Cbody_bytes_sent%3E%5B%5E+%5D*%29+%22%28%3F%3Chttp_referer%3E%5B%5E%22%5D*%29%22+%22%28%3F%3Chttp_host%3E%5B%5E%22%5D*%29%22+%28%3F%3Chost%3E%5B%5E+%5D*%29+%22%28%3F%3Chttp_user_agent%3E%5B%5E%22%5D*%29%22+%22%28%3F%3Chttp_x_forwarded_for%3E%5B%5E%22%5D*%29%22+upstream_response_time+%28%3F%3Cupstream_response_time%3E%5B%5E+%5D*%29+upstream_addr+%28%3F%3Cupstream_addr%3E%5B%5E+%5D*%29+msec+%28%3F%3Cmsec+request_time%3E%5B%5E+%5D*%29+request_time+%28%3F%3Crequest_time%3E%5B%5E+%5D*%29&input=%22192.168.6.118+-+-+%5B25%2FMay%2F2014%3A23%3A44%3A21+%2B0000%5D++GET+%2Fimages%2Ftemplates%2Fmain%2Ffavicon_16_24_32.ico+HTTP%2F1.1+%5C%22200%5C%22+1811+%5C%22-%5C%22+%5C%22test-domain.com%5C%22+test-domain.com+%5C%22Mozilla%2F5.0+%28Windows+NT+6.3%3B+WOW64%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F35.0.1916.114+Safari%2F537.36%5C%22+%5C%22-%5C%22+upstream_response_time+0.028+upstream_addr+192.168.6.7%3A8017+msec+1401061461.752+request_time+0.028%22&time_format=






<source> 
  type tail 
  path /var/log/foo/bar.log 
  pos_file /var/log/td-agent/foo-bar.log.pos 
  tag foo.bar 
  format /^(?<remote_addr>[^ ]*) - (?<remote_user>[^ ]*) \[(?<time>[^\]]*)\]\s+(?<request_type>[^ ]*) (?<request_url>[^ ]*) (?<request_http_protocol>[^ ]*) "(?<status>[^"]*)" (?<body_bytes_sent>[^ ]*) "(?<http_referer>[^"]*)" "(?<http_host>[^"]*)" (?<host>[^ ]*) "(?<http_user_agent>[^"]*)" "(?<http_x_forwarded_for>[^"]*)" upstream_response_time (?<upstream_response_time>[^ ]*) upstream_addr (?<upstream_addr>[^ ]*) msec (?<msec request_time>[^ ]*) request_time (?<request_time>[^ ]*)/ 
</source>



Posted by '김용환'
,

[fluentd] format json

Cloud 2018. 4. 10. 18:20


아파치나 nginx로그를 fluentd로 전달하고 싶을 때 regex를 사용하는 것보다 format json을 사용하는 것이 좋다.


https://docs.fluentd.org/v0.12/articles/recipe-json-to-elasticsearch



<source>
  @type tail
  path /var/log/httpd-access.log #...or where you placed your Apache access log
  pos_file /var/log/td-agent/httpd-access.log.pos # This is where you record file position
  tag foobar.json #fluentd tag!
  format json # one JSON per line
  time_key time_field # optional; default = time
</source>


Posted by '김용환'
,


마라톤 lb에서 포트별 설정(첫 번째, 두 번째... 등등)을 할 수 있다. 


https://github.com/mesosphere/marathon-lb/blob/master/Longhelp.md


Templates

The following is a list of the available HAProxy templates. Some templates are global-only (such as HAPROXY_HEAD), but most may be overridden on a per service port basis using the HAPROXY_{n}_... syntax.





Labels

HAPROXY_0_MODE=http

HAPROXY_0_VHOST=plus.google.com

HAPROXY_0_SSL_CERT=/etc/ssl/marathon/250.pem



Posted by '김용환'
,



지도를 통한 미세먼지 

https://earth.nullschool.net/#current/chem/surface/level/overlay=cosc/orthographic=-234.88,34.11,1109







일본텐키

http://www.tenki.jp/particulate_matter/ (pc)

http://www.tenki.jp/lite/particulate_matter/  (모바일)






Posted by '김용환'
,


마라톤(marathon)에서 자원 (메모리)가 없으면 다음과 가은 에러가 발생한다. (비슷하게 다른 자원도 해결할 수 있다)


눈으로 볼 때는 메모리 자원 여유는 있지만.. 


앱을 재시작하면서 순간적으로 용량이 부족할 수 있기 때문에, 항상 기존 앱 + 새로 시작할 앱 사이에 2배 공간의 여유가 순간적으로 있을 수 있으니.. 적당하게 공간을 할애하는 것이 좋다. 


 



INFO Offer [c6424609-c06c-463b-91bb-97962d915e56-O374]. Considering resources with roles {googledev, *} without resident reservation labels. Not all basic resources satisfied: cpus SATISFIED (0.1 <= 0.1), mem NOT SATISFIED (256.0 > 176.0) (mesosphere.mesos.ResourceMatcher$:marathon-akka.actor.default-dispatcher-2)



INFO Offer [c6424609-c06c-463b-91bb-97962d915e56-O374]. Insufficient resources for [/plus-stage] (need cpus=0.1, mem=256.0, disk=0.0, gpus=0, ports=(), available in offer: [id { value: "c6424609-c06c-463b-91bb-97962d915e56-O374" } framework_id { value: "3549a1e4-9a61-4bb1-9a0a-8fc66d4e76f4-0000" } slave_id { value: "c6424609-c06c-463b-91bb-97962d915e56-S1" } hostname: "11.11.11.11" resources { name: "cpus" type: SCALAR scalar { value: 7.4 } role: "*" } resources { name: "mem" type: SCALAR scalar { value: 176.0 } role: "*" } resources { name: "disk" type: SCALAR scalar { value: 45240.0 } role: "*" } resources { name: "ports" type: RANGES ranges { range { begin: 31000 end: 31021 } range { begin: 31023 end: 31075 } range { begin: 31077 end: 31136 } range { begin: 31138 end: 31345 } range { begin: 31347 end: 31560 } range { begin: 31562 end: 31856 } range { begin: 31858 end: 32000 } } role: "*" } url { scheme: "http" address { hostname: "10.197.1.63" ip: "10.197.1.63" port: 5051 } path: "/slave(1)" }] (mesosphere.mesos.TaskBuilder$:marathon-akka.actor.default-dispatcher-2)




INFO Finished processing c6424609-c06c-463b-91bb-97962d915e56-O374 from 10.197.1.63. Matched 0 ops after 1 passes. cpus(*) 7.4; mem(*) 176.0; disk(*) 45240.0; ports(*) 31000->31021,31023->31075,31077->31136,31138->31345,31347->31560,31562->31856,31858->32000 left. (mesosphere.marathon.core.matcher.manager.impl.OfferMatcherManagerActor:marathon-akka.actor.default-dispatcher-25)





그러나... 마라톤에서는 계속 Deploying 으로 뜨고 자원도 좀 있었긴 했다...

mesos slave간에 통신으로 mesos에서 저런 에러를 내보낼 수 있다.. 마라톤 하위 버전(1.0.1이었음)이라면 의심해도 좋다.


mesos 슬레이브 에러 로그를 확인하니.. 메소스 통신 중에 문제가 있었고.. 그 여파가 마라톤에서 앱 배포가 문제가 발생했다.


E0409 18:14:34.853005  2198 slave.cpp:3456] Failed to update resources for container 41283b2f-3d3f-40d6-9c37-0011f1dfaa52 of executor 'plus-stage.489512aa-9618-11e7-8450-0242540dd87f' running task plus-stage.489512aa-9618-11e7-8450-0242540dd87f on status update for terminal task, destroying container: Failed to determine cgroup for the 'cpu' subsystem: Failed to read /proc/15390/cgroup: Failed to open file: No such file or directory




문제 해결을 하려면 메소스 버전업을 진행해야 한다. 


Posted by '김용환'
,