Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sonots/go-sql_metrics
Instrument database/sql queries
https://github.com/sonots/go-sql_metrics
Last synced: 3 months ago
JSON representation
Instrument database/sql queries
- Host: GitHub
- URL: https://github.com/sonots/go-sql_metrics
- Owner: sonots
- License: mit
- Created: 2014-09-13T09:20:51.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-24T15:33:40.000Z (over 8 years ago)
- Last Synced: 2024-04-15T12:17:31.841Z (9 months ago)
- Language: Go
- Homepage:
- Size: 288 KB
- Stars: 6
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-sql\_metrics
Instrument database/sql queries
# Usage
```go
import (
"database/sql"
"github.com/sonots/go-sql_metrics"
)func main() {
// db, err := sql.Open("sqlite3", "foo.db")
_db, err := sql.Open("sqlite3", "foo.db")
db := sql_metrics.WrapDB("foo", _db)// Use as usual
result, err := db.Exec("INSERT INTO memos (id, body) VALUES (?)", id, body)
rows, err := db.Query("SELECT body FROM memos WHERE id = ?", id)
err := db.QueryRow("SELECT body FROM memos WHERE id = ?", id).Scan(&body)sql_metrics.Verbose = true // print metrics on each query
sql_metrics.Print(1) // print metrics on each 1 second
// sql_metrics.Enable = false // turn off the instrumentation
}
```Output Example (LTSV format):
```
time:2014-09-13 17:35:49.764851359 +0900 JST db:foo query:SELECT body FROM memos WHERE id = ? count:4 max:0.001562 mean:0.000817 min:0.000033 percentile95:0.001562 duration:1
```Verbose Output Example (LTSV format):
```
time:2014-09-13 17:35:49.717393256 +0900 JST db:foo query:SELECT body FROM memos WHERE id = ? elapsed:0.000910
```# API
Print summarized metrics on each specified second:
```
sql_metrics.Print(60)
```## Verbose
Print metrics on each query:
```
sql_metrics.Verbose = true
```## Enable
Diable instrumentation as:
```
sql_metrics.Enable = false
```## Flush()
Flush metrics on arbitrary timing by calling `Flush()` as:
```
sql_metrics.Flush()
```# ToDo
* Write tests
# Contribution
* Fork (https://github.com/sonots/go-sql_metrics/fork)
* Create a feature branch
* Commit your changes
* Rebase your local changes against the master branch
* Create new Pull Request# Copyright
* See [LICENSE](./LICENSE)