7999d24f81
this commit updates our monkit dependency to the v3 version where it outputs in an influx style. this makes discovery much easier as many tools are built to look at it this way. graphite and rothko will suffer some due to no longer being a tree based on dots. hopefully time will exist to update rothko to index based on the new metric format. it adds an influx output for the statreceiver so that we can write to influxdb v1 or v2 directly. Change-Id: Iae9f9494a6d29cfbd1f932a5e71a891b490415ff
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package dbutil
|
|
|
|
import (
|
|
"database/sql"
|
|
"flag"
|
|
"time"
|
|
|
|
"github.com/spacemonkeygo/monkit/v3"
|
|
)
|
|
|
|
var (
|
|
maxIdleConns = flag.Int("db.max_idle_conns", 20, "Maximum Amount of Idle Database connections, -1 means the stdlib default")
|
|
maxOpenConns = flag.Int("db.max_open_conns", 25, "Maximum Amount of Open Database connections, -1 means the stdlib default")
|
|
connMaxLifetime = flag.Duration("db.conn_max_lifetime", -1, "Maximum Database Connection Lifetime, -1ns means the stdlib default")
|
|
)
|
|
|
|
// ConfigurableDB contains methods for configuring a database.
|
|
type ConfigurableDB interface {
|
|
SetMaxIdleConns(int)
|
|
SetMaxOpenConns(int)
|
|
SetConnMaxLifetime(time.Duration)
|
|
Stats() sql.DBStats
|
|
}
|
|
|
|
// Configure Sets Connection Boundaries and adds db_stats monitoring to monkit
|
|
func Configure(db ConfigurableDB, mon *monkit.Scope) {
|
|
if *maxIdleConns >= 0 {
|
|
db.SetMaxIdleConns(*maxIdleConns)
|
|
}
|
|
if *maxOpenConns >= 0 {
|
|
db.SetMaxOpenConns(*maxOpenConns)
|
|
}
|
|
if *connMaxLifetime >= 0 {
|
|
db.SetConnMaxLifetime(*connMaxLifetime)
|
|
}
|
|
mon.Chain(monkit.StatSourceFunc(
|
|
func(cb func(key monkit.SeriesKey, field string, val float64)) {
|
|
monkit.StatSourceFromStruct(monkit.NewSeriesKey("db_stats"), db.Stats()).Stats(cb)
|
|
}))
|
|
}
|