Documentation
¶
Index ¶
- Constants
- Variables
- type ACL
- type Conn
- func (c *Conn) AddACL(acl string, pattern string) error
- func (c *Conn) ClearACL(acl string) error
- func (c *Conn) DeleteACL(acl string, id string) error
- func (c *Conn) GetACL(acl string) (map[string]string, error)
- func (c *Conn) ListACL() ([]ACL, error)
- func (c *Conn) ListACLFiles() (map[string]ACL, error)
- func (c *Conn) RunCmd(cmd string) ([]string, error)
- type Frame
- type FrameMetadata
- type HTTPRequest
Examples ¶
Constants ¶
const ( TerminationClientAbort = 'C' TerminationServerAbort = 'S' TerminationDeny = 'P' TerminationLocal = 'L' TerminationExhausted = 'R' TerminationInternalError = 'I' TerminationServerGoingDown = 'D' TerminationActiveUp = 'U' TerminationAdmin = 'K' TerminationClientWait = 'c' TerminationServerWait = 's' TerminationNone = '-' )
https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#8.5
const ( SessionCloseRequest = 'R' SessionCloseQueue = 'Q' SessionCloseConnection = 'C' SessionCloseHeaders = 'H' SessionCloseData = 'D' SessionCloseLast = 'L' SessionCloseTarpit = 'T' SessionCloseNone = '-' )
const ( // TYPED-DATA : <TYPE:4 bits><FLAGS:4 bits><DATA> DataTypeNULL = 0 //<0> DataTypeBOOL = 1 //<1+FLAG> DataTypeINT32 = 2 //<2><VALUE:varint> DataTypeUINT32 = 3 //<3><VALUE:varint> DataTypeINT64 = 4 //<4><VALUE:varint> DataTypeUNIT64 = 5 //<5><VALUE:varint> DataTypeIPV4 = 6 //<6><STRUCT IN_ADDR:4 bytes> DataTypeIPV6 = 7 //<7><STRUCT IN_ADDR6:16 bytes> DataTypeSTRING = 8 //<8><LENGTH:varint><BYTES> DataTypeBINARY = 9 //<9><LENGTH:varint><BYTES> DataTypeRSVD1 = 10 DataTypeRSVD2 = 11 DataTypeRSVD3 = 12 DataTypeRSVD4 = 13 DataTypeRSVD5 = 14 DataTypeRSVD6 = 15 )
4 bits TYPED-DATA : <TYPE:4 bits><FLAGS:4 bits><DATA>
Variable-length integer (varint) are encoded using Peers encoding:
0 <= X < 240 : 1 byte (7.875 bits) [ XXXX XXXX ]
240 <= X < 2288 : 2 bytes (11 bits) [ 1111 XXXX ] [ 0XXX XXXX ]
2288 <= X < 264432 : 3 bytes (18 bits) [ 1111 XXXX ] [ 1XXX XXXX ] [ 0XXX XXXX ]
264432 <= X < 33818864 : 4 bytes (25 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*2 [ 0XXX XXXX ]
33818864 <= X < 4328786160 : 5 bytes (32 bits) [ 1111 XXXX ] [ 1XXX XXXX ]*3 [ 0XXX XXXX ]
const ( FrameHaproxyHello = 1 // Sent by HAProxy when it opens a connection on an agent. FrameHaproxyDisconnect = 2 // Sent by HAProxy when it want to close the connection or in reply to an AGENT-DISCONNECT frame FrameNotify = 3 // Sent by HAProxy to pass information to an agent FrameAgentHello = 101 // Reply to a HAPROXY-HELLO frame, when the connection is established FrameAgentDDisconnect = 102 // Sent by an agent just before closing the connection FrameAck = 103 // Sent to acknowledge a NOTIFY frame )
Variables ¶
var HaproxyLogTimezone = time.Local
HaproxyLogTimezone specifies in what timezone emitted logs are defaults to local as haproxy by default uses localtime in logs
Functions ¶
This section is empty.
Types ¶
type ACL ¶
type ACL struct {
// haproxy-assigned ID
ID int `json:"id"`
// path of external file that is source of this ACL entries
SourceFile string `json:"source_file"`
// type of ACL if it is from config or "file" if it sourced from file (haproxy doesnt return type here)
Type string `json:"type"`
// Line of inline ACL
Line int `json:"line"`
}
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
HAProxy socket interface
func New ¶
Setup new connection accepts path to haproxy unix socket
Example ¶
// start
ha := New("/var/run/haproxy.sock")
// clear all entries in ACL
_ = ha.ClearACL("inc/blacklist.lst")
func (*Conn) AddACL ¶
Add new entry to acl ACL name is either file path ( if haproxy config uses -f option to load acls from file ) or ACL id prepended with hash
Example ¶
// Initialize
ha := New("/var/run/haproxy.sock")
// Get ACL entries from file in config (via -f in haproxy cfg)
acls, _ := ha.GetACL("inc/blacklist.lst")
// Check if it exists and add
if acls["/bad/path"] == "" {
ha.AddACL("inc/blacklist.lst", acls["/bad/path"])
}
func (*Conn) ClearACL ¶
Clear all entries in ACL
Example ¶
// Initialize
ha := New("/var/run/haproxy.sock")
// clear all entries in ACL
_ = ha.ClearACL("inc/blacklist.lst")
func (*Conn) DeleteACL ¶
Example ¶
// Initialize
ha := New("/var/run/haproxy.sock")
// Get ACL entries from file in config (via -f in haproxy cfg)
acls, _ := ha.GetACL("inc/blacklist.lst")
// Check if it exists and delete
if acls["/bad/path"] != "" {
ha.DeleteACL("inc/blacklist.lst", acls["/bad/path"])
}
func (*Conn) GetACL ¶
Example ¶
// Initialize
ha := New("/var/run/haproxy.sock")
// Get ACL entries from file in config (via -f in haproxy cfg)
acls, _ := ha.GetACL("inc/blacklist.lst")
for k, v := range acls {
fmt.Println(k, ":\t", v)
}
func (*Conn) ListACLFiles ¶
Return map with all external files that are used as ACL entry source with first occurence of ACL as a value
type FrameMetadata ¶
type HTTPRequest ¶
type HTTPRequest struct {
TS int64 `json:"ts_us"`
PID int `json:"pid"` // necessary to distinguish conns hitting different processes
ClientIP string `json:"client_ip"`
ClientPort uint16 `json:"client_port"`
ClientSSL bool `json:"client_ssl"`
FrontendName string `json:"frontend_name"`
BackendName string `json:"backend_name"`
ServerName string `json:"server_name"`
StatusCode int16 `json:"status_code"`
BytesRead uint64 `json:"bytes_read"`
CapturedRequestCookie string `json:"captured_request_cookie"`
CapturedResponseCookie string `json:"captured_response_cookie"`
// It is not possible to distinguish between "just captured request headers" and "just captured response headers"
// so we let user sort it out
CapturedSamples string
// timings
// aborted connections are marked via -1 by haproxy
RequestHeaderDurationMs int `json:"request_header_duration_ms"` // Tq
QueueDurationMs int `json:"queue_duration_ms"` // Tw
ServerConnDurationMs int `json:"server_conn_duration_ms"` // Tc
ResponseHeaderDurationMs int `json:"response_header_duration_ms"` // Tr
TotalDurationMs int `json:"total_duration_ms"` // Tt
RequestPath string `json:"http_path"`
RequestMethod string `json:"http_method"`
HTTPVersion string `json:"http_version"`
// Connection state
TerminationReason rune `json:"termination_reason"`
SessionCloseState rune `json:"session_close_state"`
ClientPersistenceState rune `json:"client_persistence_state"`
PersistenceCookieState rune `json:"persistence_cookie"`
// conn count stats (per-pid
TotalConn uint `json:"total_conn"`
FrontendConn uint `json:"frontend_conn"`
BackendConn uint `json:"backend_conn"`
ServerConn uint `json:"server_conn"`
Retries uint `json:"retries"`
ServerQueue uint `json:"server_queue"`
BackendQueue uint `json:"backend_queue"`
// flags
BadReq bool `json:"bad_request"`
Truncated bool `json:"truncated"`
}
HAProxy http log format https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#8.2.3
func DecodeHTTPLog ¶
func DecodeHTTPLog(s string) (HTTPRequest, error)
func (HTTPRequest) Timestamp ¶ added in v0.0.5
func (h HTTPRequest) Timestamp() time.Time