slowql

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: MIT Imports: 9 Imported by: 0

README

slowql

Go Reference Go Report Card

A slow query logs parser in Golang.

Getting started

go get github.com/devops-works/slowql

Basic usage

In a nutshell, you can use it as follows:

package main

import (
    "fmt"

    "github.com/devops-works/slowql"
)

func main() {
    // Imagine that fd is an io.Reader of your slow query logs file...

    // Create the parser
    p := slowql.NewParser(slowql.MySQL, fd)

    // Get the next query from the log
    q, err := p.GetNext()
	  if err != nil {
		    panic(err)
	  }

    // Do your stuff, for example:
    fmt.Printf("at %d, %s did the request: %s\n", q.Time, q.User, q.Query)

    fp, err := q.Fingerprint()
    if err != nil {
        panic(err)
    }
    fmt.Printf("the query fingerprint is: %s\n", fp)

    srv := p.GetServerMeta()
    fmt.Printf("the SQL server listens to port %d", srv.Port)
}

Performance

Running the example given in cmd/ without any fmt.Printf against a 292MB slow query logs from a MySQL database provides the following output:

parsed 278077 queries in 8.099622786s

which is approx. 34760 queries/second (Intel i5-8250U (8) @ 3.400GHz).

Associated tools

With this package we created some tools:

  • slowql-replayer: replay and benchmark queries from a slow query log
  • slowql-digest: digest and analyze slow query logs. Similar to pt-query-digest, but faster. 🙃

Notes

Tested databases

Not all kind of slow query logs have been tested yet:

  • MySQL
  • MariaDB
  • Percona-db
  • Percona-cluster (pxc)

Contributing

Issues and pull requests are welcomed ! If you found a bug or want to help and improve this package don't hesitate to fork it or open an issue 😄

License

MIT

Documentation

Overview

Package slowql provides everything needed to parse slow query logs from different databases (such as MySQL, MariaDB). Along to a parser, it proposes a simple API with few functions that allow you to get everything needed to compute your slow queries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	// // GetNext returns the next query of the parser
	// GetNext() Query
	// // GetServerMeta returns informations about the SQL server in usage
	// GetServerMeta() Server
	ParseBlocks(rawBlocks chan []string)
	ParseServerMeta(chan []string)
	GetServerMeta() server.Server
}

Database is the parser interface

type Kind

type Kind int

Kind is a database kind

const (
	// Unknown type
	Unknown Kind = iota
	// MySQL type
	MySQL
	// MariaDB type
	MariaDB
	// PXC type
	PXC
)

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser holds a slowql parser

func NewParser

func NewParser(k Kind, r io.Reader) Parser

NewParser returns a new parser depending on the desired kind

func (*Parser) GetNext

func (p *Parser) GetNext() query.Query

GetNext returns the next query in line

func (*Parser) GetServerMeta

func (p *Parser) GetServerMeta() server.Server

GetServerMeta returns server meta information

Directories

Path Synopsis
cmd
database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳