diff --git a/app/models/miq_schedule_worker/jobs.rb b/app/models/miq_schedule_worker/jobs.rb index a61f5182c3b..83c09876f49 100644 --- a/app/models/miq_schedule_worker/jobs.rb +++ b/app/models/miq_schedule_worker/jobs.rb @@ -16,6 +16,10 @@ def miq_server_worker_log_status queue_work(:class_name => "MiqWorker", :method_name => "log_status_all", :task_id => "log_status", :server_guid => MiqServer.my_guid, :priority => MiqQueue::HIGH_PRIORITY) end + def miq_server_audit_managed_resources + queue_work(:class_name => "MiqServer", :method_name => "audit_managed_resources", :task_id => "audit_managed_resources", :server_guid => MiqServer.my_guid) + end + def vmdb_database_connection_log_statistics queue_work(:class_name => "VmdbDatabaseConnection", :method_name => "log_statistics", :server_guid => MiqServer.my_guid) end diff --git a/app/models/miq_schedule_worker/runner.rb b/app/models/miq_schedule_worker/runner.rb index 14d7b816f09..2ef1d13a212 100644 --- a/app/models/miq_schedule_worker/runner.rb +++ b/app/models/miq_schedule_worker/runner.rb @@ -110,6 +110,11 @@ def schedules_for_all_roles ) { enqueue(:miq_server_queue_update_registration_status) } end + # Schedule - Add audit log entry for total number of vms managed by system. + scheduler.schedule_every( + worker_settings[:audit_managed_resources], + :tags =>[:miq_server_audit_managed_resources, schedule_category] + ) { enqueue(:miq_server_audit_managed_resources) } @schedules[:all] end diff --git a/app/models/miq_server.rb b/app/models/miq_server.rb index e819982ceaa..269251a4c90 100644 --- a/app/models/miq_server.rb +++ b/app/models/miq_server.rb @@ -487,6 +487,20 @@ def self.zone_is_modifiable? Zone.visible.in_my_region.count > 1 end + def self.audit_managed_resources + total_vms = 0 + total_hosts = 0 + + ExtManagementSystem.all.each do |e| + vms = e.all_vms_and_templates.count + hosts = e.all_hosts.count + total_vms += vms + total_hosts += hosts + end + totals = {"vms" => total_vms, "hosts" => total_hosts} + $audit_log.info("Under Management: #{totals.to_json}") + end + private def zone_unchanged_in_pods diff --git a/config/settings.yml b/config/settings.yml index b866025d1c4..00437dd4eb0 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1169,6 +1169,7 @@ :queue_timeout: 20.minutes :heartbeat_thread_shutdown_timeout: 10.seconds :schedule_worker: + :audit_managed_resources: 1.days :container_entities_purge_interval: 1.day :binary_blob_purge_interval: 1.hour :authentication_check_interval: 1.hour