Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
class Async::Service::Supervisor::UtilizationMonitor
Metrics::Provider(self) do
UTILIZATION = Metrics.metric("async.utilization", :gauge, description: "Active requests per worker.")
UTILIZATION_CONNECTIONS_ACTIVE = Metrics.metric("async.utilization.connections.active", :gauge, description: "The number of active connections.")
UTILIZATION_CONNECTIONS_TOTAL = Metrics.metric("async.utilization.connections.total", :gauge, description: "The total number of connections.")
UTILIZATION_REQUESTS_ACTIVE = Metrics.metric("async.utilization.requests.active", :gauge, description: "The number of active requests.")
UTILIZATION_REQUESTS_TOTAL = Metrics.metric("async.utilization.requests.total", :gauge, description: "The total number of requests.")
UTILIZATION_WORKERS = Metrics.metric("async.utilization.workers", :gauge, description: "The number of workers contributing utilization metrics.")
UTILIZATION_CONNECTIONS_ACTIVE = Metrics.metric("async.utilization.connections_active", :gauge, description: "The number of active connections.")
UTILIZATION_CONNECTIONS_TOTAL = Metrics.metric("async.utilization.connections_total", :gauge, description: "The total number of connections.")
UTILIZATION_REQUESTS_ACTIVE = Metrics.metric("async.utilization.requests_active", :gauge, description: "The number of active requests.")
UTILIZATION_REQUESTS_TOTAL = Metrics.metric("async.utilization.requests_total", :gauge, description: "The total number of requests.")
UTILIZATION_WORKER_COUNT = Metrics.metric("async.utilization.worker_count", :gauge, description: "The number of workers contributing utilization metrics.")

def emit(metrics)
metrics.each do |service_name, fields|
Expand All @@ -38,7 +38,7 @@ def emit(metrics)
end

if worker_count = fields[:worker_count]
UTILIZATION_WORKERS.emit(worker_count, tags: tags)
UTILIZATION_WORKER_COUNT.emit(worker_count, tags: tags)

if worker_count > 0 and requests_active = fields[:requests_active]
UTILIZATION.emit(requests_active.to_f / worker_count, tags: tags)
Expand Down
23 changes: 17 additions & 6 deletions test/metrics/provider/async/service/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def metric(owner, name)
it "scopes metric constants to the instrumented classes" do
expect(Object.const_defined?(:PROCESS_METRICS_GENERAL_PROCESSOR_UTILIZATION, false)).to be == false
expect(Object.const_defined?(:UTILIZATION, false)).to be == false
expect(Object.const_defined?(:UTILIZATION_WORKERS, false)).to be == false
expect(Object.const_defined?(:UTILIZATION_WORKER_COUNT, false)).to be == false

expect(Async::Service::Supervisor::ProcessMonitor.const_defined?(:PROCESS_METRICS_GENERAL_PROCESSOR_UTILIZATION, false)).to be == true
expect(Async::Service::Supervisor::UtilizationMonitor.const_defined?(:UTILIZATION, false)).to be == true
expect(Async::Service::Supervisor::UtilizationMonitor.const_defined?(:UTILIZATION_WORKERS, false)).to be == true
expect(Async::Service::Supervisor::UtilizationMonitor.const_defined?(:UTILIZATION_WORKER_COUNT, false)).to be == true
end

it "defines process monitor metrics" do
Expand Down Expand Up @@ -53,10 +53,21 @@ def metric(owner, name)
end

it "defines utilization monitor metrics" do
metric = metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION)
metrics = {
UTILIZATION: "async.utilization",
UTILIZATION_CONNECTIONS_ACTIVE: "async.utilization.connections_active",
UTILIZATION_CONNECTIONS_TOTAL: "async.utilization.connections_total",
UTILIZATION_REQUESTS_ACTIVE: "async.utilization.requests_active",
UTILIZATION_REQUESTS_TOTAL: "async.utilization.requests_total",
UTILIZATION_WORKER_COUNT: "async.utilization.worker_count",
}

expect(metric.name).to be == "async.utilization"
expect(metric.type).to be == :gauge
metrics.each do |constant, name|
metric = metric(Async::Service::Supervisor::UtilizationMonitor, constant)

expect(metric.name).to be == name
expect(metric.type).to be == :gauge
end
end

it "emits utilization monitor metrics" do
Expand All @@ -67,7 +78,7 @@ def metric(owner, name)
expect(metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION_CONNECTIONS_TOTAL)).to receive(:emit).with(10, tags: tags).once
expect(metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION_REQUESTS_ACTIVE)).to receive(:emit).with(2, tags: tags).once
expect(metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION_REQUESTS_TOTAL)).to receive(:emit).with(6, tags: tags).once
expect(metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION_WORKERS)).to receive(:emit).with(2, tags: tags).once
expect(metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION_WORKER_COUNT)).to receive(:emit).with(2, tags: tags).once
expect(metric(Async::Service::Supervisor::UtilizationMonitor, :UTILIZATION)).to receive(:emit).with(1.0, tags: tags).once

monitor.emit(
Expand Down
Loading