Documentation
¶
Index ¶
- func StartMetricsServer(addr string, handler http.Handler) error
- type DBProtocol
- type HandshakeInfo
- type HandshakeParser
- type MetricsSnapshot
- type MySQLConnectionPool
- type MySQLHandshakeParser
- type MySQLInterceptor
- type PoolStats
- type PostgreSQLHandshakeParser
- type PrometheusMetrics
- type RdsConnectionHandler
- type RdsMetrics
- type RdsProxyServiceImpl
- func (m *RdsProxyServiceImpl) CloseSession(sessionID string) error
- func (m *RdsProxyServiceImpl) GetActiveSessions() []rds.SessionInfo
- func (m *RdsProxyServiceImpl) GetMetrics() *rds.ServerMetrics
- func (m *RdsProxyServiceImpl) GetPoolStats() rds.PoolStats
- func (m *RdsProxyServiceImpl) GetTCPServer() *rds.TCPServerInfo
- func (m *RdsProxyServiceImpl) HandleWebSocketProxy(ctx context.Context, conn *proxy.Connection, wsConn proxy.WebSocketConn) error
- func (m *RdsProxyServiceImpl) Init() error
- func (m *RdsProxyServiceImpl) Name() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DBProtocol ¶
type DBProtocol string
DBProtocol 数据库协议类型
const ( ProtocolMySQL DBProtocol = "mysql" ProtocolPostgreSQL DBProtocol = "postgresql" ProtocolUnknown DBProtocol = "unknown" )
type HandshakeInfo ¶
type HandshakeInfo struct {
Protocol DBProtocol // 协议类型
Username string // 用户名
Database string // 数据库名
Options map[string]string // 其他选项
}
HandshakeInfo 握手信息
func DetectProtocolAndParse ¶
func DetectProtocolAndParse(conn net.Conn) (*HandshakeInfo, error)
DetectProtocolAndParse 检测协议类型并解析握手包
type HandshakeParser ¶
type HandshakeParser interface {
// Parse 解析握手包
Parse(conn net.Conn) (*HandshakeInfo, error)
// Protocol 返回协议类型
Protocol() DBProtocol
}
HandshakeParser 握手解析器接口
type MetricsSnapshot ¶
type MetricsSnapshot struct {
TotalConnections int64
ActiveConnections int64
FailedConnections int64
TotalBytesSent int64
TotalBytesReceived int64
TotalQueriesExecuted int64
BlockedQueries int64
Uptime string
}
MetricsSnapshot 指标快照(用于调试和日志)
func GetMetricsSnapshot ¶
func GetMetricsSnapshot(metrics *proxy.TCPServerMetrics, rdsMetrics *RdsMetrics) MetricsSnapshot
GetSnapshot 获取指标快照
type MySQLConnectionPool ¶
type MySQLConnectionPool struct {
// contains filtered or unexported fields
}
MySQLConnectionPool MySQL 连接池
func NewMySQLConnectionPool ¶
func NewMySQLConnectionPool(maxSize int, idleTimeout time.Duration, log *zerolog.Logger) *MySQLConnectionPool
NewMySQLConnectionPool 创建 MySQL 连接池
func (*MySQLConnectionPool) GetConnection ¶
GetConnection 获取连接(复用或新建)
func (*MySQLConnectionPool) GetStats ¶
func (p *MySQLConnectionPool) GetStats() map[string]PoolStats
GetStats 获取连接池统计
func (*MySQLConnectionPool) ReleaseConnection ¶
func (p *MySQLConnectionPool) ReleaseConnection(conn net.Conn)
ReleaseConnection 释放连接(归还到池或关闭)
type MySQLHandshakeParser ¶
type MySQLHandshakeParser struct{}
MySQLHandshakeParser MySQL 握手解析器
func (*MySQLHandshakeParser) Parse ¶
func (p *MySQLHandshakeParser) Parse(conn net.Conn) (*HandshakeInfo, error)
func (*MySQLHandshakeParser) Protocol ¶
func (p *MySQLHandshakeParser) Protocol() DBProtocol
type MySQLInterceptor ¶
type MySQLInterceptor struct {
// contains filtered or unexported fields
}
MySQLInterceptor MySQL 协议拦截器
type PostgreSQLHandshakeParser ¶
type PostgreSQLHandshakeParser struct{}
PostgreSQLHandshakeParser PostgreSQL 握手解析器
func (*PostgreSQLHandshakeParser) Parse ¶
func (p *PostgreSQLHandshakeParser) Parse(conn net.Conn) (*HandshakeInfo, error)
func (*PostgreSQLHandshakeParser) Protocol ¶
func (p *PostgreSQLHandshakeParser) Protocol() DBProtocol
type PrometheusMetrics ¶
type PrometheusMetrics struct {
// contains filtered or unexported fields
}
PrometheusMetrics Prometheus 指标收集器
func NewPrometheusMetrics ¶
func NewPrometheusMetrics(namespace string) *PrometheusMetrics
NewPrometheusMetrics 创建 Prometheus 指标收集器
func (*PrometheusMetrics) Handler ¶
func (m *PrometheusMetrics) Handler() http.Handler
Handler 返回 Prometheus HTTP handler
func (*PrometheusMetrics) RecordQueryDuration ¶
func (m *PrometheusMetrics) RecordQueryDuration(seconds float64)
RecordQueryDuration 记录查询延迟
func (*PrometheusMetrics) UpdateFromServerMetrics ¶
func (m *PrometheusMetrics) UpdateFromServerMetrics(metrics *proxy.TCPServerMetrics)
UpdateFromServerMetrics 从服务器指标同步到 Prometheus
func (*PrometheusMetrics) UpdatePoolStats ¶
func (m *PrometheusMetrics) UpdatePoolStats(stats map[string]PoolStats)
UpdatePoolStats 更新连接池统计
type RdsConnectionHandler ¶
type RdsConnectionHandler struct {
// contains filtered or unexported fields
}
RdsConnectionHandler RDS 连接处理器
func NewRdsConnectionHandler ¶
func NewRdsConnectionHandler( maxConnections int, policySvc policy.Service, backendSvc backend.Service, auditSvc audit.Service, log *zerolog.Logger, ) *RdsConnectionHandler
NewRdsConnectionHandler 创建 RDS 连接处理器
func (*RdsConnectionHandler) GetMetrics ¶
func (h *RdsConnectionHandler) GetMetrics() *RdsMetrics
GetMetrics 获取指标
func (*RdsConnectionHandler) GetPoolStats ¶
func (h *RdsConnectionHandler) GetPoolStats() map[string]interface{}
GetPoolStats 获取连接池统计
func (*RdsConnectionHandler) HandleConnection ¶
HandleConnection 实现 proxy.ConnectionHandler 接口
type RdsMetrics ¶
RdsMetrics RDS 代理指标
type RdsProxyServiceImpl ¶
type RdsProxyServiceImpl struct {
ioc.ObjectImpl
// TCP 代理配置
TCPEnabled bool `json:"tcp_enabled" yaml:"tcp_enabled" toml:"tcp_enabled" env:"TCP_ENABLED"`
TCPListenAddr string `json:"tcp_listen_addr" yaml:"tcp_listen_addr" toml:"tcp_listen_addr" env:"TCP_LISTEN_ADDR"`
TCPMaxConns int `json:"tcp_max_conns" yaml:"tcp_max_conns" toml:"tcp_max_conns" env:"TCP_MAX_CONNS"`
// WebSocket 代理配置(兼容模式)
WebSocketEnabled bool `json:"websocket_enabled" yaml:"websocket_enabled" toml:"websocket_enabled" env:"WEBSOCKET_ENABLED"`
ConnectTimeout int `json:"connect_timeout" yaml:"connect_timeout" toml:"connect_timeout" env:"CONNECT_TIMEOUT"`
IdleTimeout int `json:"idle_timeout" yaml:"idle_timeout" toml:"idle_timeout" env:"IDLE_TIMEOUT"`
// Prometheus 监控
MetricsEnabled bool `json:"metrics_enabled" yaml:"metrics_enabled" toml:"metrics_enabled" env:"METRICS_ENABLED"`
MetricsAddr string `json:"metrics_addr" yaml:"metrics_addr" toml:"metrics_addr" env:"METRICS_ADDR"`
// contains filtered or unexported fields
}
func (*RdsProxyServiceImpl) CloseSession ¶
func (m *RdsProxyServiceImpl) CloseSession(sessionID string) error
CloseSession 关闭指定会话
func (*RdsProxyServiceImpl) GetActiveSessions ¶
func (m *RdsProxyServiceImpl) GetActiveSessions() []rds.SessionInfo
GetActiveSessions 获取活跃会话列表
func (*RdsProxyServiceImpl) GetMetrics ¶
func (m *RdsProxyServiceImpl) GetMetrics() *rds.ServerMetrics
GetMetrics 获取服务器指标
func (*RdsProxyServiceImpl) GetPoolStats ¶
func (m *RdsProxyServiceImpl) GetPoolStats() rds.PoolStats
GetPoolStats 获取连接池统计
func (*RdsProxyServiceImpl) GetTCPServer ¶
func (m *RdsProxyServiceImpl) GetTCPServer() *rds.TCPServerInfo
GetTCPServer 获取 TCP 服务器信息(用于管理)
func (*RdsProxyServiceImpl) HandleWebSocketProxy ¶
func (m *RdsProxyServiceImpl) HandleWebSocketProxy(ctx context.Context, conn *proxy.Connection, wsConn proxy.WebSocketConn) error
HandleWebSocketProxy 处理 WebSocket 代理(兼容模式)
func (*RdsProxyServiceImpl) Init ¶
func (m *RdsProxyServiceImpl) Init() error
func (*RdsProxyServiceImpl) Name ¶
func (m *RdsProxyServiceImpl) Name() string