slowquery

package
v0.2.0-beta.13 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package slowquery parses already-stored container log lines (see internal/api/database_slow_queries.go) into structured slow-query entries for Postgres and MySQL. Redis has no log-based slow query record (SLOWLOG is a live-server command, not log output) and is deliberately not handled here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Timestamp time.Time
	// DurationMs is the statement's own reported execution time in
	// milliseconds (Postgres' "duration:", MySQL's "Query_time"
	// converted from seconds).
	DurationMs float64
	Query      string
	// RowsExamined is 0 when the engine's slow query log doesn't report
	// it (Postgres never does; MySQL always does for a real slow-log
	// entry).
	RowsExamined int64
}

Entry is one parsed slow query.

func ParseMySQL

func ParseMySQL(lines []LogLine) []Entry

ParseMySQL extracts every slow-query entry from lines, in the order given, reconstructing each entry's multi-line block: a "# Query_time:" header, an optional "# User@Host:"/"SET timestamp=...;" line, then one or more lines of SQL text terminated by the next header line (another "#"-prefixed line) or the end of input. Everything before the first header line, and any "#"-prefixed line that isn't a header this package recognizes (e.g. "# Time:", "# User@Host:"), is skipped.

func ParsePostgres

func ParsePostgres(lines []LogLine) []Entry

ParsePostgres extracts every slow-statement entry from lines, in the order given. Non-matching lines (ordinary Postgres log output that isn't a duration line) are skipped, not treated as an error: the raw log stream mixes slow-query lines with every other message Postgres writes to stderr.

type LogLine

type LogLine struct {
	Timestamp time.Time
	Message   string
}

LogLine is one stored container log line: its own capture timestamp (not the engine's in-message timestamp text) and raw message.

Jump to

Keyboard shortcuts

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