opstat-plugins 0.3.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +17 -0
  4. data/LICENSE +675 -0
  5. data/lib/app/models/apache2.rb +192 -0
  6. data/lib/app/models/bsdnet/bytes_in_out.rb +54 -0
  7. data/lib/app/models/bsdnet/current_entries.rb +34 -0
  8. data/lib/app/models/bsdnet.rb +12 -0
  9. data/lib/app/models/cpu.rb +86 -0
  10. data/lib/app/models/disk.rb +51 -0
  11. data/lib/app/models/disk_io.rb +53 -0
  12. data/lib/app/models/facts.rb +30 -0
  13. data/lib/app/models/fpm.rb +138 -0
  14. data/lib/app/models/haproxy.rb +57 -0
  15. data/lib/app/models/jvm.rb +51 -0
  16. data/lib/app/models/load.rb +99 -0
  17. data/lib/app/models/memory.rb +55 -0
  18. data/lib/app/models/nagios.rb +51 -0
  19. data/lib/app/models/network.rb +58 -0
  20. data/lib/app/models/oracle_fras_sizes.rb +41 -0
  21. data/lib/app/models/oracle_sessions.rb +43 -0
  22. data/lib/app/models/oracle_tablespaces_sizes.rb +51 -0
  23. data/lib/app/models/temper.rb +51 -0
  24. data/lib/app/models/webobjects.rb +83 -0
  25. data/lib/app/models/xen.rb +99 -0
  26. data/lib/data/hp_pdu.yml +191 -0
  27. data/lib/logging.rb +29 -0
  28. data/lib/opstat-plugins.rb +44 -0
  29. data/lib/parsers/apache2.rb +19 -0
  30. data/lib/parsers/bsdnet.rb +29 -0
  31. data/lib/parsers/cpu.rb +42 -0
  32. data/lib/parsers/disk.rb +49 -0
  33. data/lib/parsers/facts.rb +12 -0
  34. data/lib/parsers/fpm.rb +31 -0
  35. data/lib/parsers/freeswitch_fifos.rb +63 -0
  36. data/lib/parsers/haproxy.rb +34 -0
  37. data/lib/parsers/haproxy_tables.rb +25 -0
  38. data/lib/parsers/hp_pdu.rb +36 -0
  39. data/lib/parsers/jvm.rb +22 -0
  40. data/lib/parsers/load.rb +20 -0
  41. data/lib/parsers/memory.rb +29 -0
  42. data/lib/parsers/nagios.rb +39 -0
  43. data/lib/parsers/network.rb +37 -0
  44. data/lib/parsers/oracle_fras_sizes.rb +25 -0
  45. data/lib/parsers/oracle_sessions.rb +20 -0
  46. data/lib/parsers/oracle_tablespaces_sizes.rb +22 -0
  47. data/lib/parsers/temper.rb +17 -0
  48. data/lib/parsers/webobjects.rb +33 -0
  49. data/lib/parsers/xen.rb +39 -0
  50. data/lib/plugins/apache2.rb +76 -0
  51. data/lib/plugins/bsdnet.rb +13 -0
  52. data/lib/plugins/cpu.rb +13 -0
  53. data/lib/plugins/custom_sql_statement.rb +24 -0
  54. data/lib/plugins/disk.rb +31 -0
  55. data/lib/plugins/facts.rb +30 -0
  56. data/lib/plugins/fpm.rb +33 -0
  57. data/lib/plugins/freeswitch_fifos.rb +27 -0
  58. data/lib/plugins/haproxy.rb +24 -0
  59. data/lib/plugins/haproxy_tables.rb +28 -0
  60. data/lib/plugins/hp_pdu.rb +28 -0
  61. data/lib/plugins/jvm.rb +23 -0
  62. data/lib/plugins/load.rb +20 -0
  63. data/lib/plugins/memory.rb +18 -0
  64. data/lib/plugins/nagios.rb +39 -0
  65. data/lib/plugins/network.rb +21 -0
  66. data/lib/plugins/oracle_fras_sizes.rb +48 -0
  67. data/lib/plugins/oracle_sessions.rb +47 -0
  68. data/lib/plugins/oracle_tablespaces_sizes.rb +59 -0
  69. data/lib/plugins/temper.rb +21 -0
  70. data/lib/plugins/webobjects.rb +42 -0
  71. data/lib/plugins/xen.rb +22 -0
  72. data/opstat-plugins.gemspec +20 -0
  73. data/spec/cpu_spec.rb +39 -0
  74. data/spec/disk_io_spec.rb +31 -0
  75. data/spec/disk_spec.rb +31 -0
  76. data/spec/fixtures/parser_cpu_16_core.txt +24 -0
  77. data/spec/fixtures/parser_cpu_16_core_corrupted.txt +24 -0
  78. data/spec/fixtures/parser_cpu_single_core.txt +10 -0
  79. data/spec/fixtures/parser_cpu_single_core_corrupted.txt +9 -0
  80. data/spec/fixtures/parser_disk_3_mounts.txt +9 -0
  81. data/spec/fixtures/parser_disk_corrupted.txt +9 -0
  82. data/spec/fixtures/parser_disk_io.txt +2 -0
  83. data/spec/fixtures/parser_disk_io_corrupted.txt +2 -0
  84. data/spec/fixtures/parser_haproxy_correct.txt +2 -0
  85. data/spec/fixtures/parser_haproxy_corrupted.txt +2 -0
  86. data/spec/fixtures/parser_haproxy_many_frontend_many_backend.txt +6 -0
  87. data/spec/fixtures/parser_haproxy_single_frontend_single_backend_with_single_svname.txt +5 -0
  88. data/spec/fixtures/parser_load.txt +1 -0
  89. data/spec/fixtures/parser_load_corrupted.txt +2 -0
  90. data/spec/fixtures/parser_memory.txt +43 -0
  91. data/spec/fixtures/parser_memory_corrupted.txt +43 -0
  92. data/spec/fixtures/parser_network.txt +5 -0
  93. data/spec/fixtures/parser_network_corrupted.txt +5 -0
  94. data/spec/fixtures/parser_webobjects_many_apps_many_instances.result.yml +590 -0
  95. data/spec/fixtures/parser_webobjects_many_apps_many_instances.txt +2 -0
  96. data/spec/fixtures/parser_webobjects_one_app_many_instances.result.yml +305 -0
  97. data/spec/fixtures/parser_webobjects_one_app_many_instances.txt +395 -0
  98. data/spec/haproxy_spec.rb +68 -0
  99. data/spec/load_spec.rb +21 -0
  100. data/spec/memory_spec.rb +21 -0
  101. data/spec/network_spec.rb +21 -0
  102. data/spec/spec_helper.rb +102 -0
  103. data/spec/webobjects_spec.rb +28 -0
  104. metadata +189 -0
@@ -0,0 +1,192 @@
1
+ class Apache2
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::AreaStackedChart
6
+ store_in collection: "opstat.reports"
7
+ field :timestamp, type: DateTime
8
+ index({timestamp: 1, host_id: 1, plugin_id: 1},{background: true})
9
+
10
+ def self.chart_data(options = {})
11
+ charts = []
12
+ charts = self.all_vhosts_charts(options)
13
+ return charts
14
+ end
15
+
16
+ def self.all_vhosts_charts(options)
17
+ charts = []
18
+ stats = Apache2.where( {:timestamp => { :$gte => options[:start],:$lt => options[:end]}, :host_id => options[:host_id], :plugin_id => options[:plugin_id] }).order(:timestamp).all.group_by{|v| v.vhost_name}
19
+ charts = self.vhosts_requests_and_bytes_per_sec(stats)
20
+ return charts
21
+ end
22
+
23
+ def self.vhosts_requests_and_bytes_per_sec(stats)
24
+ charts = []
25
+ stats.each_pair do |vhost,data|
26
+ chart_bytes = self.chart_structure({:title => "Bytes sent per second for #{vhost} vhost", :value_axis => { :title => "Bytes sent per second"}})
27
+ chart_requests = self.chart_structure({:title => "Request sent per second for #{vhost} vhost", :value_axis => { :title => "request sent per second"}})
28
+
29
+ prev = {}
30
+ statuses = {}
31
+ data.each do |vhost_data|
32
+ current = {:bytes_sent_per_sec => {}, :requests_per_sec => {}}
33
+ current[:bytes_sent_per_sec]['timestamp'] = vhost_data['timestamp'].to_f * 1000
34
+ statuses.keys.each do |s|
35
+ current[:bytes_sent_per_sec][s] = 0
36
+ end
37
+ current[:requests_per_sec]['timestamp'] = vhost_data['timestamp'].to_f * 1000
38
+ statuses.keys.each do |s|
39
+ current[:requests_per_sec][s] = 0
40
+ end
41
+ vhost_data['stats'].each_pair do |status, values|
42
+ statuses[status] = true
43
+ unless prev.has_key?(status) then
44
+ prev[status] = values
45
+ prev[status]['timestamp'] = vhost_data['timestamp']
46
+ next
47
+ end
48
+
49
+ time_diff = vhost_data['timestamp'].to_i - prev[status]['timestamp'].to_i
50
+ bytes_sent_per_sec = ((values["bytes_sent"] - prev[status]['bytes_sent'])/time_diff.to_f).round(3)
51
+ requests_per_sec = ((values['requests'] - prev[status]['requests'])/time_diff.to_f).round(3)
52
+ #TODO Interpolation of no data intervals
53
+ #TODO take into account requests also
54
+ if bytes_sent_per_sec < 0
55
+ prev[status] = values
56
+ prev[status]['timestamp'] = vhost_data['timestamp']
57
+ next
58
+ end
59
+
60
+ current[:bytes_sent_per_sec][status] = bytes_sent_per_sec.to_f
61
+ current[:requests_per_sec][status] = requests_per_sec.to_f
62
+ prev[status] = values
63
+ prev[status]['timestamp'] = vhost_data['timestamp']
64
+ end
65
+ chart_requests[:graph_data] << current[:requests_per_sec]
66
+ chart_bytes[:graph_data] << current[:bytes_sent_per_sec]
67
+ end
68
+ statuses.keys.sort.each do |status|
69
+ properties = self.statuses_properties.select{|a| a[:value_field] == status.to_s}.first
70
+ p status
71
+ chart_requests[:graphs] << { :value_axis => 'valueAxis1', :value_field => status.to_s, :line_color => properties[:line_color], :balloon_text => "[[title]]: ([[value]])", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line' }
72
+ chart_bytes[:graphs] << { :value_axis => 'valueAxis1', :value_field => status.to_s, :line_color => properties[:line_color], :balloon_text => "[[title]]: ([[value]])", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line' }
73
+ end
74
+ charts << chart_bytes << chart_requests
75
+ end
76
+ charts
77
+ end
78
+
79
+ def self.statuses_properties
80
+ [
81
+ { :value_field => "200",
82
+ :hidden => false,
83
+ :line_color => "#00FF00",
84
+ :line_thickness => 3,
85
+ :title => "Status 200"},
86
+ { :value_field => "202",
87
+ :hidden => false,
88
+ :line_color => "#00FF33",
89
+ :line_thickness => 3,
90
+ :title => "Status 202"},
91
+ { :value_field => "204",
92
+ :hidden => false,
93
+ :line_color => "#00FF66",
94
+ :line_thickness => 3,
95
+ :title => "Status 204"},
96
+ { :value_field => "206",
97
+ :hidden => false,
98
+ :line_color => "#00FF88",
99
+ :line_thickness => 3,
100
+ :title => "Status 206"},
101
+ { :value_field => "300",
102
+ :hidden => false,
103
+ :line_color => "#FFFF00",
104
+ :line_thickness => 3,
105
+ :title => "Status 301"},
106
+ { :value_field => "301",
107
+ :hidden => false,
108
+ :line_color => "#FFEE00",
109
+ :line_thickness => 3,
110
+ :title => "Status 300"},
111
+ { :value_field => "302",
112
+ :hidden => false,
113
+ :line_color => "#FFDD00",
114
+ :line_thickness => 3,
115
+ :title => "Status 302"},
116
+ { :value_field => "303",
117
+ :hidden => false,
118
+ :line_color => "#FFAA00",
119
+ :line_thickness => 3,
120
+ :title => "Status 303"},
121
+ { :value_field => "304",
122
+ :hidden => false,
123
+ :line_color => "#FF9900",
124
+ :line_thickness => 3,
125
+ :title => "Status 304"},
126
+ { :value_field => "400",
127
+ :hidden => false,
128
+ :line_color => "#FF8800",
129
+ :line_thickness => 3,
130
+ :title => "Status 400"},
131
+ { :value_field => "403",
132
+ :hidden => false,
133
+ :line_color => "#FF6600",
134
+ :line_thickness => 3,
135
+ :title => "Status 403"},
136
+ { :value_field => "404",
137
+ :hidden => false,
138
+ :line_color => "#FF4400",
139
+ :line_thickness => 3,
140
+ :title => "Status 404"},
141
+ { :value_field => "405",
142
+ :hidden => false,
143
+ :line_color => "#EE0000",
144
+ :line_thickness => 3,
145
+ :title => "Status 405"},
146
+ { :value_field => "406",
147
+ :hidden => false,
148
+ :line_color => "#CC0000",
149
+ :line_thickness => 3,
150
+ :title => "Status 406"},
151
+ { :value_field => "407",
152
+ :hidden => false,
153
+ :line_color => "#BB0000",
154
+ :line_thickness => 3,
155
+ :title => "Status 407"},
156
+ { :value_field => "408",
157
+ :hidden => false,
158
+ :line_color => "#AA0000",
159
+ :line_thickness => 3,
160
+ :title => "Status 408"},
161
+ { :value_field => "420",
162
+ :hidden => false,
163
+ :line_color => "#550000",
164
+ :line_thickness => 3,
165
+ :title => "Status 420"},
166
+ { :value_field => "500",
167
+ :hidden => false,
168
+ :line_color => "#FF0000",
169
+ :line_thickness => 3,
170
+ :title => "Status 500"},
171
+ { :value_field => "501",
172
+ :hidden => false,
173
+ :line_color => "#FF2200",
174
+ :line_thickness => 3,
175
+ :title => "Status 501"},
176
+ { :value_field => "502",
177
+ :hidden => false,
178
+ :line_color => "#FF4400",
179
+ :line_thickness => 3,
180
+ :title => "Status 502"},
181
+ { :value_field => "503",
182
+ :hidden => false,
183
+ :line_color => "#FF6600",
184
+ :line_thickness => 3,
185
+ :title => "Status 503"}
186
+ ]
187
+ end
188
+
189
+ def self.graphs
190
+ {}
191
+ end
192
+ end
@@ -0,0 +1,54 @@
1
+ class Bsdnet
2
+ class BytesInOut
3
+ include Mongoid::Document
4
+ include Mongoid::Attributes::Dynamic
5
+ include Mongoid::Timestamps
6
+ include Graphs::AreaNotStackedChart
7
+ store_in collection: "opstat.reports"
8
+ field :timestamp, type: DateTime
9
+ index({timestamp: 1, host_id: 1, plugin_id: 1},{background: true})
10
+
11
+ def self.chart_data(options = {})
12
+ charts = []
13
+ options[:interface] = 'vlan254'
14
+ charts << self.bytes_chart(options)
15
+ #TODO interfaces??
16
+ return charts
17
+ end
18
+
19
+ def self.bytes_chart(options)
20
+ chart = self.chart_structure({:title => "Network traffic in/out", :value_axis => { :title => "Network traffic [Bytes]"}})
21
+ #TODO - sort by date
22
+ values = Bsdnet::BytesInOut.where(:timestamp.gte => options[:start]).
23
+ where(:timestamp.lt => options[:end]).
24
+ where(:host_id => options[:host_id]).
25
+ where(:plugin_id => options[:plugin_id]).
26
+ order(timestamp: :asc)
27
+ prev = nil
28
+ values.each do |data|
29
+ if prev.nil?
30
+ prev = data
31
+ next
32
+ end
33
+ bytes_in_per_sec = (data[:bytes_in_v4] - prev[:bytes_in_v4])/(data[:timestamp] - prev[:timestamp])
34
+ bytes_out_per_sec = (data[:bytes_out_v4] - prev[:bytes_out_v4])/(data[:timestamp] - prev[:timestamp])
35
+ chart[:graph_data] << {
36
+ :timestamp => data[:timestamp],
37
+ :bytes_out => bytes_out_per_sec.to_i,
38
+ :bytes_in => bytes_in_per_sec.to_i
39
+ }
40
+ prev = data
41
+ end
42
+
43
+ chart
44
+ end
45
+
46
+ def self.graphs
47
+ {
48
+ :bytes_in => { :line_color => '#FF3300' },
49
+ :bytes_out => {:line_color => '#00FF00' }
50
+ }
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,34 @@
1
+ class Bsdnet
2
+ class CurrentEntries
3
+ include Mongoid::Document
4
+ include Mongoid::Attributes::Dynamic
5
+ include Mongoid::Timestamps
6
+ include Graphs::AreaNotStackedChart
7
+ store_in collection: "opstat.reports"
8
+ field :timestamp, type: DateTime
9
+
10
+ def self.chart_data(options = {})
11
+ charts = []
12
+ options[:interface] = 'vlan254'
13
+ charts << self.entries_chart(options)
14
+ return charts
15
+ end
16
+
17
+ def self.entries_chart(options)
18
+ chart = self.chart_structure({:title => "Network current entries", :value_axis => { :title => "Network entries []"}})
19
+ values = Bsdnet::CurrentEntries.where(:timestamp.gte => options[:start]).
20
+ where(:timestamp.lt => options[:end]).
21
+ where(:host_id => options[:host_id]).
22
+ where(:plugin_id => options[:plugin_id]).
23
+ order(timestamp: :asc)
24
+ chart[:graph_data] = values
25
+ chart
26
+ end
27
+
28
+ def self.graphs
29
+ {
30
+ :current_entries => { :line_color => '#FF3300' },
31
+ }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,12 @@
1
+ pwd = File.dirname(File.expand_path(__FILE__))
2
+ require "#{pwd}/bsdnet/bytes_in_out.rb"
3
+ require "#{pwd}/bsdnet/current_entries.rb"
4
+
5
+ class Bsdnet
6
+ def self.chart_data(options = {})
7
+ charts = []
8
+ charts += Bsdnet::BytesInOut.chart_data(options)
9
+ charts += Bsdnet::CurrentEntries.chart_data(options)
10
+ return charts
11
+ end
12
+ end
@@ -0,0 +1,86 @@
1
+ class Cpu
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ store_in collection: "opstat.reports"
6
+ index({timestamp: 1, host_id: 1, plugin_id: 1},{background: true})
7
+
8
+ def self.chart_data(options = {})
9
+ charts = []
10
+ charts << self.cpu_chart(options)
11
+ return charts
12
+ end
13
+
14
+ def self.cpu_chart(options)
15
+ cpu_utilization = {
16
+ :value_axes => [
17
+ {
18
+ :name => "valueAxis1",
19
+ :title => 'Cpu utilization in %',
20
+ :position => 'left',
21
+ :min_max_multiplier => 1,
22
+ :stack_type => '100%',
23
+ :include_guides_in_min_max => 'true',
24
+ :grid_alpha => 0.1
25
+ }
26
+ ],
27
+ :graph_data => [],
28
+ :category_field => 'timestamp',
29
+ :graphs => [],
30
+ :title => "Host CPU usage",
31
+ :title_size => 20
32
+ }
33
+
34
+ #CHOOSE HERE which
35
+ # TODO ADD ALL TYPES
36
+ graphs = {
37
+ 'system' => { :value_axis => 'valueAxis1', :line_color => "#FF0000", :balloon_text => "[[title]]: ([[percents]]%)", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line' },
38
+ 'nice' => { :line_color => '#FF3300' },
39
+ 'user' => { :line_color => '#FF7700' },
40
+ 'iowait' => { :line_color => '#FFaa00' },
41
+ 'irq' => { :line_color => '#FFdd00' },
42
+ 'softirq' => { :line_color => '#FFFF00' },
43
+ 'idle' => {:line_color => '#00FF00' }
44
+ }
45
+ prev = nil
46
+ self.cpu_aggregate(options).each do |data|
47
+ if prev.nil? then
48
+ prev = data
49
+ next
50
+ end
51
+ temp = {"timestamp" => data[:timestamp]}
52
+ graphs.each_key {|g| temp[g] = data[g] - prev[g]}
53
+ cpu_utilization[:graph_data] << temp
54
+ prev = data
55
+ end
56
+
57
+ graphs.each_pair do |graph, properties|
58
+ #TODO value_axis
59
+ #TODO merge set values with default
60
+ cpu_utilization[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :line_color => properties[:line_color], :balloon_text => "[[title]]: ([[percents]]%)", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line', :title => graph}
61
+ end
62
+ cpu_utilization
63
+ end
64
+
65
+ def self.cpu_detailed(options)
66
+ end
67
+
68
+ def self.cpu_aggregate(options)
69
+ #data = Cpu.where( { :timestamp => {:$gte => options[:start],:$lt => options[:end]} , :cpu_id => 'cpu', :host_id => options[:host_id], :plugin_id => options[:plugin_id]} ).order_by(timestamp: asc).all
70
+
71
+ data = Cpu.where( :timestamp.gte => options[:start]).
72
+ where( :timestamp.lt => options[:end]).
73
+ where( :cpu_id => 'cpu').
74
+ where( :host_id => options[:host_id]).
75
+ where( :plugin_id => options[:plugin_id] ).order_by(timestamp: :asc)
76
+ data
77
+ end
78
+
79
+ def self.graphs_defaults
80
+ []
81
+ end
82
+
83
+ def self.axes_defaults
84
+ []
85
+ end
86
+ end
@@ -0,0 +1,51 @@
1
+ class Disk
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::AreaStackedChart
6
+ store_in collection: "opstat.reports"
7
+ field :timestamp, type: DateTime
8
+ index({timestamp: 1, host_id: 1, plugin_id: 1})
9
+
10
+ def self.chart_data(options = {})
11
+ charts = []
12
+ charts = self.all_disks_charts(options)
13
+ return charts
14
+ end
15
+
16
+ def self.all_disks_charts(options)
17
+ charts = []
18
+ Disk.where(:timestamp.gte => options[:start]).
19
+ where(:timestamp.lt => options[:end]).
20
+ where(:host_id => options[:host_id]).
21
+ where(:plugin_id => options[:plugin_id]).
22
+ order_by(timestamp: :asc).group_by{|u| u.mount}.each_pair do |mount, values|
23
+ charts << self.disk_chart(mount, values)
24
+ end
25
+ return charts
26
+ end
27
+
28
+ def self.disk_chart(mount, values)
29
+ chart = self.chart_structure({:title => "Disk space usage for #{mount}", :value_axis => { :title => "Disk usage in KB"}})
30
+ #TODO - get fields from above DRY
31
+ chart[:graph_data] = values
32
+ chart
33
+ end
34
+
35
+ def self.graphs
36
+ {
37
+ :block_used => {
38
+ :hidden => false,
39
+ :line_color => "#FF0000",
40
+ :line_thickness => 3,
41
+ :title => "block used"
42
+ },
43
+ :block_free => {
44
+ :hidden => false,
45
+ :line_color => "#00FF00",
46
+ :line_thickness => 3,
47
+ :title => "block free"
48
+ }
49
+ }
50
+ end
51
+ end
@@ -0,0 +1,53 @@
1
+ class DiskIo
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::LineChart
6
+ store_in collection: "opstat.reports"
7
+ field :timestamp, type: DateTime
8
+ index({timestamp: 1, hostname: 1, ip_address: 1},{background: true})
9
+
10
+ def self.chart_data(options = {})
11
+ charts = []
12
+ charts << self.disk_io_charts(options)
13
+ return charts
14
+ end
15
+
16
+ def self.disk_io_charts(options)
17
+ chart = self.chart_structure({:title => "Host load average", :value_axis => { :title => "Memory size in KB"},:include_guides_in_min_max => false})
18
+
19
+ #CHOOSE HERE which
20
+ # TODO ADD ALL TYPES
21
+ #TODO ADD GUIDES - if num of cores from facter
22
+ graphs = [ :load_1m, :load_5m, :load_15m ]
23
+
24
+ #TODO cpu and here - sort by timestamp
25
+ chart[:graph_data] = DiskIo.where(:timestamp.gte => options[:start]).
26
+ where(:timestamp.lt => options[:end]).
27
+ where(:host_id => options[:host_id]).
28
+ where(:plugin_id => options[:plugin_id]).
29
+ order(timestamp: :asc)
30
+
31
+ chart
32
+ end
33
+
34
+ def self.graphs
35
+ {
36
+ :load_15m => {
37
+ :hidden => false,
38
+ :line_color => "#FF0000",
39
+ :line_thickness => 3,
40
+ :title => "Load 15 minutes average"},
41
+ :load_5m => {
42
+ :hidden => false,
43
+ :line_color => "#FFFF00",
44
+ :line_thickness => 2,
45
+ :title => "Load 5 minutes average"},
46
+ :load_1m => {
47
+ :hidden => false,
48
+ :line_color => "#FFaa00",
49
+ :line_thickness => 1,
50
+ :title => "Load 1 minute average"}
51
+ }
52
+ end
53
+ end
@@ -0,0 +1,30 @@
1
+ class Facts
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ store_in collection: "opstat.reports"
6
+ field :timestamp, type: DateTime
7
+ index({timestamp: 1, host_id: 1, plugin_id: 1, plugin_type: 1}, {background: true})
8
+ index({host_id: 1, plugin_id: 1},{background: true})
9
+
10
+
11
+ def self.chart_data(options = {})
12
+ facter_data = {}
13
+ self.where(:timestamp.gte => options[:start]).
14
+ where(:ip_address => options[:ip_address]).
15
+ where(:hostname => options[:hostname]).order_by(timestamp: :asc).each do |data|
16
+ facter_data[data[:name]] ||= data[:value]
17
+ end
18
+ { :facter_data => facter_data }
19
+ end
20
+
21
+ def self.get_latest_facts_for_host(host_id)
22
+ Facts.where(:host_id => host_id)
23
+ where(:plugin_type => 'facts').
24
+ last
25
+ end
26
+
27
+ def self.legend
28
+ @legend = {}
29
+ end
30
+ end
@@ -0,0 +1,138 @@
1
+ class Fpm
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ store_in collection: "opstat.reports"
6
+ field :timestamp, type: DateTime
7
+
8
+ def self.chart_data(options = {})
9
+ charts = self.fpms_charts(options)
10
+ return charts
11
+ end
12
+
13
+ def self.fpms_charts(options = {})
14
+ charts = []
15
+ Fpm.where(:timestamp.gte => options[:start]).
16
+ where(:timestamp.lt => options[:end]).
17
+ where(:host_id => options[:host_id]).
18
+ where(:plugin_id => options[:plugin_id]).
19
+ order_by(timestamp: :asc).group_by{|u| u.pool}.each_pair do |pool, values|
20
+ charts << self.fpm_chart(pool,values)
21
+ end
22
+ return charts
23
+ end
24
+
25
+ def self.fpm_chart(pool, values)
26
+ max_active_processes = 0
27
+ chart_data = {
28
+ :value_axes => self.axes,
29
+ :graph_data => [],
30
+ :graphs => self.graphs,
31
+ :title => "#{pool} FPM pool statistic",
32
+ :category_field => 'timestamp',
33
+ :title_size => 20,
34
+ :guides => {}
35
+ }
36
+
37
+ prev = nil
38
+ values.each do |value|
39
+ temp = {}
40
+
41
+ if prev.nil? then
42
+ prev = value
43
+ next
44
+ end
45
+
46
+ time_diff = value[:timestamp].to_i - prev[:timestamp].to_i
47
+ accepted_connections_per_sec = ((value[:accepted_connections] - prev[:accepted_connections])/time_diff.to_f).round(3)
48
+ #Interpolation of no data intervals
49
+ if accepted_connections_per_sec < 0
50
+ prev = value
51
+ next
52
+ end
53
+
54
+ max_active_processes = value[:processes_active_max] if value[:processes_active_max] > max_active_processes
55
+
56
+ temp = {'timestamp' => value[:timestamp]}
57
+ temp[:processes_active] = value[:processes_active]
58
+ temp[:processes_idle] = value[:processes_idle]
59
+ temp[:accepted_connections_per_sec] = accepted_connections_per_sec.to_f
60
+ prev = value
61
+ chart_data[:graph_data] << temp
62
+ end
63
+ chart_data[:guides] = [
64
+ {
65
+ :value => max_active_processes,
66
+ :value_axis => 'valueAxis2',
67
+ :line_color => "#FF0000",
68
+ :line_thickness => 1,
69
+ :dash_length => 5,
70
+ :label => "Max processes",
71
+ :inside => 'true',
72
+ :line_alpha => 1,
73
+ :position => 'bottom',
74
+ }
75
+ ]
76
+
77
+ return chart_data
78
+ end
79
+
80
+ def self.graphs
81
+ [
82
+ { :value_field => "processes_active",
83
+ :graph_type => 'line',
84
+ :hidden => false,
85
+ :balloon_text => "[[title]]: ([[value]])",
86
+ :line_color => "#FF0000",
87
+ :line_thickness => 1,
88
+ :line_alpha => 1,
89
+ :fill_alphas => 0.6,
90
+ :title => "Active Processes",
91
+ :value_axis => "valueAxis2"},
92
+ { :value_field => "processes_idle",
93
+ :graph_type => 'line',
94
+ :hidden => false,
95
+ :balloon_text => "[[title]]: ([[value]])",
96
+ :line_color => "#00FF00",
97
+ :line_thickness => 1,
98
+ :line_alpha => 1,
99
+ :fill_alphas => 0.6,
100
+ :title => "Idle processes",
101
+ :value_axis => "valueAxis2"},
102
+ { :value_field => "accepted_connections_per_sec",
103
+ :graph_type => 'line',
104
+ :hidden => false,
105
+ :balloon_text => "[[title]]: ([[value]])",
106
+ :line_color => "#0000FF",
107
+ :line_thickness => 3,
108
+ :line_alpha => 1,
109
+ :fill_alphas => 0,
110
+ :title => "Accepted connections per second",
111
+ :value_axis => "valueAxis1"},
112
+ ]
113
+ end
114
+
115
+ def self.axes
116
+ [
117
+ {
118
+ :name => 'valueAxis1',
119
+ :title => 'Accepted connections per second',
120
+ :position => 'right',
121
+ :min_max_multiplier => 1,
122
+ :grid_alpha => 0.07,
123
+ :include_guides_in_min_max => 'true',
124
+ :stack_type => "none"
125
+ },
126
+ {
127
+ :name => 'valueAxis2',
128
+ :title => 'Active processes',
129
+ :position => 'left',
130
+ :grid_alpha => 0.07,
131
+ :min_max_multiplier => 1,
132
+ :include_guides_in_min_max => 'true',
133
+ :stack_type => "regular"
134
+ }
135
+ ]
136
+
137
+ end
138
+ end