-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathset-miq-metric.rb
executable file
·85 lines (73 loc) · 2.6 KB
/
set-miq-metric.rb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env ruby
# Load Rails
ENV['RAILS_ENV'] = ARGV[0] || 'development'
begin
require './manageiq/config/environment'
rescue LoadError
DIR = File.dirname(__FILE__)
require DIR + '/../manageiq/config/environment'
end
# --------------------
# functions and consts
# --------------------
def push_metric (prov, timestamp, interval = "daily")
prov.metric_rollups << MetricRollup.create(
:capture_interval_name => interval,
:timestamp => timestamp,
:time_profile => TimeProfile.first,
:cpu_usage_rate_average => rand(100),
:mem_usage_absolute_average => rand(100),
:derived_vm_numvcpus => 4,
:net_usage_rate_average => rand(1000),
:derived_memory_available => 8192,
:derived_memory_used => rand(8192),
:stat_container_group_create_rate => rand(100),
:stat_container_group_delete_rate => rand(50),
:stat_container_image_registration_rate => rand(25)
)
end
def push_nodes_metric (prov, timestamp)
prov.container_nodes.each do |node|
node.metric_rollups << MetricRollup.create(
:capture_interval_name => "hourly",
:timestamp => timestamp,
:cpu_usage_rate_average => rand(100),
:mem_usage_absolute_average => rand(100),
:derived_vm_numvcpus => 4,
:net_usage_rate_average => rand(1000),
:derived_memory_available => 8192,
:derived_memory_used => rand(8192))
end
end
def push_container_metric (prov, timestamp)
prov.containers.each do |node|
node.metric_rollups << MetricRollup.create(
:capture_interval_name => "hourly",
:timestamp => timestamp,
:cpu_usage_rate_average => rand(100),
:mem_usage_absolute_average => rand(100),
:derived_vm_numvcpus => 4,
:net_usage_rate_average => rand(1000),
:derived_memory_available => 8192,
:derived_memory_used => rand(8192))
end
end
def push_last_30_days(prov)
(0 .. 30).each { |x| push_metric(prov, x.days.ago, "daily") }
end
def push_last_24_hours(prov)
(0 .. 24).each { |x| push_metric(prov, x.hours.ago, "hourly") }
(0 .. 24).each { |x| push_nodes_metric(prov, x.hours.ago) }
(0 .. 24).each { |x| push_container_metric(prov, x.hours.ago) }
end
# --------------------
# push metric data
# --------------------
ManageIQ::Providers::ContainerManager.all.each do |prov|
push_last_30_days(prov)
push_last_24_hours(prov)
end
ContainerProject.all.each do |prov|
push_last_30_days(prov)
push_last_24_hours(prov)
end