health monitoring for prism, expose server version in /api/health

This commit is contained in:
lone-cloud 2026-02-07 03:07:21 -08:00
parent 2aa86c6757
commit cc21c41e73
4 changed files with 32 additions and 3 deletions

View file

@ -30,4 +30,7 @@ USER prism
EXPOSE 8080 EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
CMD ["./prism"] CMD ["./prism"]

View file

@ -105,6 +105,7 @@ All notifications will now be sent to your Telegram chat. Unlike Signal, Telegra
Receive notifications when new Proton Mail emails arrive. Receive notifications when new Proton Mail emails arrive.
Unlike other integrations, this one will generate new messages to be delivered by one of the configured transports. Unlike other integrations, this one will generate new messages to be delivered by one of the configured transports.
Note that using this integration requires a paid Proton Mail account to be able to use the Proton Mail Bridge that this integration relies on. Note that using this integration requires a paid Proton Mail account to be able to use the Proton Mail Bridge that this integration relies on.
Also note that the Proton Mail Bridge is RAM hungry.
> **Note:** The default image (`shenxn/protonmail-bridge:build`) used by Prism compiles from source and supports all architectures. For x86_64 only, you can use `shenxn/protonmail-bridge:latest` (smaller, faster). > **Note:** The default image (`shenxn/protonmail-bridge:build`) used by Prism compiles from source and supports all architectures. For x86_64 only, you can use `shenxn/protonmail-bridge:latest` (smaller, faster).
@ -246,8 +247,25 @@ curl -X DELETE http://localhost:8080/webpush/app/my-app \
The health of the system can be viewed in the same admin UI used for linking Signal. Prism uses [basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) - provide your `API_KEY` as the password (username can be anything). The health of the system can be viewed in the same admin UI used for linking Signal. Prism uses [basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) - provide your `API_KEY` as the password (username can be anything).
For API-based monitoring, call `/api/health` which returns JSON: ### Health Endpoints
#### GET /health
Public health check endpoint (no authentication required). Returns `200 OK` when the service is running. Used for Docker health checks and load balancer health probes.
```bash
curl http://localhost:8080/health
```
#### GET /api/health
Detailed health endpoint (requires authentication). Returns JSON with uptime and integration status:
```bash
curl http://localhost:8080/api/health \
-H "Authorization: Bearer YOUR_API_KEY"
```
```json ```json
{"uptime":"3s","signal":{"linked":true},"proton":{"linked":true},"telegram":{"linked":true}} {"version":"1.0.0","uptime":"3s","signal":{"linked":true},"proton":{"linked":true},"telegram":{"linked":true}}
``` ```

View file

@ -9,6 +9,7 @@ import (
) )
type healthResponse struct { type healthResponse struct {
Version string `json:"version"`
Uptime string `json:"uptime"` Uptime string `json:"uptime"`
Signal *integrationHealth `json:"signal,omitempty"` Signal *integrationHealth `json:"signal,omitempty"`
Proton *integrationHealth `json:"proton,omitempty"` Proton *integrationHealth `json:"proton,omitempty"`
@ -19,11 +20,16 @@ type integrationHealth struct {
Linked bool `json:"linked"` Linked bool `json:"linked"`
} }
func (s *Server) handleHealthCheck(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) { func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
uptime := time.Since(s.startTime) uptime := time.Since(s.startTime)
resp := healthResponse{ resp := healthResponse{
Uptime: util.FormatUptime(uptime), Version: s.version,
Uptime: util.FormatUptime(uptime),
} }
if s.integrations.Signal != nil && s.integrations.Signal.IsEnabled() { if s.integrations.Signal != nil && s.integrations.Signal.IsEnabled() {

View file

@ -123,6 +123,8 @@ func (s *Server) setupRoutes() {
integration.RegisterAll(s.integrations, r, s.cfg, s.store, s.logger, authMiddleware) integration.RegisterAll(s.integrations, r, s.cfg, s.store, s.logger, authMiddleware)
r.Get("/health", s.handleHealthCheck)
r.With(authMiddleware(s.cfg.APIKey)).Get("/fragment/apps", s.handleFragmentApps) r.With(authMiddleware(s.cfg.APIKey)).Get("/fragment/apps", s.handleFragmentApps)
r.With(authMiddleware(s.cfg.APIKey)).Get("/fragment/integrations", s.handleFragmentIntegrations) r.With(authMiddleware(s.cfg.APIKey)).Get("/fragment/integrations", s.handleFragmentIntegrations)