ipld-eth-server/pkg/prom/prom.go

80 lines
2.0 KiB
Go
Raw Permalink Normal View History

2020-10-27 17:42:38 +00:00
// VulcanizeDB
// Copyright © 2020 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2020-10-19 13:07:29 +00:00
package prom
import (
"github.com/jmoiron/sqlx"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
2020-10-19 13:07:29 +00:00
)
const (
namespace = "ipld_eth_server"
subsystemHTTP = "http"
subsystemWS = "ws"
subsystemIPC = "ipc"
2020-10-19 13:07:29 +00:00
)
var (
metrics bool
httpCount prometheus.Counter
httpDuration prometheus.Histogram
2020-10-19 20:00:09 +00:00
wsCount prometheus.Gauge
ipcCount prometheus.Gauge
2020-10-19 13:07:29 +00:00
)
// Init module initialization
func Init() {
metrics = true
httpCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Subsystem: subsystemHTTP,
Name: "count",
2020-10-19 20:00:09 +00:00
Help: "http request count",
})
httpDuration = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystemHTTP,
Name: "duration",
2020-10-19 20:00:09 +00:00
Help: "http request duration",
})
2020-10-19 20:00:09 +00:00
wsCount = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystemWS,
Name: "count",
Help: "websocket connection count",
})
2020-10-19 20:00:09 +00:00
ipcCount = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Subsystem: subsystemIPC,
Name: "count",
2020-10-19 20:00:09 +00:00
Help: "unix socket connection count",
})
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))
}
}