@@ -25,6 +25,8 @@ type Metrics struct {
2525 totalUsers prometheus.Gauge
2626 totalLiveWatchedChannels prometheus.Gauge
2727 channelVodCount * prometheus.GaugeVec
28+ totalVodsDuration prometheus.Gauge
29+ channelVodDuration * prometheus.GaugeVec
2830 totalVodsInQueue prometheus.Gauge
2931 riverTotalPendingJobs prometheus.Gauge
3032 riverTotalScheduledJobs prometheus.Gauge
@@ -59,6 +61,14 @@ func NewService(store *database.Database, riverClient *tasks_client.RiverClient)
5961 Name : "channel_vod_count" ,
6062 Help : "Number of vods per channel" ,
6163 }, []string {"channel" }),
64+ totalVodsDuration : prometheus .NewGauge (prometheus.GaugeOpts {
65+ Name : "total_vods_duration_seconds" ,
66+ Help : "Total duration of all VODs in seconds" ,
67+ }),
68+ channelVodDuration : prometheus .NewGaugeVec (prometheus.GaugeOpts {
69+ Name : "channel_vod_duration_seconds" ,
70+ Help : "Total duration of VODs per channel in seconds" ,
71+ }, []string {"channel" }),
6272 totalVodsInQueue : prometheus .NewGauge (prometheus.GaugeOpts {
6373 Name : "total_vods_in_queue" ,
6474 Help : "Total number of vods in queue" ,
@@ -103,6 +113,8 @@ func NewService(store *database.Database, riverClient *tasks_client.RiverClient)
103113 metrics .totalUsers ,
104114 metrics .totalLiveWatchedChannels ,
105115 metrics .channelVodCount ,
116+ metrics .totalVodsDuration ,
117+ metrics .channelVodDuration ,
106118 metrics .totalVodsInQueue ,
107119 metrics .riverTotalPendingJobs ,
108120 metrics .riverTotalScheduledJobs ,
@@ -214,7 +226,8 @@ func (s *Service) GatherMetrics() (*prometheus.Registry, error) {
214226 s .metrics .totalLiveWatchedChannels .Set (0 )
215227 }
216228 s .metrics .totalLiveWatchedChannels .Set (float64 (lwCount ))
217- // Get all channels and the number of VODs they have
229+ // Get all channels with the number of VODs they have and their total duration
230+ var totalDurationSeconds int64 = 0
218231 channels , err := s .Store .Client .Channel .Query ().WithVods ().All (context .Background ())
219232 if err != nil {
220233 log .Error ().Err (err ).Msg ("error getting all channels" )
@@ -223,7 +236,14 @@ func (s *Service) GatherMetrics() (*prometheus.Registry, error) {
223236 for _ , channel := range channels {
224237 cVCount := len (channel .Edges .Vods )
225238 s .metrics .channelVodCount .With (prometheus.Labels {"channel" : channel .Name }).Set (float64 (cVCount ))
239+ var channelDuration int64 = 0
240+ for _ , vod := range channel .Edges .Vods {
241+ channelDuration += int64 (vod .Duration )
242+ }
243+ s .metrics .channelVodDuration .With (prometheus.Labels {"channel" : channel .Name }).Set (float64 (channelDuration ))
244+ totalDurationSeconds += channelDuration
226245 }
246+ s .metrics .totalVodsDuration .Set (float64 (totalDurationSeconds ))
227247 // Total VODs in queue
228248 qCount , err := s .Store .Client .Queue .Query ().Where (queue .Processing (true )).Count (context .Background ())
229249 if err != nil {
0 commit comments