good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pggat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gfx
pggat
Commits
17474c72
Commit
17474c72
authored
2 years ago
by
Trevor Judice
Browse files
Options
Downloads
Patches
Plain Diff
changes
parent
6bad2ea5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/gat/gatling/gatling.go
+5
-0
5 additions, 0 deletions
lib/gat/gatling/gatling.go
lib/metrics/gat.go
+58
-0
58 additions, 0 deletions
lib/metrics/gat.go
lib/metrics/metrics.go
+1
-0
1 addition, 0 deletions
lib/metrics/metrics.go
with
64 additions
and
0 deletions
lib/gat/gatling/gatling.go
+
5
−
0
View file @
17474c72
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
lib/metrics/gat.go
0 → 100644
+
58
−
0
View file @
17474c72
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
))
}
This diff is collapsed.
Click to expand it.
lib/metrics/metrics.go
+
1
−
0
View file @
17474c72
...
...
@@ -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
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment