good morning!!!!

Skip to content
Snippets Groups Projects
Commit 17474c72 authored by Trevor Judice's avatar Trevor Judice
Browse files

changes

parent 6bad2ea5
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ import (
"gfx.cafe/gfx/pggat/lib/gat/admin"
"gfx.cafe/gfx/pggat/lib/gat/database"
"gfx.cafe/gfx/pggat/lib/gat/gatling/server"
"gfx.cafe/gfx/pggat/lib/metrics"
"gfx.cafe/gfx/pggat/lib/gat"
"gfx.cafe/gfx/pggat/lib/gat/gatling/client"
......@@ -161,6 +162,7 @@ func (g *Gatling) ListenAndServe(ctx context.Context) error {
if err != nil {
errch <- err
}
metrics.RecordAcceptConnectionStatus(err)
close(errch)
err = g.handleConnection(ctx, c)
if err != nil {
......@@ -172,6 +174,7 @@ func (g *Gatling) ListenAndServe(ctx context.Context) error {
err = <-errch
if err != nil {
// metrics.Counter("pggat", "accept connection errors")
log.Println("failed to accept connection:", err)
}
}
......@@ -187,11 +190,13 @@ func (g *Gatling) handleConnection(ctx context.Context, c net.Conn) error {
g.mu.Lock()
defer g.mu.Unlock()
g.clients[cl.GetId()] = cl
metrics.RecordActiveConnections(len(g.clients))
}()
defer func() {
g.mu.Lock()
defer g.mu.Unlock()
delete(g.clients, cl.GetId())
metrics.RecordActiveConnections(len(g.clients))
}()
err := cl.Accept(ctx)
......
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type gatMetrics struct {
ConnectionCounter prometheus.Counter
ConnectionErrorCounter *prometheus.CounterVec
ActiveConnections prometheus.Gauge
}
func GatMetrics() *gatMetrics {
s.Lock()
defer s.Unlock()
if s.gat == nil {
s.gat = newGatmetrics()
}
return s.gat
}
func newGatmetrics() *gatMetrics {
o := &gatMetrics{
ConnectionCounter: promauto.NewCounter(prometheus.CounterOpts{
Name: "pggat_connection_count_total",
Help: "total number of connections initiated with pggat",
}),
ConnectionErrorCounter: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pggat_connection_error_count_total",
Help: "total number of connections initiated with pggat",
}, []string{"error"}),
ActiveConnections: promauto.NewGauge(prometheus.GaugeOpts{
Name: "pggat_current_connection_count",
Help: "number of connections to pggat currently",
}),
}
return o
}
func RecordAcceptConnectionStatus(err error) {
if !On() {
return
}
g := GatMetrics()
if err != nil {
g.ConnectionErrorCounter.WithLabelValues(err.Error()).Inc()
}
g.ConnectionCounter.Inc()
}
func RecordActiveConnections(count int) {
if !On() {
return
}
g := GatMetrics()
g.ActiveConnections.Set(float64(count))
}
......@@ -22,6 +22,7 @@ type metrics struct {
counters map[string]prometheus.Counter
histos map[string]prometheus.Histogram
pools map[string]poolMetrics
gat *gatMetrics
sync.RWMutex
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment