2016-04-29 18:06:19 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
2016-05-27 21:15:51 +00:00
|
|
|
"fmt"
|
2016-04-29 18:06:19 +00:00
|
|
|
"net/http"
|
2016-05-27 21:15:51 +00:00
|
|
|
"strconv"
|
2016-04-29 18:06:19 +00:00
|
|
|
)
|
|
|
|
|
2016-05-28 00:01:08 +00:00
|
|
|
const (
|
|
|
|
invalidSinceErrPrefix = "can't read the since query parameter"
|
|
|
|
)
|
|
|
|
|
2016-05-24 23:41:35 +00:00
|
|
|
func (s *HTTPServer) ClientStatsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
2016-04-29 18:06:19 +00:00
|
|
|
if s.agent.client == nil {
|
|
|
|
return nil, clientNotRunning
|
|
|
|
}
|
2016-05-09 19:24:03 +00:00
|
|
|
|
2016-05-27 21:15:51 +00:00
|
|
|
var since int
|
|
|
|
var err error
|
|
|
|
ts := false
|
|
|
|
if sinceTime := req.URL.Query().Get("since"); sinceTime != "" {
|
|
|
|
ts = true
|
|
|
|
since, err = strconv.Atoi(sinceTime)
|
|
|
|
if err != nil {
|
2016-05-28 00:01:08 +00:00
|
|
|
return nil, CodedError(400, fmt.Sprintf("%s: %v", invalidSinceErrPrefix, err))
|
2016-05-27 21:15:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 19:24:03 +00:00
|
|
|
clientStats := s.agent.client.StatsReporter()
|
2016-05-27 21:15:51 +00:00
|
|
|
if ts {
|
|
|
|
return clientStats.HostStatsTS(int64(since)), nil
|
|
|
|
}
|
2016-05-24 23:41:35 +00:00
|
|
|
return clientStats.HostStats(), nil
|
2016-05-18 05:11:25 +00:00
|
|
|
}
|