Skip to content

Commit

Permalink
fixup! Add a metrics for the TLS version used
Browse files Browse the repository at this point in the history
  • Loading branch information
silkeh committed Oct 10, 2019
1 parent b874eee commit bba788d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
13 changes: 8 additions & 5 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
Help: "Returns earliest SSL cert expiry in unixtime",
})

probeTLSVersion = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_tls_version",
Help: "Returns the TLS version used, or NaN when unknown",
})
probeTLSVersion = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "probe_tls_version_info",
Help: "Contains the TLS version used",
},
[]string{"version"},
)

probeHTTPVersionGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_http_version",
Expand Down Expand Up @@ -505,7 +508,7 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
isSSLGauge.Set(float64(1))
registry.MustRegister(probeSSLEarliestCertExpiryGauge, probeTLSVersion)
probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(resp.TLS).Unix()))
probeTLSVersion.Set(getTLSVersion(resp.TLS))
probeTLSVersion.WithLabelValues(getTLSVersion(resp.TLS)).Set(1)
if httpConfig.FailIfSSL {
level.Error(logger).Log("msg", "Final request was over SSL")
success = false
Expand Down
15 changes: 9 additions & 6 deletions prober/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
Name: "probe_ssl_earliest_cert_expiry",
Help: "Returns earliest SSL cert expiry date",
})
probeTLSVersion := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_tls_version",
Help: "Returns the TLS version used, or NaN when unknown",
})
probeTLSVersion := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "probe_tls_version_info",
Help: "Returns the TLS version used, or NaN when unknown",
},
[]string{"version"},
)
probeFailedDueToRegex := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_failed_due_to_regex",
Help: "Indicates if probe failed due to regex",
Expand All @@ -124,7 +127,7 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
state := conn.(*tls.Conn).ConnectionState()
registry.MustRegister(probeSSLEarliestCertExpiry, probeTLSVersion)
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeTLSVersion.Set(getTLSVersion(&state))
probeTLSVersion.WithLabelValues(getTLSVersion(&state)).Set(1)
}
scanner := bufio.NewScanner(conn)
for i, qr := range module.TCP.QueryResponse {
Expand Down Expand Up @@ -193,7 +196,7 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
state := tlsConn.ConnectionState()
registry.MustRegister(probeSSLEarliestCertExpiry)
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeTLSVersion.Set(getTLSVersion(&state))
probeTLSVersion.WithLabelValues(getTLSVersion(&state)).Set(1)
}
}
return true
Expand Down
13 changes: 6 additions & 7 deletions prober/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package prober

import (
"crypto/tls"
"math"
"time"
)

Expand All @@ -29,17 +28,17 @@ func getEarliestCertExpiry(state *tls.ConnectionState) time.Time {
return earliest
}

func getTLSVersion(state *tls.ConnectionState) float64 {
func getTLSVersion(state *tls.ConnectionState) string {
switch state.Version {
case tls.VersionTLS10:
return 1.0
return "TLS 1.0"
case tls.VersionTLS11:
return 1.1
return "TLS 1.1"
case tls.VersionTLS12:
return 1.2
return "TLS 1.2"
case tls.VersionTLS13:
return 1.3
return "TLS 1.3"
default:
return math.NaN()
return "unknown"
}
}

0 comments on commit bba788d

Please sign in to comment.