feat: expose monitoring tg ai job health
This commit is contained in:
@@ -83,6 +83,41 @@ type ProviderStatus struct {
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type Stats struct {
|
||||
At time.Time `json:"at"`
|
||||
Owners []OwnerStat `json:"owners,omitempty"`
|
||||
Errors []ErrorStat `json:"errors,omitempty"`
|
||||
Backlog []BacklogStat `json:"backlog,omitempty"`
|
||||
}
|
||||
|
||||
type OwnerStat struct {
|
||||
OwnerService string `json:"owner_service"`
|
||||
TaskType string `json:"task_type"`
|
||||
ModelProfile string `json:"model_profile"`
|
||||
Status string `json:"status"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
type ErrorStat struct {
|
||||
OwnerService string `json:"owner_service,omitempty"`
|
||||
TaskType string `json:"task_type"`
|
||||
ModelProfile string `json:"model_profile"`
|
||||
ErrorCode string `json:"error_code"`
|
||||
Total int64 `json:"total"`
|
||||
Last24h int64 `json:"last_24h"`
|
||||
}
|
||||
|
||||
type BacklogStat struct {
|
||||
OwnerService string `json:"owner_service"`
|
||||
TaskType string `json:"task_type"`
|
||||
ModelProfile string `json:"model_profile"`
|
||||
Pending int64 `json:"pending"`
|
||||
Running int64 `json:"running"`
|
||||
StaleRunning int64 `json:"stale_running"`
|
||||
OldestPendingAgeSeconds int64 `json:"oldest_pending_age_seconds"`
|
||||
OldestRunningAgeSeconds int64 `json:"oldest_running_age_seconds"`
|
||||
}
|
||||
|
||||
func New(baseURL, token string, timeout time.Duration) *Client {
|
||||
baseURL = strings.TrimRight(strings.TrimSpace(baseURL), "/")
|
||||
if baseURL == "" {
|
||||
@@ -223,6 +258,29 @@ func (c *Client) ProvidersStatus(ctx context.Context) (*ProvidersStatus, error)
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *Client) Stats(ctx context.Context) (*Stats, error) {
|
||||
if c == nil {
|
||||
return nil, fmt.Errorf("ai-service not configured")
|
||||
}
|
||||
req, err := c.request(ctx, http.MethodGet, "/api/v1/stats", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ai stats: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||
return nil, fmt.Errorf("ai stats: http %d: %s", resp.StatusCode, readSmall(resp.Body))
|
||||
}
|
||||
var out Stats
|
||||
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil {
|
||||
return nil, fmt.Errorf("decode ai stats: %w", err)
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (c *Client) request(ctx context.Context, method, path string, body []byte) (*http.Request, error) {
|
||||
var r io.Reader
|
||||
if body != nil {
|
||||
|
||||
Reference in New Issue
Block a user