opstat-plugins 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
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,57 @@
1
+ class Haproxy
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
+ field :stot, type: Integer
9
+ index({timestamp: 1, host_id: 1, plugin_id: 1}, {background: true})
10
+
11
+ def self.chart_data(options = {})
12
+ charts = []
13
+ charts = self.haproxy_charts(options)
14
+ return charts
15
+ end
16
+
17
+ def self.haproxy_charts(options)
18
+ haproxy_instance =[]
19
+ charts = []
20
+ Haproxy.where(:timestamp.gte => options[:start]).
21
+ where(:timestamp.lt => options[:end]).
22
+ where(:host_id => options[:host_id]).
23
+ where(:plugin_id => options[:plugin_id]).
24
+ order_by(timestamp: :asc).group_by{|u| u[:name]}.each_pair do |instance, values|
25
+ charts << self.haproxy_chart(instance, values)
26
+ end
27
+ return charts
28
+ end
29
+
30
+ def self.haproxy_chart(instance, values)
31
+ chart = self.chart_structure({:title => "Haproxy #{instance}", :value_axis => { :title => "Session per second"} })
32
+ prev = {}
33
+ chart_data = {}
34
+ instances = Hash.new
35
+ values.each do |value|
36
+ instances[value[:stot]] ||= true
37
+ unless prev.has_key?(value[:stot]) then
38
+ prev[value[:stot]] = value
39
+ next
40
+ end
41
+ time_diff = value[:timestamp].to_i - prev[value[:stot]][:timestamp].to_i
42
+ chart[:graph_data] << {
43
+ "timestamp" => value[:timestamp],
44
+ "session_per_sec" => (value[:summary][:stot] - prev[value[:stot]][:summary][:stot]).to_f/time_diff
45
+ }
46
+ prev[value[:stot]] = value
47
+ end
48
+ chart
49
+ end
50
+
51
+ def self.graphs
52
+ {
53
+ :session_per_sec => { :line_color => '#00FFAC', :line_thickness => 4, :title => "session_per_second", :hidden => false},
54
+ }
55
+ end
56
+ end
57
+
@@ -0,0 +1,51 @@
1
+ class Jvm
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::AreaNotStackedChart
6
+ store_in collection: "opstat.reports"
7
+ field :timestamp, type: DateTime
8
+
9
+ def self.chart_data(options = {})
10
+ charts = []
11
+
12
+ charts << self.threads_chart(options)
13
+ end
14
+
15
+ def self.threads_chart(options)
16
+ graphs = [:free, :swap_used]
17
+ graph_fields = graphs << :timestamp
18
+ chart = area_stacked_chart(:graphs => graphs, :value_axis_title => 'Number of threads', :chart_title => 'Java threads')
19
+ chart[:graph_data] = Jvm.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_by(timestamp: :asc)
24
+ return chart
25
+ end
26
+ end
27
+
28
+ def area_stacked_chart(config)
29
+ chart = {
30
+ :value_axes => [
31
+ {
32
+ :name => "valueAxis1",
33
+ :title => config[:value_axis1_title],
34
+ :position => 'left',
35
+ :stack_type => 'regular',
36
+ :grid_alpha => 0.07,
37
+ :min_max_multiplier => 1,
38
+ :include_guides_in_min_max => 'true'
39
+ }
40
+ ],
41
+ :category_field => 'timestamp',
42
+ :graph_data => [],
43
+ :graphs => [],
44
+ :title => config[:chart_title],
45
+ :title_size => 20
46
+ }
47
+ config[:graphs].each do |graph|
48
+ chart[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :balloon_text => "[[title]]: ([[value]])", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.8, :graph_type => 'line' }
49
+ end
50
+ return chart
51
+ end
@@ -0,0 +1,99 @@
1
+ class Load
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.load_chart(options)
13
+ return charts
14
+ end
15
+
16
+ def self.load_chart(options)
17
+ chart = self.chart_structure({:title => "Host load average", :value_axis => { :title => "Load averages"}, :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] = Load.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_by(timestamp: :asc)
30
+
31
+ host_facts = Facts.get_latest_facts_for_host(options[:host_id])
32
+ unless host_facts.nil?
33
+ cores_total = host_facts['facts']['processors']['count']
34
+ #TODO - find best way to set guides
35
+ # green zone - OK
36
+ guides = [ {
37
+ :value => 0,
38
+ :to_value => cores_total,
39
+ :value_axis => 'valueAxis1',
40
+ :line_color => "#00FF00",
41
+ :fill_color => "#00FF00",
42
+ :line_thickness => 1,
43
+ :dash_length => 5,
44
+ :label => "",
45
+ :inside => false,
46
+ :line_alpha => 1,
47
+ :fill_alpha => 0.1,
48
+ :position => 'bottom'},
49
+ # yellow zone - warn
50
+ {:value => cores_total,
51
+ :to_value => cores_total * 2,
52
+ :value_axis => 'valueAxis1',
53
+ :line_color => "#FFFF00",
54
+ :fill_color => "#FFFF00",
55
+ :line_thickness => 1,
56
+ :dash_length => 5,
57
+ :label => "",
58
+ :inside => false,
59
+ :line_alpha => 1,
60
+ :fill_alpha => 0.1,
61
+ :position => 'bottom'},
62
+ # red zone - critical
63
+ {:value => cores_total * 2,
64
+ :to_value => cores_total * 10,
65
+ :value_axis => 'valueAxis1',
66
+ :line_color => "#FF0000",
67
+ :fill_color => "#FF0000",
68
+ :line_thickness => 1,
69
+ :dash_length => 5,
70
+ :label => "",
71
+ :inside => false,
72
+ :line_alpha => 1,
73
+ :fill_alpha => 0.1,
74
+ :position => 'bottom'}]
75
+ end
76
+ chart[:guides] = guides
77
+ chart
78
+ end
79
+
80
+ def self.graphs
81
+ {
82
+ :load_15m => {
83
+ :hidden => false,
84
+ :line_color => "#FF0000",
85
+ :line_thickness => 3,
86
+ :title => "Load 15 minutes average"},
87
+ :load_5m => {
88
+ :hidden => false,
89
+ :line_color => "#FFFF00",
90
+ :line_thickness => 2,
91
+ :title => "Load 5 minutes average"},
92
+ :load_1m => {
93
+ :hidden => false,
94
+ :line_color => "#FFaa00",
95
+ :line_thickness => 1,
96
+ :title => "Load 1 minute average"}
97
+ }
98
+ end
99
+ end
@@ -0,0 +1,55 @@
1
+ class Memory
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.memory_chart(options)
13
+ return charts
14
+ end
15
+
16
+ def self.memory_chart(options)
17
+ chart = self.chart_structure({:title => "Host memory usage", :value_axis => { :title => "Memory size in KB"}})
18
+ #TODO - get fields from above DRY
19
+ chart[:graph_data] = Memory.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]).order_by(timestamp: :asc)
23
+
24
+ guides = []
25
+ host_facts = Facts.get_latest_facts_for_host(options[:host_id])
26
+ unless host_facts.nil?
27
+ memory_total_bytes = host_facts['facts']['memory']['system']['total_bytes']
28
+ memory_total_kibytes = memory_total_bytes/1024
29
+ guide = {}
30
+ require 'ruby-units'
31
+ guide[:value] = memory_total_kibytes
32
+ guide[:value_axis] = 'valueAxis1'
33
+ guide[:line_color] = "#FF0000"
34
+ guide[:line_thickness] = 1
35
+ guide[:dash_length] = 5
36
+ guide[:label] = "Total physical memory: #{memory_total_kibytes}KiB (by facter)"
37
+ guide[:inside] = true
38
+ guide[:line_alpha] = 1
39
+ guide[:position] = 'bottom'
40
+ guides << guide
41
+ end
42
+ chart[:guides] = guides
43
+ chart
44
+ end
45
+
46
+ def self.graphs
47
+ {
48
+ :used => { :line_color => '#FF3300' },
49
+ :cached => {:line_color => '#FFFF00' },
50
+ :buffers => {:line_color => '#FFaa33' },
51
+ :free => {:line_color => '#00FF00' },
52
+ :swap_used => {:line_color => '#00FFFF' }
53
+ }
54
+ end
55
+ end
@@ -0,0 +1,51 @@
1
+ class Nagios
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
+
9
+ def self.chart_data(options = {})
10
+ charts = []
11
+ charts << self.nagios_chart(options)
12
+ return charts
13
+ end
14
+
15
+ def self.nagios_chart(options)
16
+ chart = self.chart_structure({:title => "Nagios alerts statistic", :value_axis => { :title => "Number of services"}})
17
+ #TODO - get fields from above DRY
18
+ chart[:graph_data] = Nagios.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)
23
+ return chart
24
+ end
25
+
26
+ def self.graphs
27
+ {
28
+ :services_critical => {
29
+ :line_color => "#FF0000",
30
+ :hidden => false,
31
+ :title => "Services with critical errors"
32
+ },
33
+ :services_warning => {
34
+ :line_color => "#FFFF00",
35
+ :hidden => false,
36
+ :title => "Services with warnings"
37
+ },
38
+ :services_unknown => {
39
+ :line_color => "#FFaa00",
40
+ :hidden => false,
41
+ :title => "Services in unknown state"
42
+ },
43
+ :services_ok => {
44
+ :line_color => "#00FF00",
45
+ :hidden => true,
46
+ :title => "Services with no problems"
47
+ }
48
+
49
+ }
50
+ end
51
+ end
@@ -0,0 +1,58 @@
1
+ class Network
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::AreaNotStackedChart
6
+ store_in collection: "opstat.reports"
7
+ field :timestamp, type: DateTime
8
+ field :bytes_receive, type: Integer
9
+ field :bytes_transmit, type: Integer
10
+ index({timestamp: 1, host_id: 1 , plugin_id: 1},{background: true})
11
+
12
+ def self.chart_data(options = {})
13
+ charts = []
14
+ charts = self.all_interfaces_charts(options)
15
+ return charts
16
+ end
17
+
18
+ def self.all_interfaces_charts(options)
19
+ charts = []
20
+ Network.where(:timestamp.gte => options[:start]).
21
+ where(:timestamp.lt => options[:end]).
22
+ where(:host_id => options[:host_id]).
23
+ where(:plugin_id => options[:plugin_id]).
24
+ order_by(timestamp: :asc).group_by{|u| u.interface}.each_pair do |interface, values|
25
+ charts << self.interface_chart(interface, values)
26
+ end
27
+ return charts
28
+ end
29
+
30
+ def self.interface_chart(interface, values)
31
+ chart_data = self.chart_structure({:title => "Network traffic for #{interface}", :value_axis => { :title => "Network traffic for #{interface}"}})
32
+
33
+ prev = nil
34
+ values.each do |value|
35
+ if prev.nil? then
36
+ prev = value
37
+ next
38
+ end
39
+ time_diff = value[:timestamp].to_i - prev[:timestamp].to_i
40
+ chart_data[:graph_data] << {
41
+ "timestamp" => value[:timestamp],
42
+ "bytes_receive_per_sec" => ((value[:bytes_receive].to_i - prev[:bytes_receive].to_i)/time_diff).to_i,
43
+ "bytes_transmit_per_sec" => ((value[:bytes_transmit].to_i - prev[:bytes_transmit].to_i)/time_diff).to_i
44
+ }
45
+ prev = value
46
+
47
+ end
48
+
49
+ chart_data
50
+ end
51
+
52
+ def self.graphs
53
+ {
54
+ :bytes_receive_per_sec => { :line_color => '#0033FF' },
55
+ :bytes_transmit_per_sec => {:line_color => '#00FF00' }
56
+ }
57
+ end
58
+ end
@@ -0,0 +1,41 @@
1
+ class OracleFrasSizes
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
+
9
+ #TODO - files chart
10
+ def self.chart_data(options = {})
11
+ charts = []
12
+ charts = self.all_fras_charts(options)
13
+ return charts
14
+ end
15
+
16
+ def self.all_fras_charts(options)
17
+ charts = []
18
+ OracleFrasSizes.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.path}.each_pair do |path, values|
23
+ charts << self.fra_chart(path, values)
24
+ end
25
+ return charts
26
+ end
27
+
28
+ def self.fra_chart(path, values)
29
+ chart = self.chart_structure({:title => "Flash Recovery Area #{path} space usage", :value_axis => { :title => "FRA space usage"}})
30
+ chart[:graph_data] = values
31
+
32
+ return chart
33
+ end
34
+
35
+ def self.graphs
36
+ {
37
+ :used => { :line_color => '#FF0000' },
38
+ :free => {:line_color => '#00FF00' }
39
+ }
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ class OracleSessions
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
+
9
+ def self.chart_data(options = {})
10
+ charts = []
11
+ charts << self.sessions_chart(options)
12
+ return charts
13
+ end
14
+
15
+ def self.sessions_chart(options)
16
+ chart = self.chart_structure({:title => "Oracle sessions", :value_axis => { :title => "Sessions count"}})
17
+ chart[:graph_data] = OracleSessions.where(:timestamp.gte => options[:start]).
18
+ where(:timestamp.lt => options[:end]).
19
+ where(:host_id => options[:host_id]).
20
+ where(:plugin_id => options[:plugin_id]).
21
+ order_by(timestamp: :asc)
22
+ return chart
23
+ end
24
+
25
+ def self.graphs
26
+ {
27
+ :used => {
28
+ :hidden => false,
29
+ :line_color => "#FF0000",
30
+ :line_thickness => 3,
31
+ :balloon_text => "[[title]]: [[value]] ([[percents]]%)",
32
+ :title => "Session used"
33
+ },
34
+ :free => {
35
+ :hidden => false,
36
+ :line_color => "#00FF00",
37
+ :line_thickness => 3,
38
+ :balloon_text => "[[title]]: [[value]] ([[percents]]%)",
39
+ :title => "Sessions free"
40
+ }
41
+ }
42
+ end
43
+ end
@@ -0,0 +1,51 @@
1
+ class OracleTablespacesSizes
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
+
9
+ def self.chart_data(options = {})
10
+ charts = []
11
+ charts = self.all_tablespaces_charts(options)
12
+ return charts
13
+ end
14
+
15
+ def self.all_tablespaces_charts(options)
16
+ charts = []
17
+ OracleTablespacesSizes.where(:timestamp.gte => options[:start]).
18
+ where(:timestamp.lt => options[:end]).
19
+ where(:host_id => options[:host_id]).
20
+ where(:plugin_id => options[:plugin_id]).
21
+ order(timestamp: :asc).group_by{|u| u.name}.each_pair do |tablespace, values|
22
+ charts << self.tablespace_chart(tablespace, values)
23
+ end
24
+ return charts
25
+ end
26
+
27
+ def self.tablespace_chart(tablespace, values)
28
+ chart = self.chart_structure({:title => "Tablespace #{tablespace} space usage", :value_axis => { :title => "Size in bytes"}})
29
+ chart[:graph_data] = values
30
+ return chart
31
+ end
32
+
33
+ def self.graphs
34
+ {
35
+ :used => {
36
+ :hidden => false,
37
+ :line_color => "#FF0000",
38
+ :line_thickness => 3,
39
+ :balloon_text => "[[title]]: [[value]] ([[percents]]%)",
40
+ :title => "Bytes used"
41
+ },
42
+ :free => {
43
+ :hidden => false,
44
+ :line_color => "#00FF00",
45
+ :line_thickness => 3,
46
+ :balloon_text => "[[title]]: [[value]] ([[percents]]%)",
47
+ :title => "Bytes free"
48
+ }
49
+ }
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ class Temper
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::AreaNotStackedChart
6
+ store_in collection: "opstat.reports"
7
+ field :timestamp, type: DateTime
8
+
9
+ def self.chart_data(options = {})
10
+ charts = []
11
+ charts << self.temper_chart(options)
12
+ return charts
13
+ end
14
+
15
+ def self.temper_chart(options)
16
+ chart = self.chart_structure({:title => "Temperature in [C]", :value_axis => { :title => "Temperature"}})
17
+ # data = {
18
+ # :value_axes => [
19
+ # {
20
+ ## :stack_type => 'regular',
21
+ # }
22
+ # ],
23
+ # }
24
+
25
+
26
+ #TODO - get fields from above DRY
27
+ chart[:graph_data] = Temper.where(:timestamp.gte => options[:start]).
28
+ where(:timestamp.lt => options[:end]).
29
+ where(:host_id => options[:host_id]).
30
+ where(:plugin_id => options[:plugin_id]).
31
+ order_by(timestamp: :asc)
32
+ chart
33
+ end
34
+
35
+ def self.axes_defaults
36
+ {
37
+ :value_axis => {:title => 'Temperature in C'}
38
+ }
39
+ end
40
+
41
+ def self.graphs
42
+ {
43
+ :temperature => {
44
+ :value_field => "Temperature",
45
+ :hidden => false,
46
+ :line_color => "#FF0000",
47
+ :title => "Temperature"
48
+ }
49
+ }
50
+ end
51
+ end
@@ -0,0 +1,83 @@
1
+ class Webobjects
2
+ include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic
4
+ include Mongoid::Timestamps
5
+ include Graphs::AreaStackedChart
6
+ index({timestamp: 1, host_id: 1, plugin_id: 1},{background: true})
7
+ store_in collection: "opstat.reports"
8
+
9
+ def self.chart_data(options = {})
10
+ charts = []
11
+ charts = self.all_applications_charts(options)
12
+ return charts
13
+ end
14
+
15
+ def self.all_sensors_applications_charts(options = {})
16
+ charts = []
17
+ Webobjects.where(:timestamp.gte => options[:start]).
18
+ where(:timestamp.lt => options[:end]).
19
+ where(:plugin_type => 'webobjects').
20
+ order_by(timestamp: :asc).group_by{|u| u.name}.each_pair do |app, stats|
21
+ charts << self.application_charts(app,stats)
22
+ end
23
+ return charts.flatten
24
+ end
25
+
26
+ def self.all_applications_charts(options = {})
27
+ charts = []
28
+ Webobjects.where(:timestamp.gte => options[:start]).
29
+ where(:timestamp.lt => options[:end])
30
+ where(:host_id => options[:host_id]).
31
+ where(:plugin_id => options[:plugin_id]).
32
+ order_by(timestamp: :asc).group_by{|u| u.name}.each_pair do |app, stats|
33
+ charts << self.application_charts(app,stats)
34
+ end
35
+ return charts.flatten
36
+ end
37
+
38
+ def self.application_charts(app,app_stats)
39
+ chart = self.chart_structure({:title => "Number of sessions - #{app} application", :value_axis => { :title => "Number of sessions"}})
40
+ prev = nil
41
+ instances = Hash.new
42
+ app_stats.group_by {|s| s.timestamp}.each do |timestamp, stats|
43
+ temp = {:timestamp => timestamp}
44
+ stats.each do |stat|
45
+ #<Webobjects _id: 201, created_at: nil, updated_at: nil, name: "ifirma", host: "ifirmaapp01", port: "2201", state: "ALIVE", deaths: "0", refusingNewSessions: false, scheduled: false, schedulingHourlyStartTime: 3, schedulingDailyStartTime: 3, schedulingWeeklyStartTime: 3, schedulingType: "DAILY", schedulingStartDay: 1, schedulingInterval: 12, transactions: "284487", activeSessions: "41", averageIdlePeriod: "0.646", avgTransactionTime: "0.054", autoRecover: "true", timestamp: 2018-10-17 06:16:31 UTC, host_id: BSON::ObjectId('5bc6d3bf7327d40cb44d9ad6'), plugin_id: BSON::ObjectId('5bc6d3c07327d40cb44d9af7'), plugin_type: "webobjects"
46
+ instances[stat[:instance_id]] ||= true
47
+ temp[stat[:instance_id]] = stat[:activeSessions].to_i
48
+ end
49
+ chart[:graph_data] << temp
50
+ end
51
+ instances.keys.each do |graph|
52
+ chart[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :balloon_text => "[[title]]: ([[value]])", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.1, :graph_type => 'line' }
53
+ end
54
+
55
+ # tps = self.tps_graph(app)
56
+ # instances.keys.each do |graph|
57
+ # tps[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph.to_s, :balloon_text => "[[title]]: ([[value]])", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.1, :graph_type => 'line' }
58
+ # end
59
+
60
+ # sessions = sessions_graph(app)
61
+ # instances.keys.each do |graph|
62
+ # sessions[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :balloon_text => "[[title]]: ([[value]])", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 0.1, :graph_type => 'line' }
63
+ # end
64
+ # sessions[:graph_data] = chart_data[:sessions]
65
+ # tps[:graph_data] = chart_data[:tps]
66
+ # chart[:graph_data] = chart_data[:sessions]
67
+ p chart
68
+ return chart
69
+ end
70
+
71
+ def self.tps_graph(app)
72
+ return self.chart_structure({:title => "Transactions per second - #{app} application", :value_axis => { :title => "Transactions/sec"}})
73
+ end
74
+
75
+ def self.graphs
76
+ {
77
+ :sessions => { :line_color => '#0033FF' },
78
+ }
79
+ end
80
+ def self.sessions_graph(app)
81
+ return self.chart_structure({:title => "Number of sessions - #{app} application", :value_axis => { :title => "Number of sessions"}})
82
+ end
83
+ end