message

package
v0.0.0-...-721af93 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ServerStatusInTrans            uint16 = 0x0001
	ServerStatusAutocommit         uint16 = 0x0002
	ServerStatusResultsExists      uint16 = 0x0008
	ServerStatusNoGoodIndexUsed    uint16 = 0x0010
	ServerStatusNoIndexUsed        uint16 = 0x0020
	ServerStatusCursorExists       uint16 = 0x0040
	ServerStatusLastRowSnet        uint16 = 0x0080
	ServerStatusDbDropped          uint16 = 0x0100
	ServerStatusNoBackslashEscapes uint16 = 0x0200
	ServerStatusMetadataChanged    uint16 = 0x0400
	ServerQueryWasSlow             uint16 = 0x0800
	ServerPsOutParams              uint16 = 0x1000
	ServerStatusInTransReadonly    uint16 = 0x2000
	ServerSessionStateChanged      uint16 = 0x4000
)

reponse status

Variables

View Source
var GlobalSQLHashCache = newSQLHashCache()

GlobalSQLHashCache is cache the SQL=>Hash(SQL) pairs

Functions

func EncodeReportToBytes

func EncodeReportToBytes(r *Report) ([]byte, error)

EncodeReportToBytes marshal a Report to bytes

Types

type AssemblySummary

type AssemblySummary struct {
	DB          string              `json:"a"` // DB name
	IP          string              `json:"b"` // server ip
	LastSeen    int64               `json:"c"` // timestamp
	Group       *SummaryGroup       `json:"d"` // summary group by query
	Client      *ClientSummaryGroup `json:"e"` // summary group by client
	UnknownExec int64               `json:"f"` // counter of execute commands without sql
}

AssemblySummary group Summary by db and server ip

func (*AssemblySummary) AddMessage

func (s *AssemblySummary) AddMessage(m *Message, slow bool) bool

AddMessage asseble a Message to this summary

func (*AssemblySummary) HashKey

func (s *AssemblySummary) HashKey() string

HashKey for mapping

type ClientSummaryGroup

type ClientSummaryGroup struct {
	ClientGroup map[string]*SummaryGroup
}

ClientSummaryGroup is a wrapper of map[string]*SummaryGroup

func (*ClientSummaryGroup) AddMessage

func (g *ClientSummaryGroup) AddMessage(m *Message, slow bool) bool

AddMessage asseble a Message to this summary

func (*ClientSummaryGroup) MarshalJSON

func (g *ClientSummaryGroup) MarshalJSON() ([]byte, error)

MarshalJSON interface

func (*ClientSummaryGroup) UnmarshalJSON

func (g *ClientSummaryGroup) UnmarshalJSON(b []byte) error

UnmarshalJSON interface

type ClientSummaryUnit

type ClientSummaryUnit struct {
	IP    string        `json:"a"`
	Group *SummaryGroup `json:"b"`
}

ClientSummaryUnit flattens the ClientSummaryGroup

type Message

type Message struct {
	DB           string            `json:"-"`           // db name
	SQL          string            `json:"-"`           // templated sql
	Raw          string            `json:"c,omitempty"` // raw sql
	Err          bool              `json:"d"`           // sql process error
	ErrMsg       string            `json:"e,omitempty"` // sql process error message
	Errno        uint16            `json:"f,omitempty"` // sql process error number
	ServerStatus uint16            `json:"g"`           // server response status code
	AffectRows   uint64            `json:"h"`           // affect rows
	TimestampReq int64             `json:"i"`           // timestamp for request package
	TimestampRsp int64             `json:"j"`           // timestamp for response package
	Latency      float32           `json:"k"`           // latency in millisecond
	Vars         map[string]string `json:"l,omitempty"` // Vars retrieved form Raw
	ServerIP     string            `json:"-"`           // server ip
	ServerPort   uint16            `json:"-"`           // server port
	ClientIP     string            `json:"n"`           // client ip
	ClientPort   uint16            `json:"-"`           // client port
	AssemblyKey  string            `json:"-"`           // hash key for assembly
	UnknownExec  bool              `json:"-"`           // execute command without crossponding sql
}

Message is the info of a sql query

func (*Message) AssemblyHashKey

func (m *Message) AssemblyHashKey() (hash string, lastreport time.Time, lastsample time.Time)

AssemblyHashKey hash(db+ip+sql) for map, same as AssembleHashKey()

func (*Message) HashKey

func (m *Message) HashKey() (hash string, lastreport time.Time, lastsample time.Time)

HashKey hash(sql) for map

func (*Message) SummaryHashKey

func (m *Message) SummaryHashKey() string

SummaryHashKey is the hash key of the corresponding AssemblySummary

type Report

type Report struct {
	DB map[string]*AssemblySummary
}

Report group captured info by DB

func DecodeReportFromBytes

func DecodeReportFromBytes(data []byte) (*Report, error)

DecodeReportFromBytes unmarshal bytes to a Report

func NewReport

func NewReport() *Report

NewReport create a Report object

func (*Report) AddMessage

func (r *Report) AddMessage(m *Message, slow bool) bool

AddMessage asseble a Message to this Report

func (*Report) MarshalJSON

func (r *Report) MarshalJSON() ([]byte, error)

MarshalJSON interface

func (*Report) Merge

func (r *Report) Merge(ar *Report)

Merge assemble another Report to this one

func (*Report) Reset

func (r *Report) Reset()

Reset collect Messages to reuse

func (*Report) UnmarshalJSON

func (r *Report) UnmarshalJSON(b []byte) error

UnmarshalJSON interface

type SQLHashCache

type SQLHashCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SQLHashCache cache the SQL=>MD5(SQL) pairs

type Summary

type Summary struct {
	Key             string     `json:"a"`           // hash key of SQL
	SQL             string     `json:"b,omitempty"` // SQL template
	SuccessCount    int        `json:"c"`           // success query number
	FailedCount     int        `json:"d"`           // failed query number
	LastSeen        int64      `json:"e"`           // the latest timestamp
	SuccCostTotal   float32    `json:"f"`           // total cost of success query in millisecond
	FailedCostTotal float32    `json:"g"`           // total cost of failed query in millisecond
	NoGoodIndexUsed int64      `json:"h"`           // count of SERVER_STATUS_NO_GOOD_INDEX_USED
	NoIndexUsed     int64      `json:"i"`           // count of SERVER_STATUS_NO_INDEX_USED
	QueryWasSlow    int64      `json:"j"`           // count of SERVER_QUERY_WAS_SLOW
	QPS             *int       `json:"k,omitempty"` // qps
	AverageLatency  *float32   `json:"l,omitempty"` // average latency in millisecond
	MinLatency      *float32   `json:"m,omitempty"` // min latency in millisecond
	MaxLatency      *float32   `json:"n,omitempty"` // max latency in millisecond
	Latency99       *float32   `json:"o,omitempty"` // latency of 99 quantile in milliseconds
	Slow            []*Message `json:"p,omitempty"` // slow queries
	AssemblyKey     string     `json:"-"`           // hash key for assembly
	Sample          *Message   `json:"r,omitempty"` // one normal query sample
}

Summary is a collection of counters and recoreds

func (*Summary) AddMessage

func (s *Summary) AddMessage(m *Message, slow bool, client bool) bool

AddMessage assemble a Message to this summary

type SummaryGroup

type SummaryGroup struct {
	Summary map[string]*Summary
}

SummaryGroup groups summary by sql

func (*SummaryGroup) AddMessage

func (s *SummaryGroup) AddMessage(m *Message, slow bool, client bool) bool

AddMessage asseble a Message to this summary

func (*SummaryGroup) MarshalJSON

func (s *SummaryGroup) MarshalJSON() ([]byte, error)

MarshalJSON interface

func (*SummaryGroup) UnmarshalJSON

func (s *SummaryGroup) UnmarshalJSON(b []byte) error

UnmarshalJSON interface

Jump to

Keyboard shortcuts

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