2016-03-05 02:08:16 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Standard represents a standard tile38 message.
|
|
|
|
type Standard struct {
|
|
|
|
OK bool `json:"ok"`
|
|
|
|
Err string `json:"err"`
|
|
|
|
Elapsed string `json:"elapsed"`
|
|
|
|
}
|
|
|
|
|
2016-04-03 05:16:36 +03:00
|
|
|
// ServerStats represents tile38 server statistics.
|
2016-03-08 18:35:43 +03:00
|
|
|
type ServerStats struct {
|
2016-03-05 02:08:16 +03:00
|
|
|
Standard
|
|
|
|
Stats struct {
|
|
|
|
ServerID string `json:"id"`
|
|
|
|
Following string `json:"following"`
|
|
|
|
AOFSize int `json:"aof_size"`
|
|
|
|
NumCollections int `json:"num_collections"`
|
|
|
|
InMemorySize int `json:"in_memory_size"`
|
|
|
|
NumPoints int `json:"num_points"`
|
|
|
|
NumObjects int `json:"num_objects"`
|
|
|
|
HeapSize int `json:"heap_size"`
|
|
|
|
AvgItemSize int `json:"avg_item_size"`
|
|
|
|
PointerSize int `json:"pointer_size"`
|
|
|
|
} `json:"stats"`
|
|
|
|
}
|
|
|
|
|
2016-04-03 05:16:36 +03:00
|
|
|
// Server returns tile38 server statistics.
|
2016-03-08 18:35:43 +03:00
|
|
|
func (conn *Conn) Server() (ServerStats, error) {
|
|
|
|
var stats ServerStats
|
|
|
|
msg, err := conn.Do("server")
|
2016-03-05 02:08:16 +03:00
|
|
|
if err != nil {
|
|
|
|
return stats, err
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal(msg, &stats); err != nil {
|
|
|
|
return stats, err
|
|
|
|
}
|
|
|
|
if !stats.OK {
|
2016-03-08 18:35:43 +03:00
|
|
|
if stats.Err != "" {
|
2016-03-05 02:08:16 +03:00
|
|
|
return stats, errors.New(stats.Err)
|
|
|
|
}
|
|
|
|
return stats, errors.New("not ok")
|
|
|
|
}
|
|
|
|
return stats, nil
|
|
|
|
}
|