Skip to content

Instantly share code, notes, and snippets.

@hqingyi
Created March 24, 2016 03:05
Show Gist options
  • Save hqingyi/4917f9da00cd00990f25 to your computer and use it in GitHub Desktop.
Save hqingyi/4917f9da00cd00990f25 to your computer and use it in GitHub Desktop.
haproxy -> fluentd forwarder -> fluentd server -> elasticsearch -> kibana
<source>
type tail
path /var/log/haproxy.log
pos_file /var/log/td-agent/haproxy.log.pos
tag haproxy.http
format /^(?<syslog_time>.+) (?<source_ip>.+) (?<ps>\w+)\[(?<pid>\d+)\]: (?<c_ip>[\w\.]+):(?<c_port>\d+) \[(?<time>.+)\] (?<f_end>[\w\.-]+) (?<b_end>[\w\.-]+)\/(?<b_server>[^ ]+) (?<tq>[-]?\d+)\/(?<tw>[-]?\d+)\/(?<tc>[-]?\d+)\/(?<tr>[-]?\d+)\/(?<tt>\d+) (?<status_code>\d+) (?<bytes_read>\d+) (?<captured_request_cookie>.+) (?<captured_response_cookie>.+) (?<termination_state>.+) (?<actconn>\d+)\/(?<feconn>\d+)\/(?<beconn>\d+)\/(?<srv_conn>\d+)\/(?<retries>\d+) (?<srv_queue>\d+)\/(?<backend_queue>\d+) \"(?<http_request>.+)\"$/
time_format %d/%b/%Y:%H:%M:%S.%L
</source>
<match *.**>
type secure_forward
shared_key ...
self_hostname ...
secure no
<server>
host ...
</server>
</match>
# Input
<source>
@type secure_forward
shared_key ...
self_hostname ...
port 24284
secure no
</source>
# Output
<match *.**>
type copy
<store>
type elasticsearch
host localhost
port 9200
include_tag_key true
tag_key log_name
logstash_format true
flush_interval 1s
</store>
</match>
global
daemon
maxconn 20480
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
defaults
log global
$ModLoad imudp
$UDPServerAddress 127.0.0.1
$UDPServerRun 514
# haproxy
local0.* /var/log/haproxy.log
&stop
local1.* /var/log/haproxy1.log
&stop
$AddUnixListenSocket /var/lib/haproxy/dev/log
# Send HAProxy messages to a dedicated logfile
if $programname startswith 'haproxy' then /var/log/haproxy.log
&~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment