|
1
|
package api |
|
2
|
|
|
3
|
import ( |
|
4
|
"net/http" |
|
5
|
"time" |
|
6
|
) |
|
7
|
|
|
8
|
var startTime = time.Now() |
|
9
|
|
|
10
|
type statusResponse struct { |
|
11
|
Status string `json:"status"` |
|
12
|
Uptime string `json:"uptime"` |
|
13
|
Agents int `json:"agents"` |
|
14
|
Started time.Time `json:"started"` |
|
15
|
} |
|
16
|
|
|
17
|
func (s *Server) handleStatus(w http.ResponseWriter, r *http.Request) { |
|
18
|
agents := s.registry.List() |
|
19
|
writeJSON(w, http.StatusOK, statusResponse{ |
|
20
|
Status: "ok", |
|
21
|
Uptime: time.Since(startTime).Round(time.Second).String(), |
|
22
|
Agents: len(agents), |
|
23
|
Started: startTime, |
|
24
|
}) |
|
25
|
} |
|
26
|
|