forked from taylorchu/work
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetrics.go
46 lines (40 loc) · 1.02 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package work
import "time"
// QueueMetrics contains metrics from a queue.
type QueueMetrics struct {
Namespace string
QueueID string
// Total number of jobs that can be executed right now.
ReadyTotal int64
// Total number of jobs that are scheduled to run in future.
ScheduledTotal int64
// Processing delay from oldest ready job
Latency time.Duration
}
// MetricsExporter can be implemented by Queue to report metrics.
type MetricsExporter interface {
GetQueueMetrics(*QueueMetricsOptions) (*QueueMetrics, error)
}
// Metrics wraps metrics reported by MetricsExporter.
type Metrics struct {
Queue []*QueueMetrics
}
// QueueMetricsOptions specifies how to fetch queue metrics.
type QueueMetricsOptions struct {
Namespace string
QueueID string
At time.Time
}
// Validate validates QueueMetricsOptions.
func (opt *QueueMetricsOptions) Validate() error {
if opt.Namespace == "" {
return ErrEmptyNamespace
}
if opt.QueueID == "" {
return ErrEmptyQueueID
}
if opt.At.IsZero() {
return ErrAt
}
return nil
}