Class: Hatchet::Features::Metrics
- Inherits:
-
Object
- Object
- Hatchet::Features::Metrics
- Defined in:
- lib/hatchet/features/metrics.rb
Overview
Metrics client for reading metrics out of Hatchet’s metrics API
This class provides a high-level interface for retrieving queue metrics, Prometheus metrics, task statistics, and task metrics from the Hatchet system.
Instance Method Summary collapse
-
#get_queue_metrics ⇒ Hash
Retrieve the current queue metrics for the tenant.
-
#get_task_metrics(since: nil, until_time: nil, workflow_ids: nil, parent_task_external_id: nil, triggering_event_external_id: nil) ⇒ TaskMetrics
Retrieve task metrics grouped by status (queued, running, completed, failed, cancelled).
-
#get_task_stats ⇒ Object
Get task statistics for the tenant.
-
#initialize(rest_client, config) ⇒ void
constructor
Initializes a new Metrics client instance.
-
#scrape_tenant_prometheus_metrics ⇒ String
Scrape Prometheus metrics for the tenant.
Constructor Details
#initialize(rest_client, config) ⇒ void
Initializes a new Metrics client instance
32 33 34 35 36 37 |
# File 'lib/hatchet/features/metrics.rb', line 32 def initialize(rest_client, config) @rest_client = rest_client @config = config @task_api = HatchetSdkRest::TaskApi.new(rest_client) @tenant_api = HatchetSdkRest::TenantApi.new(rest_client) end |
Instance Method Details
#get_queue_metrics ⇒ Hash
Retrieve the current queue metrics for the tenant
45 46 47 48 |
# File 'lib/hatchet/features/metrics.rb', line 45 def get_queue_metrics result = @tenant_api.tenant_get_step_run_queue_metrics(@config.tenant_id) result.queues || {} end |
#get_task_metrics(since: nil, until_time: nil, workflow_ids: nil, parent_task_external_id: nil, triggering_event_external_id: nil) ⇒ TaskMetrics
Retrieve task metrics grouped by status (queued, running, completed, failed, cancelled)
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/hatchet/features/metrics.rb', line 85 def get_task_metrics(since: nil, until_time: nil, workflow_ids: nil, parent_task_external_id: nil, triggering_event_external_id: nil) since_time = since || (Time.now - (24 * 60 * 60)) until_val = until_time || Time.now result = @task_api.v1_task_list_status_metrics( @config.tenant_id, since_time.utc.iso8601, { _until: until_val.utc.iso8601, workflow_ids: workflow_ids, parent_task_external_id: parent_task_external_id, triggering_event_external_id: triggering_event_external_id, }, ) # Build metrics hash from the status metric objects metrics = { cancelled: 0, completed: 0, failed: 0, queued: 0, running: 0 } if result.is_a?(Array) result.each do |m| status_name = m.respond_to?(:status) ? m.status.to_s.downcase.to_sym : nil count = m.respond_to?(:count) ? m.count : 0 metrics[status_name] = count if metrics.key?(status_name) end end TaskMetrics.new(**metrics) end |
#get_task_stats ⇒ Object
Get task statistics for the tenant
66 67 68 |
# File 'lib/hatchet/features/metrics.rb', line 66 def get_task_stats @tenant_api.tenant_get_task_stats(@config.tenant_id) end |
#scrape_tenant_prometheus_metrics ⇒ String
Scrape Prometheus metrics for the tenant
56 57 58 |
# File 'lib/hatchet/features/metrics.rb', line 56 def scrape_tenant_prometheus_metrics @tenant_api.tenant_get_prometheus_metrics(@config.tenant_id) end |