Skip to content

Commit

Permalink
proxy: add proxy_ssh_sessions_total metric
Browse files Browse the repository at this point in the history
This is similar to server_interactive_sessions_total, but tracks all
SSH sessions through a proxy.
  • Loading branch information
Andrew Lytvynov authored and awly committed Sep 18, 2020
1 parent 269d028 commit 3004b65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/srv/regular/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ import (

"github.com/gravitational/trace"
"github.com/pborman/uuid"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
)

var proxiedSessions = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: teleport.MetricProxySSHSessions,
Help: "Number of active sessions through this proxy",
},
)

func init() {
prometheus.MustRegister(proxiedSessions)
}

// proxySubsys implements an SSH subsystem for proxying listening sockets from
// remote hosts to a proxy client (AKA port mapping)
type proxySubsys struct {
Expand Down Expand Up @@ -250,6 +262,7 @@ func (t *proxySubsys) proxyToSite(
}
t.log.Infof("Connected to auth server: %v", conn.RemoteAddr())

proxiedSessions.Inc()
go func() {
var err error
defer func() {
Expand Down Expand Up @@ -424,6 +437,7 @@ func (t *proxySubsys) proxyToHost(
// address to the SSH server
t.doHandshake(remoteAddr, ch, conn)

proxiedSessions.Inc()
go func() {
var err error
defer func() {
Expand All @@ -446,6 +460,7 @@ func (t *proxySubsys) proxyToHost(

func (t *proxySubsys) close(err error) {
t.closeOnce.Do(func() {
proxiedSessions.Dec()
t.error = err
close(t.closeC)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/srv/sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var (
serverSessions = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: teleport.MetricServerInteractiveSessions,
Help: "Number of active sessions",
Help: "Number of active sessions to this host",
},
)
)
Expand Down
3 changes: 3 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const (
// MetricServerInteractiveSessions measures interactive sessions in flight
MetricServerInteractiveSessions = "server_interactive_sessions_total"

// MetricProxySSHSessions measures sessions in flight on the proxy
MetricProxySSHSessions = "proxy_ssh_sessions_total"

// MetricRemoteClusters measures connected remote clusters
MetricRemoteClusters = "remote_clusters"

Expand Down

0 comments on commit 3004b65

Please sign in to comment.