From 994145b6096a36c6bbb70bd1d0b6168f76703dbf Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 9 Mar 2022 17:48:53 -0800 Subject: [PATCH] Fix prometheus viewer count value & rename metrics names --- metrics/metrics.go | 11 +++++------ metrics/viewers.go | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/metrics/metrics.go b/metrics/metrics.go index 8de152c22..dbbbcbd4b 100644 --- a/metrics/metrics.go +++ b/metrics/metrics.go @@ -35,31 +35,31 @@ func Start(getStatus func() models.Status) { } activeViewerCount = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "active_viewer_count", + Name: "owncast_instance_active_viewer_count", Help: "The number of viewers.", ConstLabels: labels, }) activeChatClientCount = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "active_chat_client_count", + Name: "owncast_instance_active_chat_client_count", Help: "The number of connected chat clients.", ConstLabels: labels, }) chatUserCount = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "total_chat_users", + Name: "owncast_instance_total_chat_users", Help: "The total number of chat users on this Owncast instance.", ConstLabels: labels, }) currentChatMessageCount = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "current_chat_message_count", + Name: "owncast_instance_current_chat_message_count", Help: "The number of chat messages currently saved before cleanup.", ConstLabels: labels, }) cpuUsage = promauto.NewGauge(prometheus.GaugeOpts{ - Name: "cpu_use_pct", + Name: "owncast_instance_cpu_use_pct", Help: "CPU percentage used as seen within Owncast", ConstLabels: labels, }) @@ -77,7 +77,6 @@ func handlePolling() { collectCPUUtilization() collectRAMUtilization() collectDiskUtilization() - collectChatClientCount() // Alerting handleAlerting() diff --git a/metrics/viewers.go b/metrics/viewers.go index 83958f927..79539be90 100644 --- a/metrics/viewers.go +++ b/metrics/viewers.go @@ -23,10 +23,10 @@ func startViewerCollectionMetrics() { defer storage.Close() collectViewerCount() - handlePolling() for range time.Tick(viewerMetricsPollingInterval) { collectViewerCount() + collectChatClientCount() } } @@ -35,15 +35,15 @@ func collectViewerCount() { if !core.GetStatus().Online { return } + + // Save to our Prometheus collector. + activeViewerCount.Set(float64(core.GetStatus().ViewerCount)) } func collectChatClientCount() { count := len(chat.GetClients()) activeChatClientCount.Set(float64(count)) - // Save to our Prometheus collector. - activeViewerCount.Set(float64(count)) - // Total message count cmc := data.GetMessagesCount() currentChatMessageCount.Set(float64(cmc))