mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Add prometheus - WIP
This commit is contained in:
parent
137f77eef6
commit
92e81ade15
3 changed files with 50 additions and 8 deletions
15
mysql.go
15
mysql.go
|
|
@ -152,6 +152,7 @@ func (dbw *DBWrapper) SqlQuery(query string, args ...interface{}) (*sql.Rows, er
|
|||
}
|
||||
|
||||
res, err := dbw.Db.Query(query, args...)
|
||||
DbOperationsQuery.Inc()
|
||||
|
||||
if err != nil {
|
||||
if !dbw.checkConnection(false) {
|
||||
|
|
@ -187,7 +188,7 @@ func (dbw *DBWrapper) SqlBegin(concurrencySafety bool, quiet bool) (DbTransactio
|
|||
tx, err = dbw.Db.BeginTx(context.Background(), &sql.TxOptions{Isolation: isoLvl})
|
||||
benchmarc.Stop()
|
||||
|
||||
//DbIoSeconds.WithLabelValues("mysql", "begin").Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("mysql", "begin").Observe(benchmarc.Seconds())
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"context": "sql",
|
||||
|
|
@ -221,7 +222,7 @@ func (dbw *DBWrapper) SqlCommit(tx DbTransaction, quiet bool) error {
|
|||
err = tx.Commit()
|
||||
benchmarc.Stop()
|
||||
|
||||
//DbIoSeconds.WithLabelValues("mysql", "commit").Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("mysql", "commit").Observe(benchmarc.Seconds())
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"context": "sql",
|
||||
|
|
@ -253,7 +254,7 @@ func (dbw *DBWrapper) SqlRollback(tx DbTransaction, quiet bool) error {
|
|||
err = tx.Rollback()
|
||||
benchmarc.Stop()
|
||||
|
||||
//DbIoSeconds.WithLabelValues("mysql", "rollback").Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("mysql", "rollback").Observe(benchmarc.Seconds())
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"context": "sql",
|
||||
|
|
@ -322,12 +323,13 @@ func (dbw *DBWrapper) sqlExecInternal(db DbClientOrTransaction, opDescription st
|
|||
benchmarc = icingadb_utils.NewBenchmark()
|
||||
}
|
||||
res, err := db.Exec(sql, args...)
|
||||
DbOperationsExec.Inc()
|
||||
if !quiet {
|
||||
benchmarc.Stop()
|
||||
}
|
||||
|
||||
if !quiet {
|
||||
//DbIoSeconds.WithLabelValues("mysql", opDescription).Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("mysql", opDescription).Observe(benchmarc.Seconds())
|
||||
log.WithFields(log.Fields{
|
||||
"context": "sql",
|
||||
"benchmark": benchmarc,
|
||||
|
|
@ -376,6 +378,7 @@ func sqlTryFetchAll(db DbClientOrTransaction, queryDescription string, query str
|
|||
benchmarc = icingadb_utils.NewBenchmark()
|
||||
}
|
||||
rows, errQuery := db.Query(query, args...)
|
||||
DbOperationsQuery.Inc()
|
||||
if !quiet {
|
||||
benchmarc.Stop()
|
||||
}
|
||||
|
|
@ -384,7 +387,7 @@ func sqlTryFetchAll(db DbClientOrTransaction, queryDescription string, query str
|
|||
|
||||
defer func() {
|
||||
if !quiet {
|
||||
//DbIoSeconds.WithLabelValues("mysql", queryDescription).Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("mysql", queryDescription).Observe(benchmarc.Seconds())
|
||||
log.WithFields(log.Fields{
|
||||
"context": "sql",
|
||||
"benchmark": benchmarc,
|
||||
|
|
@ -472,7 +475,7 @@ func (dbw DBWrapper) SqlTransaction(concurrencySafety bool, retryOnConnectionFai
|
|||
benchmarc.Stop()
|
||||
}
|
||||
|
||||
//DbIoSeconds.WithLabelValues("mysql", "transaction").Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("mysql", "transaction").Observe(benchmarc.Seconds())
|
||||
|
||||
if !quiet {
|
||||
log.WithFields(log.Fields{
|
||||
|
|
|
|||
39
prometheus.go
Normal file
39
prometheus.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package icingadb_connection
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var DbIoSeconds = promauto.NewSummaryVec(
|
||||
prometheus.SummaryOpts{
|
||||
Name: "db_io_seconds",
|
||||
Help: "Database I/O (s)",
|
||||
},
|
||||
[]string{"backend_type", "operation"},
|
||||
)
|
||||
|
||||
var DbOperationsTotal = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "db_operations_total",
|
||||
Help: "Database operations since startup",
|
||||
})
|
||||
|
||||
var DbOperationsQuery = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "db_operations_query",
|
||||
Help: "Database query operations since startup",
|
||||
})
|
||||
|
||||
var DbOperationsExec = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "db_operations_exec",
|
||||
Help: "Database exec operations since startup",
|
||||
})
|
||||
|
||||
//TODO: Move this to main package of IcingaDB
|
||||
func Httpd(addr string, chErr chan error) {
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
log.Infof("Serving debug info at http://%s/metrics", addr)
|
||||
chErr <- http.ListenAndServe(addr, nil)
|
||||
}
|
||||
4
redis.go
4
redis.go
|
|
@ -230,7 +230,7 @@ func (rdbw *RDBWrapper) HGetAll(key string) (map[string]string, error) {
|
|||
|
||||
benchmarc.Stop()
|
||||
|
||||
//DbIoSeconds.WithLabelValues("redis", "hgetall").Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("redis", "hgetall").Observe(benchmarc.Seconds())
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"context": "redis",
|
||||
|
|
@ -261,7 +261,7 @@ func (rdbw *RDBWrapper) TxPipelined(fn func(pipeliner redis.Pipeliner) error) ([
|
|||
|
||||
benchmarc.Stop()
|
||||
|
||||
//DbIoSeconds.WithLabelValues("redis", "multi").Observe(benchmarc.Seconds())
|
||||
DbIoSeconds.WithLabelValues("redis", "multi").Observe(benchmarc.Seconds())
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"context": "redis",
|
||||
|
|
|
|||
Loading…
Reference in a new issue