From 8d47a7681d32a894c98264abf7587199061c6b02 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Tue, 14 Apr 2020 21:24:37 +0200 Subject: [PATCH] add most documented metrics --- README.md | 3 + go.mod | 2 + go.sum | 3 + main.go | 125 +++++++++++++++++++---- main_test.go | 280 ++++++++++++++++++++++++++++++++++++++++++++------- 5 files changed, 358 insertions(+), 55 deletions(-) create mode 100644 go.sum diff --git a/README.md b/README.md index 688402d..973186b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ Prometheus Exporter for Jitsi Meet written in Go. Based on [Jitsi Meet Exporter](https://git.autistici.org/ai3/tools/jitsi-prometheus-exporter) from [Autistici](https://www.autistici.org/) +There's multiple different statistics endpoint that can be exposed by jitsi (like /stats and /colibri/stats); you can configure the used URL with the `videobridge-url`. +The exporter will handle both of them, but some metrics that aren't exposed may be reported as 0. + ## Usage ``` diff --git a/go.mod b/go.mod index c3fae30..88ee852 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/systemli/prometheus-jitsi-meet-exporter go 1.14 + +require github.com/google/go-cmp v0.4.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4430646 --- /dev/null +++ b/go.sum @@ -0,0 +1,3 @@ +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 5a09f5a..32dd3b0 100644 --- a/main.go +++ b/main.go @@ -14,33 +14,122 @@ var ( ) type videoBridgeStats struct { - LargestConference int `json:"largest_conference"` - TotalParticipants int `json:"total_participants"` - ConferenceSizes []int `json:"conference_sizes"` - TotalConferencesCreated int `json:"total_conferences_created"` - Conferences int `json:"conferences"` - Participants int `json:"participants"` + Threads int `json:"threads"` + BitRateDownload int `json:"bit_rate_download"` + BitRateUpload int `json:"bit_rate_upload"` + PacketRateDownload int `json:"packet_rate_download"` + PacketRateUpload int `json:"packet_rate_upload"` + LossRateDownload float64 `json:"loss_rate_download"` + LossRateUpload float64 `json:"loss_rate_upload"` + JitterAggregate float64 `json:"jitter_aggregate"` + RTTAggregate float64 `json:"rtt_aggregate"` + LargestConference int `json:"largest_conference"` + ConferenceSizes []int `json:"conference_sizes"` + AudioChannels int `json:"audiochannels"` + VideoChannels int `json:"videochannels"` + Conferences int `json:"conferences"` + Participants int `json:"participants"` + Videostreams int `json:"videostreams"` + TotalLossControlledParticipantSeconds int `json:"total_loss_controlled_participant_seconds"` + TotalLossLimitedParticipantSeconds int `json:"total_loss_limited_participant_seconds"` + TotalLossDegradedParticipantSeconds int `json:"total_loss_degraded_participant_seconds"` + TotalConferenceSeconds int `json:"total_conference_seconds"` + TotalConferencesCreated int `json:"total_conferences_created"` + TotalFailedConferences int `json:"total_failed_conferences"` + TotalPartiallyFailedConferences int `json:"total_partially_failed_conferences"` + TotalDataChannelMessagesReceived int `json:"total_data_channel_messages_received"` + TotalDataChannelMessagesSent int `json:"total_data_channel_messages_sent"` + TotalColibriWebSocketMessagesReceived int `json:"total_colibri_web_socket_messages_received"` + TotalColibriWebSocketMessagesSent int `json:"total_colibri_web_socket_messages_sent"` + TotalParticipants int `json:"total_participants"` } -var tpl = template.Must(template.New("stats").Parse(`# HELP jitsi_total_participants Participants counter -# TYPE jitsi_total_participants counter -jitsi_total_participants {{.TotalParticipants}} -# HELP jitsi_total_conferences_created Number of conferences created -# TYPE jitsi_total_conferences_created counter -jitsi_total_conferences_created {{.TotalConferencesCreated}} -# HELP jitsi_largest_conference Participants in the largest conference +var tpl = template.Must(template.New("stats").Parse(`# HELP jitsi_threads The number of Java threads that the video bridge is using. +# TYPE jitsi_threads gauge +jitsi_threads {{.Threads}} +# HELP jitsi_bit_rate_download The total incoming bitrate for the video bridge in kilobits per second. +# TYPE jitsi_bit_rate_download gauge +jitsi_bit_rate_download {{.BitRateDownload}} +# HELP jitsi_bit_rate_upload The total outgoing bitrate for the video bridge in kilobits per second. +# TYPE jitsi_bit_rate_upload gauge +jitsi_bit_rate_upload {{.BitRateUpload}} +# HELP jitsi_packet_rate_download The total incoming packet rate for the video bridge in packets per second. +# TYPE jitsi_packet_rate_download gauge +jitsi_packet_rate_download {{.PacketRateDownload}} +# HELP jitsi_packet_rate_upload The total outgoing packet rate for the video bridge in packets per second. +# TYPE jitsi_packet_rate_upload gauge +jitsi_packet_rate_upload {{.PacketRateUpload}} +# HELP jitsi_loss_rate_download The fraction of lost incoming RTP packets. This is based on RTP sequence numbers and is relatively accurate. +# TYPE jitsi_loss_rate_download gauge +jitsi_loss_rate_download {{.LossRateDownload}} +# HELP jitsi_loss_rate_upload The fraction of lost outgoing RTP packets. This is based on incoming RTCP Receiver Reports, and an attempt to subtract the fraction of packets that were not sent (i.e. were lost before they reached the bridge). Further, this is averaged over all streams of all users as opposed to all packets, so it is not correctly weighted. This is not accurate, but may be a useful metric nonetheless. +# TYPE jitsi_loss_rate_upload gauge +jitsi_loss_rate_upload {{.LossRateUpload}} +# HELP jitsi_jitter_aggregate Experimental. An average value (in milliseconds) of the jitter calculated for incoming and outgoing streams. This hasn't been tested and it is currently not known whether the values are correct or not. +# TYPE jitsi_jitter_aggregate gauge +jitsi_jitter_aggregate {{.JitterAggregate}} +# HELP jitsi_rtt_aggregate An average value (in milliseconds) of the RTT across all streams. +# TYPE jitsi_rtt_aggregate gauge +jitsi_rtt_aggregate {{.RTTAggregate}} +# HELP jitsi_largest_conference The number of participants in the largest conference currently hosted on the bridge. # TYPE jitsi_largest_conference gauge jitsi_largest_conference {{.LargestConference}} -# HELP jitsi_conferences Current number of active conferences +# HELP jitsi_audiochannels The current number of audio channels. +# TYPE jitsi_audiochannels gauge +jitsi_audiochannels {{.AudioChannels}} +# HELP jitsi_videochannels The current number of video channels. +# TYPE jitsi_videochannels gauge +jitsi_videochannels {{.VideoChannels}} +# HELP jitsi_conferences The current number of conferences. # TYPE jitsi_conferences gauge jitsi_conferences {{.Conferences}} -# HELP jitsi_participants Current number of active participants +# HELP jitsi_participants The current number of participants. # TYPE jitsi_participants gauge jitsi_participants {{.Participants}} +# HELP jitsi_videostreams An estimation of the number of current video streams forwarded by the bridge. +# TYPE jitsi_videostreams gauge +jitsi_videostreams {{.Videostreams}} +# HELP jitsi_total_loss_controlled_participant_seconds The total number of participant-seconds that are loss-controlled. +# TYPE jitsi_total_loss_controlled_participant_seconds counter +jitsi_total_loss_controlled_participant_seconds {{.TotalLossControlledParticipantSeconds}} +# HELP jitsi_total_loss_limited_participant_seconds The total number of participant-seconds that are loss-limited. +# TYPE jitsi_total_loss_limited_participant_seconds counter +jitsi_total_loss_limited_participant_seconds {{.TotalLossLimitedParticipantSeconds}} +# HELP jitsi_total_loss_degraded_participant_seconds The total number of participant-seconds that are loss-degraded. +# TYPE jitsi_total_loss_degraded_participant_seconds counter +jitsi_total_loss_degraded_participant_seconds {{.TotalLossDegradedParticipantSeconds}} +# HELP jitsi_total_conference_seconds The sum of the lengths of all completed conferences, in seconds. +# TYPE jitsi_total_conference_seconds counter +jitsi_total_conference_seconds {{.TotalConferenceSeconds}} +# HELP jitsi_total_conferences_created The total number of conferences created on the bridge. +# TYPE jitsi_total_conferences_created counter +jitsi_total_conferences_created {{.TotalConferencesCreated}} +# HELP jitsi_total_failed_conferences The total number of failed conferences on the bridge. A conference is marked as failed when all of its channels have failed. A channel is marked as failed if it had no payload activity. +# TYPE jitsi_total_failed_conferences counter +jitsi_total_failed_conferences {{.TotalFailedConferences}} +# HELP jitsi_total_partially_failed_conferences The total number of partially failed conferences on the bridge. A conference is marked as partially failed when some of its channels has failed. A channel is marked as failed if it had no payload activity. +# TYPE jitsi_total_partially_failed_conferences counter +jitsi_total_partially_failed_conferences {{.TotalPartiallyFailedConferences}} +# HELP jitsi_total_data_channel_messages_received The total number messages received through data channels. +# TYPE jitsi_total_data_channel_messages_received counter +jitsi_total_data_channel_messages_received {{.TotalDataChannelMessagesReceived}} +# HELP jitsi_total_data_channel_messages_sent The total number messages sent through data channels. +# TYPE jitsi_total_data_channel_messages_sent counter +jitsi_total_data_channel_messages_sent {{.TotalDataChannelMessagesSent}} +# HELP jitsi_total_colibri_web_socket_messages_received The total number messages received through COLIBRI web sockets. +# TYPE jitsi_total_colibri_web_socket_messages_received counter +jitsi_total_colibri_web_socket_messages_received {{.TotalColibriWebSocketMessagesReceived}} +# HELP jitsi_total_colibri_web_socket_messages_sent The total number messages sent through COLIBRI web sockets. +# TYPE jitsi_total_colibri_web_socket_messages_sent counter +jitsi_total_colibri_web_socket_messages_sent {{.TotalColibriWebSocketMessagesSent}} `)) -func serveMetrics(w http.ResponseWriter, req *http.Request) { - resp, err := http.Get(*videoBridgeURL) +type handler struct { + sourceURL string +} + +func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) { + resp, err := http.Get(h.sourceURL) if err != nil { log.Printf("scrape error: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) @@ -63,7 +152,7 @@ func main() { log.SetFlags(0) flag.Parse() - http.HandleFunc("/metrics", serveMetrics) + http.Handle("/metrics", handler{sourceURL: *videoBridgeURL}) if err := http.ListenAndServe(*addr, nil); err != nil { log.Fatal(err) } diff --git a/main_test.go b/main_test.go index fb8bb4d..c113bec 100644 --- a/main_test.go +++ b/main_test.go @@ -1,55 +1,261 @@ package main import ( - "log" "net/http" "net/http/httptest" "testing" + + "github.com/google/go-cmp/cmp" ) +type constHandler struct { + s string +} + +func (h constHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(h.s)) +} + func TestGetMetrics(t *testing.T) { - req, err := http.NewRequest("GET", "/metrics", nil) - if err != nil { - t.Fatal(err) - } - - go func() { - http.HandleFunc("/stats", getJitsiVideobridgeStats) - if err := http.ListenAndServe(":8888", nil); err != nil { - log.Fatal(err) - } - }() - - rr := httptest.NewRecorder() - handler := http.HandlerFunc(serveMetrics) - handler.ServeHTTP(rr, req) - - if status := rr.Code; status != http.StatusOK { - t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK) - } - - var expected = `# HELP jitsi_total_participants Participants counter -# TYPE jitsi_total_participants counter -jitsi_total_participants 18 -# HELP jitsi_total_conferences_created Number of conferences created -# TYPE jitsi_total_conferences_created counter -jitsi_total_conferences_created 14 -# HELP jitsi_largest_conference Participants in the largest conference + tcs := []struct { + statsJson string + expected string + }{ + { + statsJson: `{"largest_conference":3,"total_sip_call_failures":0,"total_participants":18,"conference_sizes":[0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"bridge_selector":{"total_least_loaded_in_region":0,"total_split_due_to_load":0,"total_not_loaded_in_region_in_conference":0,"total_least_loaded_in_region_in_conference":0,"total_not_loaded_in_region":0,"total_split_due_to_region":0,"bridge_count":1,"operational_bridge_count":1,"total_least_loaded_in_conference":0,"total_least_loaded":3},"total_conferences_created":14,"total_recording_failures":0,"conferences":2,"total_live_streaming_failures":0,"participants":4}`, + expected: `# HELP jitsi_threads The number of Java threads that the video bridge is using. +# TYPE jitsi_threads gauge +jitsi_threads 0 +# HELP jitsi_bit_rate_download The total incoming bitrate for the video bridge in kilobits per second. +# TYPE jitsi_bit_rate_download gauge +jitsi_bit_rate_download 0 +# HELP jitsi_bit_rate_upload The total outgoing bitrate for the video bridge in kilobits per second. +# TYPE jitsi_bit_rate_upload gauge +jitsi_bit_rate_upload 0 +# HELP jitsi_packet_rate_download The total incoming packet rate for the video bridge in packets per second. +# TYPE jitsi_packet_rate_download gauge +jitsi_packet_rate_download 0 +# HELP jitsi_packet_rate_upload The total outgoing packet rate for the video bridge in packets per second. +# TYPE jitsi_packet_rate_upload gauge +jitsi_packet_rate_upload 0 +# HELP jitsi_loss_rate_download The fraction of lost incoming RTP packets. This is based on RTP sequence numbers and is relatively accurate. +# TYPE jitsi_loss_rate_download gauge +jitsi_loss_rate_download 0 +# HELP jitsi_loss_rate_upload The fraction of lost outgoing RTP packets. This is based on incoming RTCP Receiver Reports, and an attempt to subtract the fraction of packets that were not sent (i.e. were lost before they reached the bridge). Further, this is averaged over all streams of all users as opposed to all packets, so it is not correctly weighted. This is not accurate, but may be a useful metric nonetheless. +# TYPE jitsi_loss_rate_upload gauge +jitsi_loss_rate_upload 0 +# HELP jitsi_jitter_aggregate Experimental. An average value (in milliseconds) of the jitter calculated for incoming and outgoing streams. This hasn't been tested and it is currently not known whether the values are correct or not. +# TYPE jitsi_jitter_aggregate gauge +jitsi_jitter_aggregate 0 +# HELP jitsi_rtt_aggregate An average value (in milliseconds) of the RTT across all streams. +# TYPE jitsi_rtt_aggregate gauge +jitsi_rtt_aggregate 0 +# HELP jitsi_largest_conference The number of participants in the largest conference currently hosted on the bridge. # TYPE jitsi_largest_conference gauge jitsi_largest_conference 3 -# HELP jitsi_conferences Current number of active conferences +# HELP jitsi_audiochannels The current number of audio channels. +# TYPE jitsi_audiochannels gauge +jitsi_audiochannels 0 +# HELP jitsi_videochannels The current number of video channels. +# TYPE jitsi_videochannels gauge +jitsi_videochannels 0 +# HELP jitsi_conferences The current number of conferences. # TYPE jitsi_conferences gauge jitsi_conferences 2 -# HELP jitsi_participants Current number of active participants +# HELP jitsi_participants The current number of participants. # TYPE jitsi_participants gauge jitsi_participants 4 -` +# HELP jitsi_videostreams An estimation of the number of current video streams forwarded by the bridge. +# TYPE jitsi_videostreams gauge +jitsi_videostreams 0 +# HELP jitsi_total_loss_controlled_participant_seconds The total number of participant-seconds that are loss-controlled. +# TYPE jitsi_total_loss_controlled_participant_seconds counter +jitsi_total_loss_controlled_participant_seconds 0 +# HELP jitsi_total_loss_limited_participant_seconds The total number of participant-seconds that are loss-limited. +# TYPE jitsi_total_loss_limited_participant_seconds counter +jitsi_total_loss_limited_participant_seconds 0 +# HELP jitsi_total_loss_degraded_participant_seconds The total number of participant-seconds that are loss-degraded. +# TYPE jitsi_total_loss_degraded_participant_seconds counter +jitsi_total_loss_degraded_participant_seconds 0 +# HELP jitsi_total_conference_seconds The sum of the lengths of all completed conferences, in seconds. +# TYPE jitsi_total_conference_seconds counter +jitsi_total_conference_seconds 0 +# HELP jitsi_total_conferences_created The total number of conferences created on the bridge. +# TYPE jitsi_total_conferences_created counter +jitsi_total_conferences_created 14 +# HELP jitsi_total_failed_conferences The total number of failed conferences on the bridge. A conference is marked as failed when all of its channels have failed. A channel is marked as failed if it had no payload activity. +# TYPE jitsi_total_failed_conferences counter +jitsi_total_failed_conferences 0 +# HELP jitsi_total_partially_failed_conferences The total number of partially failed conferences on the bridge. A conference is marked as partially failed when some of its channels has failed. A channel is marked as failed if it had no payload activity. +# TYPE jitsi_total_partially_failed_conferences counter +jitsi_total_partially_failed_conferences 0 +# HELP jitsi_total_data_channel_messages_received The total number messages received through data channels. +# TYPE jitsi_total_data_channel_messages_received counter +jitsi_total_data_channel_messages_received 0 +# HELP jitsi_total_data_channel_messages_sent The total number messages sent through data channels. +# TYPE jitsi_total_data_channel_messages_sent counter +jitsi_total_data_channel_messages_sent 0 +# HELP jitsi_total_colibri_web_socket_messages_received The total number messages received through COLIBRI web sockets. +# TYPE jitsi_total_colibri_web_socket_messages_received counter +jitsi_total_colibri_web_socket_messages_received 0 +# HELP jitsi_total_colibri_web_socket_messages_sent The total number messages sent through COLIBRI web sockets. +# TYPE jitsi_total_colibri_web_socket_messages_sent counter +jitsi_total_colibri_web_socket_messages_sent 0 +`, + }, + { + statsJson: `{ + "audiochannels": 0, + "bit_rate_download": 0, + "bit_rate_upload": 0, + "conference_sizes": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], + "conferences": 0, + "current_timestamp": "2019-03-14 11:02:15.184", + "graceful_shutdown": false, + "jitter_aggregate": 0, + "largest_conference": 0, + "loss_rate_download": 0, + "loss_rate_upload": 0, + "packet_rate_download": 0, + "packet_rate_upload": 0, + "participants": 0, + "region": "eu-west-1", + "relay_id": "10.0.0.5:4096", + "rtp_loss": 0, + "rtt_aggregate": 0, + "threads": 59, + "total_bytes_received": 257628359, + "total_bytes_received_octo": 0, + "total_bytes_sent": 257754048, + "total_bytes_sent_octo": 0, + "total_colibri_web_socket_messages_received": 0, + "total_colibri_web_socket_messages_sent": 0, + "total_conference_seconds": 470, + "total_conferences_completed": 1, + "total_conferences_created": 1, + "total_data_channel_messages_received": 602, + "total_data_channel_messages_sent": 600, + "total_failed_conferences": 0, + "total_ice_failed": 0, + "total_ice_succeeded": 2, + "total_ice_succeeded_tcp": 0, + "total_loss_controlled_participant_seconds": 847, + "total_loss_degraded_participant_seconds": 1, + "total_loss_limited_participant_seconds": 0, + "total_packets_dropped_octo": 0, + "total_packets_received": 266644, + "total_packets_received_octo": 0, + "total_packets_sent": 266556, + "total_packets_sent_octo": 0, + "total_partially_failed_conferences": 0, + "total_participants": 2, + "videochannels": 0, + "videostreams": 0 +}`, + expected: `# HELP jitsi_threads The number of Java threads that the video bridge is using. +# TYPE jitsi_threads gauge +jitsi_threads 59 +# HELP jitsi_bit_rate_download The total incoming bitrate for the video bridge in kilobits per second. +# TYPE jitsi_bit_rate_download gauge +jitsi_bit_rate_download 0 +# HELP jitsi_bit_rate_upload The total outgoing bitrate for the video bridge in kilobits per second. +# TYPE jitsi_bit_rate_upload gauge +jitsi_bit_rate_upload 0 +# HELP jitsi_packet_rate_download The total incoming packet rate for the video bridge in packets per second. +# TYPE jitsi_packet_rate_download gauge +jitsi_packet_rate_download 0 +# HELP jitsi_packet_rate_upload The total outgoing packet rate for the video bridge in packets per second. +# TYPE jitsi_packet_rate_upload gauge +jitsi_packet_rate_upload 0 +# HELP jitsi_loss_rate_download The fraction of lost incoming RTP packets. This is based on RTP sequence numbers and is relatively accurate. +# TYPE jitsi_loss_rate_download gauge +jitsi_loss_rate_download 0 +# HELP jitsi_loss_rate_upload The fraction of lost outgoing RTP packets. This is based on incoming RTCP Receiver Reports, and an attempt to subtract the fraction of packets that were not sent (i.e. were lost before they reached the bridge). Further, this is averaged over all streams of all users as opposed to all packets, so it is not correctly weighted. This is not accurate, but may be a useful metric nonetheless. +# TYPE jitsi_loss_rate_upload gauge +jitsi_loss_rate_upload 0 +# HELP jitsi_jitter_aggregate Experimental. An average value (in milliseconds) of the jitter calculated for incoming and outgoing streams. This hasn't been tested and it is currently not known whether the values are correct or not. +# TYPE jitsi_jitter_aggregate gauge +jitsi_jitter_aggregate 0 +# HELP jitsi_rtt_aggregate An average value (in milliseconds) of the RTT across all streams. +# TYPE jitsi_rtt_aggregate gauge +jitsi_rtt_aggregate 0 +# HELP jitsi_largest_conference The number of participants in the largest conference currently hosted on the bridge. +# TYPE jitsi_largest_conference gauge +jitsi_largest_conference 0 +# HELP jitsi_audiochannels The current number of audio channels. +# TYPE jitsi_audiochannels gauge +jitsi_audiochannels 0 +# HELP jitsi_videochannels The current number of video channels. +# TYPE jitsi_videochannels gauge +jitsi_videochannels 0 +# HELP jitsi_conferences The current number of conferences. +# TYPE jitsi_conferences gauge +jitsi_conferences 0 +# HELP jitsi_participants The current number of participants. +# TYPE jitsi_participants gauge +jitsi_participants 0 +# HELP jitsi_videostreams An estimation of the number of current video streams forwarded by the bridge. +# TYPE jitsi_videostreams gauge +jitsi_videostreams 0 +# HELP jitsi_total_loss_controlled_participant_seconds The total number of participant-seconds that are loss-controlled. +# TYPE jitsi_total_loss_controlled_participant_seconds counter +jitsi_total_loss_controlled_participant_seconds 847 +# HELP jitsi_total_loss_limited_participant_seconds The total number of participant-seconds that are loss-limited. +# TYPE jitsi_total_loss_limited_participant_seconds counter +jitsi_total_loss_limited_participant_seconds 0 +# HELP jitsi_total_loss_degraded_participant_seconds The total number of participant-seconds that are loss-degraded. +# TYPE jitsi_total_loss_degraded_participant_seconds counter +jitsi_total_loss_degraded_participant_seconds 1 +# HELP jitsi_total_conference_seconds The sum of the lengths of all completed conferences, in seconds. +# TYPE jitsi_total_conference_seconds counter +jitsi_total_conference_seconds 470 +# HELP jitsi_total_conferences_created The total number of conferences created on the bridge. +# TYPE jitsi_total_conferences_created counter +jitsi_total_conferences_created 1 +# HELP jitsi_total_failed_conferences The total number of failed conferences on the bridge. A conference is marked as failed when all of its channels have failed. A channel is marked as failed if it had no payload activity. +# TYPE jitsi_total_failed_conferences counter +jitsi_total_failed_conferences 0 +# HELP jitsi_total_partially_failed_conferences The total number of partially failed conferences on the bridge. A conference is marked as partially failed when some of its channels has failed. A channel is marked as failed if it had no payload activity. +# TYPE jitsi_total_partially_failed_conferences counter +jitsi_total_partially_failed_conferences 0 +# HELP jitsi_total_data_channel_messages_received The total number messages received through data channels. +# TYPE jitsi_total_data_channel_messages_received counter +jitsi_total_data_channel_messages_received 602 +# HELP jitsi_total_data_channel_messages_sent The total number messages sent through data channels. +# TYPE jitsi_total_data_channel_messages_sent counter +jitsi_total_data_channel_messages_sent 600 +# HELP jitsi_total_colibri_web_socket_messages_received The total number messages received through COLIBRI web sockets. +# TYPE jitsi_total_colibri_web_socket_messages_received counter +jitsi_total_colibri_web_socket_messages_received 0 +# HELP jitsi_total_colibri_web_socket_messages_sent The total number messages sent through COLIBRI web sockets. +# TYPE jitsi_total_colibri_web_socket_messages_sent counter +jitsi_total_colibri_web_socket_messages_sent 0 +`, + }, + } - if rr.Body.String() != expected { - t.Error("Response does not match the expected string") + for _, tc := range tcs { + srv := httptest.NewServer(constHandler{tc.statsJson}) + + h := handler{ + sourceURL: srv.URL, + } + req, err := http.NewRequest("GET", "/metrics", nil) + if err != nil { + t.Fatal(err) + } + + rr := httptest.NewRecorder() + h.ServeHTTP(rr, req) + + if status := rr.Code; status != http.StatusOK { + t.Errorf("handler returned wrong status code: got %v want %v", status, http.StatusOK) + } + + if rr.Body.String() != tc.expected { + t.Errorf("Response does not match the expected string:\n%s", cmp.Diff(rr.Body.String(), tc.expected)) + } + + srv.Close() } } - -func getJitsiVideobridgeStats(w http.ResponseWriter, _ *http.Request) { - _, _ = w.Write([]byte(`{"largest_conference":3,"total_sip_call_failures":0,"total_participants":18,"conference_sizes":[0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"bridge_selector":{"total_least_loaded_in_region":0,"total_split_due_to_load":0,"total_not_loaded_in_region_in_conference":0,"total_least_loaded_in_region_in_conference":0,"total_not_loaded_in_region":0,"total_split_due_to_region":0,"bridge_count":1,"operational_bridge_count":1,"total_least_loaded_in_conference":0,"total_least_loaded":3},"total_conferences_created":14,"total_recording_failures":0,"conferences":2,"total_live_streaming_failures":0,"participants":4}`)) -}