https://github.com/exhuma/gopgstats
https://github.com/exhuma/gopgstats
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/exhuma/gopgstats
- Owner: exhuma
- License: mit
- Created: 2018-10-16T10:24:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-20T16:34:25.000Z (over 7 years ago)
- Last Synced: 2025-01-30T12:32:51.816Z (over 1 year ago)
- Language: Go
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
PostgreSQL statistics for Go
============================
This package contains helper functions to retrieve runtime statistcs of a
PostgreSQL DB server. The aim is to decouple the DB queries from Go
applications.
Statistics will always return as a list of structs where each statistic has its
own struct. The decision to do this instead of returning a list of
``interface{}`` items was that this keeps type-safety and removes guesswork.
As of 2018-10-17, this package contains a couple of statistics. More will come
soon.
DSN & URLs
----------
Please take note that URLs are **not** yet supported as database DSNs. Certain
statistics are only available on the databse of the currently active
connection. This means that in order to fetch statistics from all databases, a
new connection must be established per DB. ``gopgstats`` will reuse the DSN
which was used to create the ``Fetcher`` object and modify it as needed. This
modification is currently only coded for normal connection strings. Not for
URLs!
Usage
-----
::
import (
"database/sql"
"github.com/exhuma/gopgstats"
_ "github.com/lib/pq"
)
// Use a normal PostgreSQL DSN syntax here. Note that URLs are currently
// NOT supported!
dsn := "host=dbhost username=jdoe password=s3cr37"
db, err := sql.Open("postgres", dsn)
if err != nil {
panic(err)
}
fmt.Println("--- Locks")
fetcher := gopgstats.MakeDefaultFetcher(db)
result, err := fetcher.Locks()
fmt.Println(err)
fmt.Println(result)
fmt.Println("--- Disk IO")
diskio, err := fetcher.DiskIOAll(dsn)
fmt.Println(err)
fmt.Println(diskio)