1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "net/http"
21 "time"
22 )
23
24
25
26
27 type SidekiqService struct {
28 client *Client
29 }
30
31
32
33
34
35 type QueueMetrics struct {
36 Queues map[string]struct {
37 Backlog int `json:"backlog"`
38 Latency int `json:"latency"`
39 } `json:"queues"`
40 }
41
42
43
44
45
46
47 func (s *SidekiqService) GetQueueMetrics(options ...RequestOptionFunc) (*QueueMetrics, *Response, error) {
48 req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/queue_metrics", nil, options)
49 if err != nil {
50 return nil, nil, err
51 }
52
53 q := new(QueueMetrics)
54 resp, err := s.client.Do(req, q)
55 if err != nil {
56 return nil, resp, err
57 }
58
59 return q, resp, nil
60 }
61
62
63
64
65
66 type ProcessMetrics struct {
67 Processes []struct {
68 Hostname string `json:"hostname"`
69 Pid int `json:"pid"`
70 Tag string `json:"tag"`
71 StartedAt *time.Time `json:"started_at"`
72 Queues []string `json:"queues"`
73 Labels []string `json:"labels"`
74 Concurrency int `json:"concurrency"`
75 Busy int `json:"busy"`
76 } `json:"processes"`
77 }
78
79
80
81
82
83
84 func (s *SidekiqService) GetProcessMetrics(options ...RequestOptionFunc) (*ProcessMetrics, *Response, error) {
85 req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/process_metrics", nil, options)
86 if err != nil {
87 return nil, nil, err
88 }
89
90 p := new(ProcessMetrics)
91 resp, err := s.client.Do(req, p)
92 if err != nil {
93 return nil, resp, err
94 }
95
96 return p, resp, nil
97 }
98
99
100
101
102
103 type JobStats struct {
104 Jobs struct {
105 Processed int `json:"processed"`
106 Failed int `json:"failed"`
107 Enqueued int `json:"enqueued"`
108 } `json:"jobs"`
109 }
110
111
112
113
114
115 func (s *SidekiqService) GetJobStats(options ...RequestOptionFunc) (*JobStats, *Response, error) {
116 req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/job_stats", nil, options)
117 if err != nil {
118 return nil, nil, err
119 }
120
121 j := new(JobStats)
122 resp, err := s.client.Do(req, j)
123 if err != nil {
124 return nil, resp, err
125 }
126
127 return j, resp, nil
128 }
129
130
131
132
133
134 type CompoundMetrics struct {
135 QueueMetrics
136 ProcessMetrics
137 JobStats
138 }
139
140
141
142
143
144 func (s *SidekiqService) GetCompoundMetrics(options ...RequestOptionFunc) (*CompoundMetrics, *Response, error) {
145 req, err := s.client.NewRequest(http.MethodGet, "/sidekiq/compound_metrics", nil, options)
146 if err != nil {
147 return nil, nil, err
148 }
149
150 c := new(CompoundMetrics)
151 resp, err := s.client.Do(req, c)
152 if err != nil {
153 return nil, resp, err
154 }
155
156 return c, resp, nil
157 }
158
View as plain text