2020-10-19 13:07:29 +00:00
|
|
|
package prom
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2020-10-19 15:00:55 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
2020-10-19 13:07:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-10-19 15:00:55 +00:00
|
|
|
namespace = "ipld_eth_server"
|
|
|
|
|
|
|
|
subsystemHTTP = "http"
|
|
|
|
subsystemWS = "ws"
|
|
|
|
subsystemIPC = "ipc"
|
2020-10-19 13:07:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
metrics bool
|
2020-10-19 15:00:55 +00:00
|
|
|
|
|
|
|
httpCount prometheus.Counter
|
|
|
|
httpDuration prometheus.Histogram
|
|
|
|
|
|
|
|
wsCount prometheus.Counter
|
|
|
|
wsDuration prometheus.Histogram
|
|
|
|
|
|
|
|
ipcCount prometheus.Counter
|
|
|
|
ipcDuration prometheus.Gauge
|
2020-10-19 13:07:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Init module initialization
|
|
|
|
func Init() {
|
|
|
|
metrics = true
|
2020-10-19 15:00:55 +00:00
|
|
|
|
|
|
|
httpCount = promauto.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystemHTTP,
|
|
|
|
Name: "count",
|
|
|
|
Help: "",
|
|
|
|
})
|
|
|
|
httpDuration = promauto.NewHistogram(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystemHTTP,
|
|
|
|
Name: "duration",
|
|
|
|
Help: "",
|
|
|
|
})
|
|
|
|
|
|
|
|
wsCount = promauto.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystemWS,
|
|
|
|
Name: "count",
|
|
|
|
Help: "",
|
|
|
|
})
|
|
|
|
wsDuration = promauto.NewHistogram(prometheus.HistogramOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystemWS,
|
|
|
|
Name: "duration",
|
|
|
|
Help: "",
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcCount = promauto.NewCounter(prometheus.CounterOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystemIPC,
|
|
|
|
Name: "count",
|
|
|
|
Help: "",
|
|
|
|
})
|
|
|
|
ipcDuration = promauto.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: subsystemIPC,
|
|
|
|
Name: "duration",
|
|
|
|
Help: "",
|
|
|
|
})
|
2020-10-19 13:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterDBCollector create metric colletor for given connection
|
|
|
|
func RegisterDBCollector(name string, db *sqlx.DB) {
|
|
|
|
if metrics {
|
|
|
|
prometheus.Register(NewDBStatsCollector(name, db))
|
|
|
|
}
|
|
|
|
}
|