haproxy

package
v1.29.0-alpha.145 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package haproxy xxx

Index

Constants

This section is empty.

Variables

View Source
var (
	// LoadbalanceHaproxyStatsFetchStateMetric loadbalance metric for zookeeper connection
	LoadbalanceHaproxyStatsFetchStateMetric = prometheus.NewGauge(
		prometheus.GaugeOpts{
			Namespace: "loadbalance",
			Subsystem: "haproxy",
			Name:      "fetchstats_state",
			Help:      "the state for haproxy stats fetching state, 0 for abnormal, 1 for normal",
		},
	)
)

Functions

func NewManager

func NewManager(lbName, binPath, cfgPath, generatePath, backupPath, templatePath string,
	statusFetchPeriod int) (conf.Manager, error)

NewManager create haproxy config file manager

Types

type Config

type Config struct {
	LogEnabled         bool
	LogLevel           string
	SockPath           string
	ThreadNum          int64
	MaxConn            int64
	PidPath            string
	SSLCert            string
	DefaultProxyConfig *ProxyDefault
	Stats              *StatsFrontend
	// map[ServicePort]
	HTTPMap  map[int]*HTTPFrontend
	HTTPSMap map[int]*HTTPFrontend
	TCPMap   map[int]*TCPListener
	// data for render template in order
	HTTPList  HTTPFrontendList
	HTTPSList HTTPFrontendList
	TCPList   TCPListenerList
}

Config data structure for haproxy config file

type EnvConfig

type EnvConfig struct {
	LogEnabled                bool
	LogLevel                  string
	SockPath                  string
	ThreadNum                 int64
	MaxConn                   int64
	PidPath                   string
	SSLCert                   string
	Retries                   int64
	Backlog                   int64
	ProxyMaxConn              int64
	ProxyTimeoutConnection    int64
	ProxyTimeoutClient        int64
	ProxyTimeoutServer        int64
	ProxyTimeoutTunnel        int64
	ProxyTimeoutHTTPKeepAlive int64
	ProxyTimeoutHTTPRequest   int64
	ProxyTimeoutQueue         int64
	ProxyTimeoutTarpit        int64
	ProxyOptions              []string
	HTTPProxyOptions          []string
	ServerHealthCheckInterval int64
	ServerRiseHealthCheckNum  int64
	ServerFallHealthCheckNum  int64
	StatsFrontendPort         int64
	StatsFrontendURI          string
	StatsFrontendAuthUser     string
	StatsFrontendAuthPassword string
}

EnvConfig config for haproxy from env

type HTTPBackend

type HTTPBackend struct {
	Name                string
	Domain              string
	URL                 string
	Balance             string
	HealthCheckInterval int64
	RiseHealthCheckNum  int64
	FallHealthCheckNum  int64
	// map[IP]
	Servers map[string]*RealServer
	// data for render template in order
	ServerList RealServerList
}

HTTPBackend http backend

type HTTPBackendList

type HTTPBackendList []*HTTPBackend

HTTPBackendList http backend list

func (HTTPBackendList) Len

func (hl HTTPBackendList) Len() int

Len 用于排序

func (HTTPBackendList) Less

func (hl HTTPBackendList) Less(i, j int) bool

Less 用于排序

func (HTTPBackendList) Swap

func (hl HTTPBackendList) Swap(i, j int)

Swap 用于排序

type HTTPFrontend

type HTTPFrontend struct {
	ServicePort int
	Name        string
	// map[ServiceName]
	Backends map[string]*HTTPBackend
	// data for render template in order
	BackendList HTTPBackendList
}

HTTPFrontend http frontend

type HTTPFrontendList

type HTTPFrontendList []*HTTPFrontend

HTTPFrontendList http frontend list, sorted by service port

func (HTTPFrontendList) Len

func (hl HTTPFrontendList) Len() int

Len 用于排序

func (HTTPFrontendList) Less

func (hl HTTPFrontendList) Less(i, j int) bool

Less 用于排序

func (HTTPFrontendList) Swap

func (hl HTTPFrontendList) Swap(i, j int)

Swap 用于排序

type IPRealServerList

type IPRealServerList []*RealServer

IPRealServerList real server list, sorted by ip

func (IPRealServerList) Len

func (hl IPRealServerList) Len() int

Len 用于排序

func (IPRealServerList) Less

func (hl IPRealServerList) Less(i, j int) bool

Less 用于排序

func (IPRealServerList) Swap

func (hl IPRealServerList) Swap(i, j int)

Swap 用于排序

type Manager

type Manager struct {
	Cluster         string // cluster id
	LoadbalanceName string // loadbalance instance id

	ConfigCache *Config
	// contains filtered or unexported fields
}

Manager implements TemplateManager interface, control haproxy config file generating, validation, backup and reloading

func (*Manager) CheckDifference

func (m *Manager) CheckDifference(oldFile, curFile string) bool

CheckDifference two file are difference, true is difference

func (*Manager) Collect

func (m *Manager) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus exporter Collect interface

func (*Manager) Create

func (m *Manager) Create(tmpData *types.TemplateData) (string, error)

Create config file with tmpData,

func (*Manager) Describe

func (m *Manager) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus exporter Describe interface

func (*Manager) GetStatusFunction

func (m *Manager) GetStatusFunction() restful.RouteFunction

GetStatusFunction get status function

func (*Manager) Reload

func (m *Manager) Reload(cfgFile string) error

Reload haproxy with new config file

func (*Manager) Replace

func (m *Manager) Replace(oldFile, curFile string) error

Replace old cfg file with cur one, return old file backup

func (*Manager) Start

func (m *Manager) Start() error

Start point, do not block

func (*Manager) Stop

func (m *Manager) Stop()

Stop stop

func (*Manager) TryUpdateWithoutReload

func (m *Manager) TryUpdateWithoutReload(tmpData *types.TemplateData) (needReload bool)

TryUpdateWithoutReload update haproxy config without reloading needReload: true for reload

func (*Manager) Validate

func (m *Manager) Validate(newFile string) bool

Validate new cfg file grammar is OK

type ProxyDefault

type ProxyDefault struct {
	Retries              int64
	Backlog              int64
	MaxConn              int64
	TimeoutConnection    int64
	TimeoutClient        int64
	TimeoutServer        int64
	TimeoutTunnel        int64
	TimeoutHTTPKeepAlive int64
	TimeoutHTTPRequest   int64
	TimeoutQueue         int64
	TimeoutTarpit        int64
	Options              []string
	HTTPOptions          []string
}

ProxyDefault default config for proxy

type RealServer

type RealServer struct {
	Name     string
	IP       string
	Port     int
	Weight   int
	Disabled bool
}

RealServer backend config

func (*RealServer) Key

func (rs *RealServer) Key() string

Key generate the map key for real server in backend

type RealServerList

type RealServerList []*RealServer

RealServerList real server list, sorted by name

func (RealServerList) Len

func (hl RealServerList) Len() int

Len 用于排序

func (RealServerList) Less

func (hl RealServerList) Less(i, j int) bool

Less 用于排序

func (RealServerList) Swap

func (hl RealServerList) Swap(i, j int)

Swap 用于排序

type RuntimeClient

type RuntimeClient struct {
	SockPath string
	// contains filtered or unexported fields
}

RuntimeClient haproxy runtime client

func NewRuntimeClient

func NewRuntimeClient(sockPath string) (*RuntimeClient, error)

NewRuntimeClient create runtime client

func (*RuntimeClient) ExecuteCommand

func (rc *RuntimeClient) ExecuteCommand(cmd string) error

ExecuteCommand send command to haproxy

func (*RuntimeClient) ExecuteRaw

func (rc *RuntimeClient) ExecuteRaw(cmd string) (string, error)

ExecuteRaw execute raw command

func (*RuntimeClient) GetInfo

func (rc *RuntimeClient) GetInfo() (models.ProcessInfoHaproxy, error)

GetInfo get info of haproxy

func (*RuntimeClient) GetStats

func (rc *RuntimeClient) GetStats() *models.NativeStatsCollection

GetStats get statistic of haproxy

func (*RuntimeClient) NewDisableServerCommand

func (rc *RuntimeClient) NewDisableServerCommand(backend, server string) string

NewDisableServerCommand create new command that disable unused server

func (*RuntimeClient) NewEnableServerCommand

func (rc *RuntimeClient) NewEnableServerCommand(backend, server string) string

NewEnableServerCommand create new command that enable unused server

func (*RuntimeClient) NewSetServerAddrCommand

func (rc *RuntimeClient) NewSetServerAddrCommand(backend, server, addr string, port int) string

NewSetServerAddrCommand create new command that set server addr

func (*RuntimeClient) NewSetServerWeightCommand

func (rc *RuntimeClient) NewSetServerWeightCommand(backend, server string, weight int) string

NewSetServerWeightCommand create new command that set server weight

type Server

type Server struct {
	Name               string `json:"name"`
	ServerName         string `json:"server_name"`
	CurrentQueue       int64  `json:"current_queue"`
	MaxQueue           int64  `json:"max_queue"`
	CurrentSession     int64  `json:"current_session"`
	MaxSession         int64  `json:"max_session"`
	SessionLimit       int64  `json:"session_limit"`
	SessionTotal       int64  `json:"session_total"`
	BytesIn            int64  `json:"bytes_in"`
	BytesOut           int64  `json:"bytes_out"`
	RequestDeny        int64  `json:"request_deny"`
	ResponseDeny       int64  `json:"response_deny"`
	RequestError       int64  `json:"request_error"`
	ConnectError       int64  `json:"connect_error"`
	ResponseError      int64  `json:"response_error"`
	ConnectRetry       int64  `json:"connect_retry"`
	ConnectRedispatch  int64  `json:"connect_redispatch"`
	Status             string `json:"status"`
	Weight             int64  `json:"weight"`
	Active             int64  `json:"active_server_num"`
	Backup             int64  `json:"backup_server_num"`
	CheckFail          int64  `json:"check_fail_num"`
	CheckDown          int64  `json:"check_down_num"`
	DownTime           int64  `json:"down_time_second"`
	DownTimeTotal      int64  `json:"down_time_total"`
	QueueMaxLimit      int64  `json:"queue_limit"`
	CurrentSessionRate int64  `json:"current_session_rate"`
	MaxSessionRate     int64  `json:"max_session_rate"`
	SessionRateLimit   int64  `json:"session_rate_limit"`
	CheckStatus        string `json:"check_status"`
	RequestRate        int64  `json:"request_rate"`
	RequestMaxRate     int64  `json:"request_max_rate"`
	RequestTotal       int64  `json:"request_total"`
	LastSessionSecond  int64  `json:"last_session_second"`
	LastCheckContent   string `json:"last_check_content"`
	Address            string `json:"address"`
	Mode               string `json:"mode"`
	ConnectRate        int64  `json:"connect_rate"`
	ConnectMaxRate     int64  `json:"connect_max_rate"`
}

Server server info for haproxy

type Service

type Service struct {
	Frontend *Server   `json:"frontend"`
	Backend  *Server   `json:"backend"`
	Servers  []*Server `json:"servers"`
}

Service service info for haproxy

type StatsFrontend

type StatsFrontend struct {
	Port         int64
	URI          string
	AuthUser     string
	AuthPassword string
}

StatsFrontend stats for frontend

type Status

type Status struct {
	HaproxyPid   int64      `json:"haproxy_pid"`
	UpTime       string     `json:"up_time"`
	UpTimeSecond int64      `json:"up_time_second"`
	ULimitN      int64      `json:"ulimit_n"`
	SystemLimit  string     `json:"system_limits"`
	MaxSock      int64      `json:"max_sock"`
	MaxConn      int64      `json:"max_conn"`
	MaxPipes     int64      `json:"max_pipes"`
	CurrentConn  int64      `json:"current_conn"`
	CurrentPipes int64      `json:"current_pipes"`
	ConnRate     int64      `json:"conn_rate"`
	ConnMaxRate  int64      `json:"conn_max_rate"`
	Services     []*Service `json:"services"`
}

Status status info for haproxy

type StatusResponse

type StatusResponse struct {
	Code    int     `json:"code"`
	Message string  `json:"message"`
	Data    *Status `json:"data"`
}

StatusResponse response for status api

type TCPListener

type TCPListener struct {
	ServicePort         int
	Name                string
	Balance             string
	HealthCheckInterval int64
	RiseHealthCheckNum  int64
	FallHealthCheckNum  int64
	// map[IP]
	Servers map[string]*RealServer
	// data for render template in order
	ServerList RealServerList
}

TCPListener tcp frontend

type TCPListenerList

type TCPListenerList []*TCPListener

TCPListenerList tcp listener list for sort

func (TCPListenerList) Len

func (hl TCPListenerList) Len() int

Len 用于排序

func (TCPListenerList) Less

func (hl TCPListenerList) Less(i, j int) bool

Less 用于排序

func (TCPListenerList) Swap

func (hl TCPListenerList) Swap(i, j int)

Swap 用于排序

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL