Add metrics for GRPC calls.

This commit is contained in:
Joachim Bauch 2022-06-23 12:01:34 +02:00
parent b315c09a3b
commit b6e419f18a
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
4 changed files with 83 additions and 0 deletions

View File

@ -45,3 +45,6 @@ The following metrics are available:
| `signaling_mcu_no_backend_available_total` | Counter | 0.4.0 | Total number of publishing requests where no backend was available | `type` |
| `signaling_room_sessions` | Gauge | 0.4.0 | The current number of sessions in a room | `backend`, `room`, `clienttype` |
| `signaling_server_messages_total` | Counter | 0.4.0 | The total number of signaling messages | `type` |
| `signaling_grpc_clients` | Gauge | 1.0.0 | The current number of GRPC clients | |
| `signaling_grpc_client_calls_total` | Counter | 1.0.0 | The total number of GRPC client calls | `method` |
| `signaling_grpc_server_calls_total` | Counter | 1.0.0 | The total number of GRPC server calls | `method` |

View File

@ -37,6 +37,10 @@ import (
status "google.golang.org/grpc/status"
)
func init() {
RegisterGrpcClientStats()
}
type grpcClientImpl struct {
RpcMcuClient
RpcSessionsClient
@ -76,6 +80,7 @@ func (c *GrpcClient) Close() error {
}
func (c *GrpcClient) LookupSessionId(ctx context.Context, roomSessionId string) (string, error) {
statsGrpcClientCalls.WithLabelValues("LookupSessionId").Inc()
// TODO: Remove debug logging
log.Printf("Lookup room session %s on %s", roomSessionId, c.Target())
response, err := c.impl.LookupSessionId(ctx, &LookupSessionIdRequest{
@ -96,6 +101,7 @@ func (c *GrpcClient) LookupSessionId(ctx context.Context, roomSessionId string)
}
func (c *GrpcClient) IsSessionInCall(ctx context.Context, sessionId string, room *Room) (bool, error) {
statsGrpcClientCalls.WithLabelValues("IsSessionInCall").Inc()
// TODO: Remove debug logging
log.Printf("Check if session %s is in call %s on %s", sessionId, room.Id(), c.Target())
response, err := c.impl.IsSessionInCall(ctx, &IsSessionInCallRequest{
@ -113,6 +119,7 @@ func (c *GrpcClient) IsSessionInCall(ctx context.Context, sessionId string, room
}
func (c *GrpcClient) GetPublisherId(ctx context.Context, sessionId string, streamType string) (string, string, net.IP, error) {
statsGrpcClientCalls.WithLabelValues("GetPublisherId").Inc()
// TODO: Remove debug logging
log.Printf("Get %s publisher id %s on %s", streamType, sessionId, c.Target())
response, err := c.impl.GetPublisherId(ctx, &GetPublisherIdRequest{
@ -209,6 +216,7 @@ func (c *GrpcClients) load(config *goconf.ConfigFile) error {
c.clients = clients
c.clientsMap = clientsMap
statsGrpcClients.Set(float64(len(clients)))
return nil
}

View File

@ -35,6 +35,10 @@ import (
status "google.golang.org/grpc/status"
)
func init() {
RegisterGrpcServerStats()
}
type GrpcServer struct {
UnimplementedRpcMcuServer
UnimplementedRpcSessionsServer
@ -92,6 +96,7 @@ func (s *GrpcServer) Close() {
}
func (s *GrpcServer) LookupSessionId(ctx context.Context, request *LookupSessionIdRequest) (*LookupSessionIdReply, error) {
statsGrpcServerCalls.WithLabelValues("LookupSessionId").Inc()
// TODO: Remove debug logging
log.Printf("Lookup session id for room session id %s", request.RoomSessionId)
sid, err := s.hub.roomSessions.GetSessionId(request.RoomSessionId)
@ -107,6 +112,7 @@ func (s *GrpcServer) LookupSessionId(ctx context.Context, request *LookupSession
}
func (s *GrpcServer) IsSessionInCall(ctx context.Context, request *IsSessionInCallRequest) (*IsSessionInCallReply, error) {
statsGrpcServerCalls.WithLabelValues("IsSessionInCall").Inc()
// TODO: Remove debug logging
log.Printf("Check if session %s is in call %s on %s", request.SessionId, request.RoomId, request.BackendUrl)
session := s.hub.GetSessionByPublicId(request.SessionId)
@ -127,6 +133,7 @@ func (s *GrpcServer) IsSessionInCall(ctx context.Context, request *IsSessionInCa
}
func (s *GrpcServer) GetPublisherId(ctx context.Context, request *GetPublisherIdRequest) (*GetPublisherIdReply, error) {
statsGrpcServerCalls.WithLabelValues("GetPublisherId").Inc()
// TODO: Remove debug logging
log.Printf("Get %s publisher id for session %s", request.StreamType, request.SessionId)
session := s.hub.GetSessionByPublicId(request.SessionId)

65
grpc_stats_prometheus.go Normal file
View File

@ -0,0 +1,65 @@
/**
* Standalone signaling server for the Nextcloud Spreed app.
* Copyright (C) 2022 struktur AG
*
* @author Joachim Bauch <bauch@struktur.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
statsGrpcClients = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "signaling",
Subsystem: "grpc",
Name: "clients",
Help: "The current number of GRPC clients",
})
statsGrpcClientCalls = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "grpc",
Name: "client_calls_total",
Help: "The total number of GRPC client calls",
}, []string{"method"})
grpcClientStats = []prometheus.Collector{
statsGrpcClients,
statsGrpcClientCalls,
}
statsGrpcServerCalls = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "signaling",
Subsystem: "grpc",
Name: "server_calls_total",
Help: "The total number of GRPC server calls",
}, []string{"method"})
grpcServerStats = []prometheus.Collector{
statsGrpcServerCalls,
}
)
func RegisterGrpcClientStats() {
registerAll(grpcClientStats...)
}
func RegisterGrpcServerStats() {
registerAll(grpcServerStats...)
}