oven-exporter/api/response_stats.go

61 lines
2.1 KiB
Go
Raw Permalink Normal View History

2021-07-21 00:15:57 +02:00
package api
2021-07-20 12:18:00 +02:00
import (
"fmt"
2021-08-22 15:26:13 +02:00
"net/http"
2021-07-20 12:18:00 +02:00
)
const (
2021-07-20 12:25:05 +02:00
URLRequestStatsVHost = "/v1/stats/current/vhosts/%s"
URLRequestStatsApp = "/v1/stats/current/vhosts/%s/apps/%s"
2021-07-20 12:18:00 +02:00
URLRequestStatsStream = "/v1/stats/current/vhosts/%s/apps/%s/streams/%s"
)
type ResponseStats struct {
2021-07-20 12:25:05 +02:00
Message string `json:"message"`
StatusCode int `json:"statusCode"`
Data *ResponseStatsData `json:"response,omitempty"`
2021-07-20 12:18:00 +02:00
}
type ResponseStatsData struct {
// - timestamp - time.TIme has problem with nanosecond in JSON
CreatedTime string `json:"createdTime" example:"2021-07-19T23:13:12.162+0200"`
LastRecvTime string `json:"lastRecvTime" example:"2021-07-19T23:23:27.274+0200"`
LastSentTime string `json:"lastSentTime" example:"2021-07-19T23:23:27.077+0200"`
2021-07-20 12:25:05 +02:00
LastUpdatedTime string `json:"lastUpdatedTime" example:"2021-07-19T23:23:27.274+0200"`
2021-07-20 12:18:00 +02:00
MaxTotalConnectionTime string `json:"maxTotalConnectionTime" example:"2021-07-19T23:16:37.851+0200"`
// - coonnections
2021-07-20 12:25:05 +02:00
TotalConnections int `json:"totalConnections" example:"1"`
MaxTotalConnections int `json:"maxTotalConnections" example:"2"`
2021-07-20 12:18:00 +02:00
// - traffic
2021-07-20 12:25:05 +02:00
TotalBytesIn uint64 `json:"totalBytesIn" example:"120197570"`
TotalBytesOut uint64 `json:"totalBytesOut" example:"117022184"`
2021-07-20 12:18:00 +02:00
}
2021-07-21 00:15:57 +02:00
func (c *Client) RequestStatsVHost(vhost string) (*ResponseStats, error) {
2021-07-20 12:18:00 +02:00
req := ResponseStats{}
url := fmt.Sprintf(URLRequestStatsVHost, vhost)
2021-08-22 15:26:13 +02:00
if err := c.Request(http.MethodGet, url, nil, &req); err != nil {
2021-07-20 12:18:00 +02:00
return nil, err
}
return &req, nil
}
2021-07-21 00:15:57 +02:00
func (c *Client) RequestStatsApp(vhost, app string) (*ResponseStats, error) {
2021-07-20 12:18:00 +02:00
req := ResponseStats{}
url := fmt.Sprintf(URLRequestStatsApp, vhost, app)
2021-08-22 15:26:13 +02:00
if err := c.Request(http.MethodGet, url, nil, &req); err != nil {
2021-07-20 12:18:00 +02:00
return nil, err
}
return &req, nil
}
2021-07-21 00:15:57 +02:00
func (c *Client) RequestStatsStream(vhost, app, stream string) (*ResponseStats, error) {
2021-07-20 12:18:00 +02:00
req := ResponseStats{}
url := fmt.Sprintf(URLRequestStatsStream, vhost, app, stream)
2021-08-22 15:26:13 +02:00
if err := c.Request(http.MethodGet, url, nil, &req); err != nil {
2021-07-20 12:18:00 +02:00
return nil, err
}
return &req, nil
}