Backend: Expose prometheus-style metrics endpoint

Expose a new API which can be scraped by prometheus to gather useful
metrics from an instance. The new endpoint exposes photoprism build
version information, golang version, edition and various count metrics.
This commit is contained in:
Brandon Richardson
2023-01-28 15:56:57 -04:00
committed by Michael Mayer
parent 0935d9fab0
commit 3d962e2382
6 changed files with 175 additions and 1 deletions

View File

@@ -15,6 +15,19 @@ import (
"github.com/photoprism/photoprism/internal/get"
)
type CloseableResponseRecorder struct {
*httptest.ResponseRecorder
closeCh chan bool
}
func (r *CloseableResponseRecorder) CloseNotify() <-chan bool {
return r.closeCh
}
func (r *CloseableResponseRecorder) closeClient() {
r.closeCh <- true
}
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@@ -60,3 +73,13 @@ func PerformRequestWithBody(r http.Handler, method, path, body string) *httptest
return w
}
// Executes an API request with a stream response.
func PerformRequestWithStream(r http.Handler, method, path string) *CloseableResponseRecorder {
req, _ := http.NewRequest(method, path, nil)
w := &CloseableResponseRecorder{httptest.NewRecorder(), make(chan bool, 1)}
r.ServeHTTP(w, req)
return w
}