Expose Prometheus metrics on a separate port
Metrics are served on METRICS_PORT (default 2112, "off" to disable), never on the public port. Besides the Go runtime and process metrics this adds: - http_requests_total and http_request_duration_seconds per route pattern, from an Echo middleware. - musicserver_songs_requested_total and musicserver_songs_played_total by pick mode (random, low, classic). The mode is now stored with each queued song (migration 000006, not released yet). - Library size, sync duration, last successful sync, broken songs from the last full sync, and the database connection pool. Refs #35, #36, #37 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c62b65d7cd
commit
f79f51ea4c
28 files changed
+864
-70
No files matched your search
@@ -431,7 +431,9 @@ func (s *Store) EndActiveQueues(context.Context) error {
|
||||
}
|
||||
|
||||
func (s *Store) SetQueueLastFetched(_ context.Context, arg repository.SetQueueLastFetchedParams) error {
|
||||
return s.updateQueue(arg.Uuid, func(q *repository.Queue) { q.LastFetchedSongUuid = arg.LastFetchedSongUuid })
|
||||
return s.updateQueue(arg.Uuid, func(q *repository.Queue) {
|
||||
q.LastFetchedSongUuid, q.LastFetchedMode = arg.LastFetchedSongUuid, arg.LastFetchedMode
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Store) SetQueueCurrentSong(_ context.Context, arg repository.SetQueueCurrentSongParams) error {
|
||||
@@ -457,6 +459,10 @@ func (s *Store) AddLastFetchedToQueue(_ context.Context, id uuid.UUID) error {
|
||||
if st := s.soundtrackIndex(song.SoundtrackID); st >= 0 {
|
||||
soundtrackName = s.Soundtracks[st].SoundtrackName
|
||||
}
|
||||
mode := "unknown"
|
||||
if queue.LastFetchedMode != nil {
|
||||
mode = *queue.LastFetchedMode
|
||||
}
|
||||
songNo := int32(0)
|
||||
for _, qs := range s.QueueSongs {
|
||||
if qs.QueueUuid == id {
|
||||
@@ -465,9 +471,10 @@ func (s *Store) AddLastFetchedToQueue(_ context.Context, id uuid.UUID) error {
|
||||
}
|
||||
s.QueueSongs = append(s.QueueSongs, repository.QueueSong{
|
||||
QueueUuid: id, SongNo: songNo, SongUuid: song.Uuid, SoundtrackName: soundtrackName, SongName: song.SongName,
|
||||
Mode: mode,
|
||||
})
|
||||
queue.CurrentSong = songNo
|
||||
queue.LastFetchedSongUuid = uuid.Nil
|
||||
queue.LastFetchedSongUuid, queue.LastFetchedMode = uuid.Nil, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -481,7 +488,9 @@ func (s *Store) ListQueueSongs(_ context.Context, id uuid.UUID) ([]repository.Li
|
||||
if qs.QueueUuid != id {
|
||||
continue
|
||||
}
|
||||
row := repository.ListQueueSongsRow{SongNo: qs.SongNo, SongUuid: qs.SongUuid, SoundtrackName: qs.SoundtrackName, SongName: qs.SongName}
|
||||
row := repository.ListQueueSongsRow{
|
||||
SongNo: qs.SongNo, SongUuid: qs.SongUuid, SoundtrackName: qs.SoundtrackName, SongName: qs.SongName, Mode: qs.Mode,
|
||||
}
|
||||
if i := slices.IndexFunc(s.Songs, func(song repository.Song) bool { return song.Uuid == qs.SongUuid }); i >= 0 {
|
||||
song := s.Songs[i]
|
||||
row.Path, row.TimesPlayed, row.SoundtrackUuid = &song.Path, &song.TimesPlayed, song.SoundtrackUuid
|
||||
@@ -492,6 +501,26 @@ func (s *Store) ListQueueSongs(_ context.Context, id uuid.UUID) ([]repository.Li
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (s *Store) CountLibrary(context.Context) (repository.CountLibraryRow, error) {
|
||||
defer s.lock()()
|
||||
if s.Err != nil {
|
||||
return repository.CountLibraryRow{}, s.Err
|
||||
}
|
||||
var count repository.CountLibraryRow
|
||||
for _, st := range s.Soundtracks {
|
||||
if st.Deleted != nil {
|
||||
continue
|
||||
}
|
||||
count.Soundtracks++
|
||||
for _, song := range s.Songs {
|
||||
if song.SoundtrackID == st.ID {
|
||||
count.Songs++
|
||||
}
|
||||
}
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Statistics queries return empty results; tests that need data use their own fakes.
|
||||
|
||||
func (s *Store) GetMostPlayedSoundtracksWithSongs(context.Context, int32) ([]repository.GetMostPlayedSoundtracksWithSongsRow, error) {
|
||||
|
||||
Reference in new issue
Block a user