@@ -7,11 +7,13 @@ package bmc
7
7
import (
8
8
"context"
9
9
"crypto/tls"
10
+ "crypto/x509"
10
11
"fmt"
11
12
"io"
12
13
"net"
13
14
14
15
"github.com/grpc-ecosystem/go-grpc-prometheus"
16
+ "github.com/prometheus/client_golang/prometheus"
15
17
"github.com/u-root/u-bmc/config"
16
18
pb "github.com/u-root/u-bmc/proto"
17
19
"google.golang.org/grpc"
@@ -41,6 +43,26 @@ type mgmtServer struct {
41
43
v * config.Version
42
44
}
43
45
46
+ var (
47
+ tlsCertificateExpiry = prometheus .NewGauge (prometheus.GaugeOpts {
48
+ Namespace : "ubmc" ,
49
+ Subsystem : "grpc" ,
50
+ Name : "certificate_expiry" ,
51
+ Help : "UNIX timestamp when the currently loaded TLS certificate expires for the gRPC server" ,
52
+ })
53
+ tlsCertificateLoaded = prometheus .NewGauge (prometheus.GaugeOpts {
54
+ Namespace : "ubmc" ,
55
+ Subsystem : "grpc" ,
56
+ Name : "certificate_loaded" ,
57
+ Help : "Whether the gRPC server has loaded a certificate" ,
58
+ })
59
+ )
60
+
61
+ func init () {
62
+ prometheus .MustRegister (tlsCertificateExpiry )
63
+ prometheus .MustRegister (tlsCertificateLoaded )
64
+ }
65
+
44
66
func (m * mgmtServer ) PressButton (ctx context.Context , r * pb.ButtonPressRequest ) (* pb.ButtonPressResponse , error ) {
45
67
c , err := m .gpio .PressButton (ctx , r .Button , r .DurationMs )
46
68
if err != nil {
@@ -119,6 +141,11 @@ func (m *mgmtServer) newServer(l net.Listener, c *tls.Certificate) {
119
141
if c != nil {
120
142
creds := credentials .NewServerTLSFromCert (c )
121
143
opts = []grpc.ServerOption {grpc .Creds (creds )}
144
+ c , err := x509 .ParseCertificate (c .Certificate [0 ])
145
+ if err == nil {
146
+ tlsCertificateLoaded .Set (float64 (1 ))
147
+ tlsCertificateExpiry .Set (float64 (c .NotAfter .Unix ()))
148
+ }
122
149
}
123
150
124
151
g := grpc .NewServer (opts ... )
0 commit comments