Documentation ¶
Index ¶
- Constants
- Variables
- func Close() error
- func Execute(command string, args ...interface{}) (middleware.Result, error)
- func ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
- func InitGlobalPool(addr string, rt http.RoundTripper, ...) error
- func InitGlobalPoolWithConfig(config Config, ...) error
- func InitGlobalPoolWithDefault(addr string) error
- func InitGlobalPoolWithPoolConfig(config PoolConfig) error
- func IsClosed() bool
- func Release(num int) error
- func ReplaceGlobalPool(pool *Pool) error
- func Supply(num int) error
- type Config
- type Conn
- type Pool
- type PoolConfig
- type PoolConn
- func (pc *PoolConn) Close() error
- func (pc *PoolConn) Disconnect() error
- func (pc *PoolConn) Execute(command string, args ...interface{}) (middleware.Result, error)
- func (pc *PoolConn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
- func (pc *PoolConn) IsValid() bool
- func (pc *PoolConn) Prepare(command string) (middleware.Statement, error)
- func (pc *PoolConn) PrepareContext(ctx context.Context, command string) (middleware.Statement, error)
- type RawData
- func (rd *RawData) GetMatrix() (model.Matrix, error)
- func (rd *RawData) GetScalar() (*model.Scalar, error)
- func (rd *RawData) GetString() (*model.String, error)
- func (rd *RawData) GetValue() model.Value
- func (rd *RawData) GetVector() (model.Vector, error)
- func (rd *RawData) GetWarnings() apiv1.Warnings
- type Result
- type TimeRange
Constants ¶
const ( DefaultStep = time.Minute DefaultDialTimeout = 30 * time.Second DefaultKeepAlive = 30 * time.Second DefaultTLSHandshakeTimeout = 10 * time.Second )
const ( DefaultMaxConnections = 20 DefaultInitConnections = 5 DefaultMaxIdleConnections = 10 DefaultMaxIdleTime = 1800 // seconds DefaultMaxWaitTime = 1 // seconds DefaultMaxRetryCount = -1 DefaultKeepAliveInterval = 300 // seconds DefaultKeepAliveChunkSize = 5 DefaultSleepTime = 1 // seconds DefaultUnlimitedWaitTime = -1 // seconds DefaultUnlimitedRetryCount = -1 DefaultDelayTime = 5 // milliseconds )
Variables ¶
var ( DefaultDialer = &net.Dialer{ Timeout: DefaultDialTimeout, KeepAlive: DefaultKeepAlive, } // DefaultRoundTripper is used if no RoundTripper is set in Config, DefaultRoundTripper http.RoundTripper = &http.Transport{ Proxy: http.ProxyFromEnvironment, DialContext: DefaultDialer.DialContext, TLSHandshakeTimeout: DefaultTLSHandshakeTimeout, } )
Functions ¶
func Execute ¶
func Execute(command string, args ...interface{}) (middleware.Result, error)
Execute execute given sql statement
func ExecuteContext ¶
func ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
ExecuteContext executes given command with context
func InitGlobalPool ¶
func InitGlobalPool(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime, maxWaitTime, maxRetryCount, keepAliveInterval int) error
InitGlobalPool returns a new *Pool and replaces it as global pool
func InitGlobalPoolWithConfig ¶
func InitGlobalPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, maxWaitTime, maxRetryCount, keepAliveInterval int) error
InitGlobalPoolWithConfig returns a new *Pool with a Config object and replaces it as global pool
func InitGlobalPoolWithDefault ¶
InitGlobalPoolWithDefault returns a new *Pool with default configuration and replaces it as global pool
func InitGlobalPoolWithPoolConfig ¶
func InitGlobalPoolWithPoolConfig(config PoolConfig) error
InitGlobalPoolWithPoolConfig returns a new *Pool with a PoolConfig object and replaces it as global pool
func Release ¶
Release releases given number of connections of global pool, each connection will disconnect with database
func ReplaceGlobalPool ¶
ReplaceGlobalPool replaces given pool as global pool
Types ¶
type Config ¶
func NewConfig ¶
func NewConfig(addr string, rt http.RoundTripper) Config
NewConfig returns a new client.Config with given address and round tripper
func NewConfigWithBasicAuth ¶
NewConfigWithBasicAuth returns a new client.Config with given address, user and password
func NewConfigWithDefaultRoundTripper ¶
NewConfigWithDefaultRoundTripper returns a new client.Config with given address and default round tripper
type Conn ¶
func NewConn ¶
func NewConn(addr string, rt http.RoundTripper) (*Conn, error)
NewConn returns a new *Conn with given address and round tripper
func NewConnWithConfig ¶
NewConnWithConfig returns a new *Conn with given config
func (*Conn) CheckInstanceStatus ¶
CheckInstanceStatus checks prometheus instance status
type Pool ¶
type Pool struct { sync.Mutex PoolConfig // contains filtered or unexported fields }
func NewPool ¶
func NewPool(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime, maxWaitTime, maxRetryCount, keepAliveInterval int) (*Pool, error)
NewPool returns a new *Pool
func NewPoolWithConfig ¶
func NewPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, maxWaitTime, maxRetryCount, keepAliveInterval int) (*Pool, error)
NewPoolWithConfig returns a new *Pool with a Config object
func NewPoolWithDefault ¶
NewPoolWithDefault returns a new *Pool with default configuration
func NewPoolWithPoolConfig ¶
func NewPoolWithPoolConfig(config PoolConfig) (*Pool, error)
NewPoolWithPoolConfig returns a new *Pool with a PoolConfig object
func (*Pool) Get ¶
func (p *Pool) Get() (middleware.PoolConn, error)
Get is an exported alias of get() function with routine safe
func (*Pool) Transaction ¶
func (p *Pool) Transaction() (middleware.Transaction, error)
Transaction is used to implement the interface, but it is not supported in prometheus, never call this function
func (*Pool) UsedConnections ¶
UsedConnections returns used connection number
type PoolConfig ¶
type PoolConfig struct { Config MaxConnections int InitConnections int MaxIdleConnections int MaxIdleTime int MaxWaitTime int MaxRetryCount int KeepAliveInterval int }
func NewPoolConfig ¶
func NewPoolConfig(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime, maxWaitTime, maxRetryCount, keepAliveInterval int) PoolConfig
NewPoolConfig returns a new PoolConfig
func NewPoolConfigWithConfig ¶
func NewPoolConfigWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, maxWaitTime, maxRetryCount, keepAliveInterval int) PoolConfig
NewPoolConfigWithConfig returns a new PoolConfig
func (*PoolConfig) Validate ¶
func (cfg *PoolConfig) Validate() error
Validate validates pool config
type PoolConn ¶
func Get ¶
Get get gets a connection from pool and validate it, if there is no valid connection in the pool, it will create a new connection
func NewPoolConn ¶
func NewPoolConn(addr string, rt http.RoundTripper) (*PoolConn, error)
NewPoolConn returns a new *PoolConn
func NewPoolConnWithPool ¶
NewPoolConnWithPool returns a new *PoolConn
func (*PoolConn) Disconnect ¶
Disconnect disconnects from mysql, normally when using connection pool, there is no need to disconnect manually, consider to use Close() instead.
func (*PoolConn) Execute ¶
func (pc *PoolConn) Execute(command string, args ...interface{}) (middleware.Result, error)
Execute executes given sql and placeholders on the mysql server
func (*PoolConn) ExecuteContext ¶
func (pc *PoolConn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)
ExecuteContext executes given sql and placeholders on the mysql server
func (*PoolConn) Prepare ¶
func (pc *PoolConn) Prepare(command string) (middleware.Statement, error)
Prepare prepares a statement and returns a *Statement
func (*PoolConn) PrepareContext ¶
func (pc *PoolConn) PrepareContext(ctx context.Context, command string) (middleware.Statement, error)
PrepareContext prepares a statement with context and returns a *Statement
type RawData ¶
func NewRawData ¶
NewRawData returns a new RawData
func (*RawData) GetWarnings ¶
GetWarnings returns warnings
type Result ¶
func NewResult ¶
NewResult returns a new *Result with given value and warnings note that if return value is matrix type, only the first matrix will be processed, all others will be discarded, if a query returns more than one matrix, use GetRaw() function to get the raw data which is returned by prometheus go client package
type TimeRange ¶ added in v0.3.1
func NewTimeRange ¶ added in v0.3.1
NewTimeRange returns a new TimeRange
func NewTimeRangeWithRange ¶ added in v0.3.2
NewTimeRangeWithRange returns a new TimeRange with given apiv1.Range