|
| 1 | +package metrics |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/prometheus/client_golang/prometheus" |
| 5 | + "testing_system/common/connectors/masterconn" |
| 6 | +) |
| 7 | + |
| 8 | +const ( |
| 9 | + invokerLabel = "invoker" |
| 10 | + jobTypeLabel = "job_type" |
| 11 | +) |
| 12 | + |
| 13 | +type Collector struct { |
| 14 | + Registerer *prometheus.Registry |
| 15 | + |
| 16 | + InvokerJobResults *prometheus.CounterVec |
| 17 | + InvokerTestingWaitDuration *prometheus.CounterVec |
| 18 | + InvokerSandboxOccupationDuration *prometheus.CounterVec |
| 19 | + InvokerResourceWaitDuration *prometheus.CounterVec |
| 20 | + InvokerFileActionsDuration *prometheus.CounterVec |
| 21 | + InvokerExecutionWaitDuration *prometheus.CounterVec |
| 22 | + InvokerExecutionDuration *prometheus.CounterVec |
| 23 | + InvokerSendResultDuration *prometheus.CounterVec |
| 24 | +} |
| 25 | + |
| 26 | +func NewCollector() *Collector { |
| 27 | + c := &Collector{ |
| 28 | + Registerer: prometheus.NewRegistry(), |
| 29 | + } |
| 30 | + c.InvokerJobResults = c.createInvokerCounter( |
| 31 | + "job_results_count", |
| 32 | + "Number of job results received from invoker", |
| 33 | + ) |
| 34 | + |
| 35 | + c.InvokerTestingWaitDuration = c.createInvokerCounter( |
| 36 | + "testing_wait_duration_sum", |
| 37 | + "Time submission waits for testing in invoker", |
| 38 | + ) |
| 39 | + |
| 40 | + c.InvokerSandboxOccupationDuration = c.createInvokerCounter( |
| 41 | + "sandbox_occupation_duration_sum", |
| 42 | + "Total sandbox time for submission testing in invoker", |
| 43 | + ) |
| 44 | + |
| 45 | + c.InvokerResourceWaitDuration = c.createInvokerCounter( |
| 46 | + "resource_wait_duration_sum", |
| 47 | + "Total time spent waiting for resources for submissions to load in invokers", |
| 48 | + ) |
| 49 | + |
| 50 | + c.InvokerFileActionsDuration = c.createInvokerCounter( |
| 51 | + "file_actions_duration_sum", |
| 52 | + "Total time spent waiting for file copy to sandbox in invoker", |
| 53 | + ) |
| 54 | + |
| 55 | + c.InvokerExecutionWaitDuration = c.createInvokerCounter( |
| 56 | + "execution_wait_duration_sum", |
| 57 | + "Total time spent waiting for execution of process on invoker when sandbox is set up", |
| 58 | + ) |
| 59 | + |
| 60 | + c.InvokerExecutionDuration = c.createInvokerCounter( |
| 61 | + "execution_duration_sum", |
| 62 | + "Total time spent on executing processes in sandboxes", |
| 63 | + ) |
| 64 | + |
| 65 | + c.InvokerSendResultDuration = c.createInvokerCounter( |
| 66 | + "send_result_duration_sum", |
| 67 | + "Total time spent on sending results from invoker to storage", |
| 68 | + ) |
| 69 | + return c |
| 70 | +} |
| 71 | + |
| 72 | +func (c *Collector) createInvokerCounter( |
| 73 | + name string, |
| 74 | + help string, |
| 75 | +) *prometheus.CounterVec { |
| 76 | + counter := prometheus.NewCounterVec( |
| 77 | + prometheus.CounterOpts{ |
| 78 | + Namespace: "ts", |
| 79 | + Subsystem: "invoker", |
| 80 | + Name: name, |
| 81 | + Help: help, |
| 82 | + }, |
| 83 | + []string{invokerLabel, jobTypeLabel}, |
| 84 | + ) |
| 85 | + c.Registerer.MustRegister(counter) |
| 86 | + return counter |
| 87 | +} |
| 88 | + |
| 89 | +func (c *Collector) NewJobResult(result *masterconn.InvokerJobResult) { |
| 90 | + labels := prometheus.Labels{ |
| 91 | + invokerLabel: result.InvokerStatus.Address, |
| 92 | + jobTypeLabel: result.Job.Type.String(), |
| 93 | + } |
| 94 | + |
| 95 | + c.InvokerJobResults.With(labels).Inc() |
| 96 | + c.InvokerTestingWaitDuration.With(labels).Add(result.Metrics.TestingWaitDuration.Seconds()) |
| 97 | + c.InvokerSandboxOccupationDuration.With(labels).Add(result.Metrics.TotalSandboxOccupation.Seconds()) |
| 98 | + c.InvokerResourceWaitDuration.With(labels).Add(result.Metrics.ResourceWaitDuration.Seconds()) |
| 99 | + c.InvokerFileActionsDuration.With(labels).Add(result.Metrics.FileActionsDuration.Seconds()) |
| 100 | + c.InvokerExecutionWaitDuration.With(labels).Add(result.Metrics.ExecutionWaitDuration.Seconds()) |
| 101 | + c.InvokerExecutionDuration.With(labels).Add(result.Metrics.ExecutionDuration.Seconds()) |
| 102 | + c.InvokerSendResultDuration.With(labels).Add(result.Metrics.SendResultDuration.Seconds()) |
| 103 | +} |
0 commit comments