Skip to content

Commit

Permalink
add OS and CPU arch to status API (#256)
Browse files Browse the repository at this point in the history
This commit exposes the server OS and
CPU architecture via the status API.

```
● 127.0.0.1:7373
  Version  v0.0.0-dev
  Uptime   8 minutes
  Latency  8ms
  OS       darwin
  CPUs     8 arm64
  Memory
  · Heap   1 MiB
  · Stack  640 KiB
```

Signed-off-by: Andreas Auernhammer <hi@aead.dev>
  • Loading branch information
aead committed Jul 13, 2022
1 parent 806e8a1 commit f8916be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions client.go
Expand Up @@ -163,6 +163,8 @@ func (c *Client) Status(ctx context.Context) (State, error) {

type Response struct {
Version string `json:"version"`
OS string `json:"os"`
Arch string `json:"arch"`
UpTime time.Duration `json:"uptime"`

CPUs int `json:"num_cpu"`
Expand Down
5 changes: 5 additions & 0 deletions cmd/kes/status.go
Expand Up @@ -149,9 +149,14 @@ func statusCmd(args []string) {
faint.Render(fmt.Sprintf(" %-8s", "Latency")),
latency.Round(time.Millisecond),
)
fmt.Println(
faint.Render(fmt.Sprintf(" %-8s", "OS")),
status.OS,
)
fmt.Println(
faint.Render(fmt.Sprintf(" %-8s", "CPUs")),
strconv.Itoa(status.UsableCPUs),
status.Arch,
)
fmt.Println(faint.Render(fmt.Sprintf(" %-8s", "Memory")))
fmt.Println(
Expand Down
4 changes: 4 additions & 0 deletions internal/http/generic-api.go
Expand Up @@ -50,6 +50,8 @@ func status(mux *http.ServeMux, config *ServerConfig) API {
)
type Response struct {
Version string `json:"version"`
OS string `json:"os"`
Arch string `json:"arch"`
UpTime time.Duration `json:"uptime"`

CPUs int `json:"num_cpu"`
Expand Down Expand Up @@ -86,6 +88,8 @@ func status(mux *http.ServeMux, config *ServerConfig) API {
w.Header().Set("Content-Type", ContentType)
json.NewEncoder(w).Encode(Response{
Version: sys.BinaryInfo().Version,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
UpTime: time.Since(startTime).Round(time.Second),

CPUs: runtime.NumCPU(),
Expand Down
19 changes: 8 additions & 11 deletions server.go
Expand Up @@ -8,17 +8,14 @@ import "time"

// State is a KES server status snapshot.
type State struct {
Version string `json:"version"` // The KES server version

UpTime time.Duration `json:"uptime"` // The time the KES server has been up and running

CPUs int `json:"num_cpu"`

UsableCPUs int `json:"num_cpu_used"`

HeapAlloc uint64 `json:"num_heap_used"`

StackAlloc uint64 `json:"num_stack_used"`
Version string `json:"version"` // KES server version
OS string `json:"os"` // OS running the KES server
Arch string `json:"arch"` // CPU architecture the KES server is running on
UpTime time.Duration `json:"uptime"` // Time the KES server has been up and running
CPUs int `json:"num_cpu"` // Number of available logical CPU cores
UsableCPUs int `json:"num_cpu_used"` // Number of usbale logical CPU cores
HeapAlloc uint64 `json:"num_heap_used"` // Number of bytes currently allocated on the heap
StackAlloc uint64 `json:"num_stack_used"` // Number of bytes currently allocated on the stack
}

// API describes a KES server API.
Expand Down

0 comments on commit f8916be

Please sign in to comment.