sqlactivity

package
v0.1.76 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sqlactivity samples the sessions and requests a Postgres or SQL Server is running, top style: every read returns one row per active request.

Index

Constants

View Source
const (
	EnginePostgres  = "postgres"
	EngineSQLServer = "sqlserver"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Idle      bool
	SessionID int64
}

Filter narrows a read. Idle reads sessions that run nothing too; SessionID, when not zero, reads only that session (SQL Server SPID, Postgres backend pid).

type Sample

type Sample struct {
	SampledAt            time.Time `json:"sampledAt" pretty:"label=Sampled" filter:"time" sort:"sampledAt"`
	Engine               string    `json:"engine" filter:"terms" sort:"engine"`
	Database             string    `json:"database" filter:"terms" sort:"database"`
	SessionID            int64     `json:"sessionId" pretty:"label=Session" filter:"exact" sort:"sessionId"`
	RequestID            int64     `json:"requestId" pretty:"label=Request" filter:"exact" sort:"requestId"`
	BlockedBy            int64     `json:"blockedBy" pretty:"label=Blocked by" filter:"exact" sort:"blockedBy"`
	Blocked              bool      `json:"blocked" filter:"boolean" sort:"blocked"`
	User                 string    `json:"user" filter:"terms" sort:"user"`
	Application          string    `json:"application" filter:"terms" sort:"application"`
	ClientHost           string    `json:"clientHost" pretty:"label=Client host" filter:"terms" sort:"clientHost"`
	State                string    `json:"state" filter:"terms" sort:"state"`
	Command              string    `json:"command" filter:"terms" sort:"command"`
	WaitType             string    `json:"waitType" pretty:"label=Wait" filter:"terms" sort:"waitType"`
	WaitResource         string    `json:"waitResource" pretty:"label=Wait resource" filter:"exact" sort:"waitResource"`
	WaitMs               *float64  `json:"waitMs" pretty:"label=Waited,type=duration,unit=ms" filter:"duration" sort:"waitMs"`
	StartedAt            time.Time `json:"startedAt" pretty:"label=Started" filter:"time" sort:"startedAt"`
	TransactionStartedAt time.Time `json:"transactionStartedAt" pretty:"label=Transaction started" filter:"time" sort:"transactionStartedAt"`
	ElapsedMs            float64   `json:"elapsedMs" pretty:"label=Elapsed,type=duration,unit=ms" filter:"duration" sort:"elapsedMs"`
	TransactionMs        float64   `json:"transactionMs" pretty:"label=Transaction,type=duration,unit=ms" filter:"duration" sort:"transactionMs"`
	CPUMs                *float64  `json:"cpuMs" pretty:"label=CPU,type=duration,unit=ms" filter:"duration" sort:"cpuMs"`
	LogicalReads         *int64    `json:"logicalReads" filter:"range" sort:"logicalReads"`
	Reads                *int64    `json:"reads" filter:"range" sort:"reads"`
	Writes               *int64    `json:"writes" filter:"range" sort:"writes"`
	MemoryBytes          *int64    `json:"memoryBytes" pretty:"label=Memory,type=bytes" filter:"range" sort:"memoryBytes"`
	OpenTransactions     int64     `json:"openTransactions" filter:"range" sort:"openTransactions"`
	QueryID              string    `json:"queryId" pretty:"label=Query id" filter:"exact" sort:"queryId"`
	SQL                  string    `json:"sql" pretty:"label=SQL" filter:"text" sort:"sql"`
}

Sample is one session's request as a read saw it. Every column filters and sorts. Nullable request measurements distinguish unavailable values from zero.

func (Sample) Columns

func (Sample) Columns() []api.ColumnDef

func (*Sample) Derive

func (s *Sample) Derive(at time.Time)

Derive fills what follows from the server time and the row's own times: elapsed (when the engine does not report it), transaction age and blocked.

func (Sample) Pretty

func (s Sample) Pretty() api.Text

func (Sample) PrettyFull

func (s Sample) PrettyFull() api.Textable

func (Sample) Row

func (s Sample) Row() map[string]any

func (Sample) RowDetail

func (s Sample) RowDetail() api.Textable

type Snapshot

type Snapshot struct {
	ServerTime time.Time
	Rows       []Sample
}

Snapshot is one read of an engine: the server's time and its requests.

func Read

func Read(ctx context.Context, db *sql.DB, engine string, filter Filter) (Snapshot, error)

Read reads engine's sessions through db, which must not be the connection a sampled session runs on: the reader excludes its own session. Every row is stamped with the engine and derived from the server's time.

Jump to

Keyboard shortcuts

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