Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CHQueryRecord ¶ added in v0.19.927
type CHQueryRecord struct {
Table string `gorm:"column:table"`
Operation string `gorm:"column:operation"`
SQL string `gorm:"column:sql"`
DurationMS float64 `gorm:"column:duration_ms"`
RowsAffected int64 `gorm:"column:rows_affected"`
ResponseSize int `gorm:"column:response_size"`
PreloadCount int `gorm:"column:preload_count"`
Timestamp time.Time `gorm:"column:timestamp"`
Error string `gorm:"column:error"`
Caller string `gorm:"column:caller"`
CallerURL string `gorm:"column:caller_url"`
DBType string `gorm:"column:db_type"`
Source string `gorm:"column:source"`
Endpoint string `gorm:"column:endpoint"`
ProcessID string `gorm:"column:process_id"`
}
CHQueryRecord is the GORM model for the ClickHouse `queries` table.
func (CHQueryRecord) TableName ¶ added in v0.19.927
func (CHQueryRecord) TableName() string
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector accumulates query records in a fixed-size ring buffer.
func NewCollector ¶
NewCollector creates a new collector with the given max buffer size.
func (*Collector) Add ¶
func (c *Collector) Add(r QueryRecord)
Add inserts a record into the ring buffer and forwards to the writer if set.
func (*Collector) Records ¶
func (c *Collector) Records() []QueryRecord
Records returns a snapshot of all collected records (newest first).
func (*Collector) SetWriter ¶ added in v0.19.927
SetWriter attaches a Writer that persists records to ClickHouse.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin is a GORM plugin that records every query into a Collector.
type QueryRecord ¶
type QueryRecord struct {
Table string `json:"table"`
Operation string `json:"operation"`
SQL string `json:"sql"`
Duration time.Duration `json:"duration_ns"`
DurationMS float64 `json:"duration_ms"`
RowsAffected int64 `json:"rows_affected"`
ResponseSize int `json:"response_size"`
PreloadCount int `json:"preload_count"`
Timestamp time.Time `json:"timestamp"`
Error string `json:"error,omitempty"`
Caller string `json:"caller"`
CallerURL string `json:"caller_url,omitempty"`
DBType string `json:"db_type"`
Source string `json:"source"`
Endpoint string `json:"endpoint"`
}
QueryRecord holds the captured data for a single query execution.
type Writer ¶ added in v0.19.927
type Writer struct {
// contains filtered or unexported fields
}
Writer buffers QueryRecords and flushes them to ClickHouse in batches.
func NewWriter ¶ added in v0.19.927
func NewWriter(cfg WriterConfig) *Writer
NewWriter creates a Writer. Call Start() to begin the background flush loop.
func (*Writer) Start ¶ added in v0.19.927
func (w *Writer) Start()
Start begins the background flush goroutine. Call Stop() to shut down.
func (*Writer) Stop ¶ added in v0.19.927
func (w *Writer) Stop()
Stop signals the flush goroutine to drain and exit, then blocks until done.
func (*Writer) Write ¶ added in v0.19.927
func (w *Writer) Write(r QueryRecord)
Write enqueues a record for persistence. Non-blocking; drops if the channel is full.