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,99 @@
1
+ class Xen
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
+
10
+ def self.chart_data(options = {})
11
+ charts = []
12
+
13
+ charts << self.memory_chart(options)
14
+ end
15
+
16
+ def self.vbd_chart(options)
17
+ memory = {
18
+ :value_axes => [
19
+ {
20
+ :name => "valueAxis1",
21
+ :title => 'Memory in KB',
22
+ :position => 'left',
23
+ :stack_type => 'regular',
24
+ :grid_alpha => 0.07,
25
+ :min_max_multiplier => 1,
26
+ :include_guides_in_min_max => 'true'
27
+ }
28
+ ],
29
+ :category_field => 'timestamp',
30
+ :graph_data => [],
31
+ :graphs => [],
32
+ :title => "XEN memory usage",
33
+ :title_size => 20
34
+ }
35
+ graphs = []
36
+ # TODO - why use periods in this query
37
+ Xen.where(:timestamp.gte => options[:start]).
38
+ where(:timestamp.lt => options[:end]).
39
+ where(:ip_address => options[:ip_address]).
40
+ where(:hostname => options[:hostname]).
41
+ group('UNIX_TIMESTAMP(timestamp) div 60, domain').
42
+ order_by(:timestamp).select('FROM_UNIXTIME((UNIX_TIMESTAMP(timestamp) div 60) *60,\'%Y-%m-%d %H:%i:%S\') as period_start, domain,max(memory) as memory').group_by{|u| u.period_start}.each_pair do |period_start, domains|
43
+ tmp = { :year => period_start.to_datetime.to_i * 1000 }
44
+ #TODO sort
45
+ domains.each do |domain|
46
+ tmp[domain.domain] = domain.memory
47
+ graphs << domain.domain unless graphs.include?(domain.domain)
48
+ end
49
+ memory[:graph_data] << tmp
50
+ end
51
+ graphs.each do |graph|
52
+ #TODO value_axis
53
+ memory[:graphs] << { :value_axis => 'valueAxis1', :value_field => graph, :balloon_text => "[[title]]: [[value]] KB", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 1, :graph_type => 'line' }
54
+ end
55
+ memory
56
+ end
57
+ def self.memory_chart(options)
58
+ memory = {
59
+ :value_axes => [
60
+ {
61
+ :name => "valueAxis1",
62
+ :title => 'Memory in KB',
63
+ :position => 'left',
64
+ :stack_type => 'regular',
65
+ :grid_alpha => 0.07,
66
+ :min_max_multiplier => 1,
67
+ :include_guides_in_min_max => 'true'
68
+ }
69
+ ],
70
+ :category_field => 'timestamp',
71
+ :graph_data => [],
72
+ :graphs => [],
73
+ :title => "XEN memory usage",
74
+ :title_size => 20
75
+ }
76
+ graphs = []
77
+ all_stats = Xen.where( {:timestamp => { :$gte => options[:start],:$lt => options[:end]}, :host_id => options[:host_id], :plugin_id => options[:plugin_id] }).order(:timestamp).group_by{|u| u.domain}
78
+ tmp = {}
79
+ Xen.where( {:timestamp => { :$gte => options[:start],:$lt => options[:end]}, :host_id => options[:host_id], :plugin_id => options[:plugin_id] }).order(:timestamp).group_by{|u| u.domain}.each_pair do |domain,stats|
80
+ stats.each do |stat|
81
+ tmp[stat['timestamp']] ||= { 'timestamp' => stat['timestamp'] }
82
+ tmp[stat['timestamp']] = tmp[stat['timestamp']].merge!({ stat['domain'] => stat['memory']})
83
+ end
84
+ end
85
+ memory[:graph_data] = tmp.values
86
+ all_stats.keys.each do |domain|
87
+ memory[:graphs] << { :value_axis => 'valueAxis1', :value_field => domain, :balloon_text => "[[title]]: [[value]] KB", :line_thickness => 1, :line_alpha => 1, :fill_alphas => 1, :graph_type => 'line' }
88
+ end
89
+ memory
90
+ end
91
+
92
+ def self.graphs_defaults
93
+ []
94
+ end
95
+
96
+ def self.axes_defaults
97
+ []
98
+ end
99
+ end
@@ -0,0 +1,191 @@
1
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.1.1:
2
+ :description: Voltage Segment 1 PDU A
3
+ :pdu: A
4
+ :meter_type: voltage
5
+ :store_key: segment_1
6
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.1.2:
7
+ :description: Voltage Segment 2 PDU A
8
+ :pdu: A
9
+ :meter_type: voltage
10
+ :store_key: segment_2
11
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.1.3:
12
+ :description: Voltage Segment 3 PDU A
13
+ :pdu: A
14
+ :meter_type: voltage
15
+ :store_key: segment_3
16
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.1.4:
17
+ :description: Voltage Segment 4 PDU A
18
+ :pdu: A
19
+ :meter_type: voltage
20
+ :store_key: segment_4
21
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.1.5:
22
+ :description: Voltage Segment 5 PDU A
23
+ :pdu: A
24
+ :meter_type: voltage
25
+ :store_key: segment_5
26
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.1.6:
27
+ :description: Voltage Segment 6 PDU A
28
+ :pdu: A
29
+ :meter_type: voltage
30
+ :store_key: segment_6
31
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.1.1:
32
+ :description: Current Segment 1 PDU A
33
+ :pdu: A
34
+ :meter_type: current
35
+ :store_key: segment_1
36
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.1.2:
37
+ :description: Current Segment 2 PDU A
38
+ :pdu: A
39
+ :meter_type: current
40
+ :store_key: segment_2
41
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.1.3:
42
+ :description: Current Segment 3 PDU A
43
+ :pdu: A
44
+ :meter_type: current
45
+ :store_key: segment_3
46
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.1.4:
47
+ :description: Current Segment 4 PDU A
48
+ :pdu: A
49
+ :meter_type: current
50
+ :store_key: segment_4
51
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.1.5:
52
+ :description: Current Segment 5 PDU A
53
+ :pdu: A
54
+ :meter_type: current
55
+ :store_key: segment_5
56
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.1.6:
57
+ :description: Current Segment 6 PDU A
58
+ :pdu: A
59
+ :meter_type: current
60
+ :store_key: segment_6
61
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.1.1:
62
+ :description: Load Segement 1 in % PDU A
63
+ :pdu: A
64
+ :meter_type: load
65
+ :store_key: segment_1
66
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.1.2:
67
+ :description: Load Segement 2 in % PDU A
68
+ :pdu: A
69
+ :meter_type: load
70
+ :store_key: segment_2
71
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.1.3:
72
+ :description: Load Segement 3 in % PDU A
73
+ :pdu: A
74
+ :meter_type: load
75
+ :store_key: segment_3
76
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.1.4:
77
+ :description: Load Segement 4 in % PDU A
78
+ :pdu: A
79
+ :meter_type: load
80
+ :store_key: segment_4
81
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.1.5:
82
+ :description: Load Segement 5 in % PDU A
83
+ :pdu: A
84
+ :meter_type: load
85
+ :store_key: segment_5
86
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.1.6:
87
+ :description: Load Segement 6 in % PDU A
88
+ :pdu: A
89
+ :meter_type: load
90
+ :store_key: segment_6
91
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.2.1:
92
+ :description: Voltage Segment 1 PDU B
93
+ :pdu: B
94
+ :meter_type: voltage
95
+ :store_key: segment_1
96
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.2.2:
97
+ :description: Voltage Segment 2 PDU B
98
+ :pdu: B
99
+ :meter_type: voltage
100
+ :store_key: segment_2
101
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.2.3:
102
+ :description: Voltage Segment 3 PDU B
103
+ :pdu: B
104
+ :meter_type: voltage
105
+ :store_key: segment_3
106
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.2.4:
107
+ :description: Voltage Segment 4 PDU B
108
+ :pdu: B
109
+ :meter_type: voltage
110
+ :store_key: segment_4
111
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.2.5:
112
+ :description: Voltage Segment 5 PDU B
113
+ :pdu: B
114
+ :meter_type: voltage
115
+ :store_key: segment_5
116
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.2.2.6:
117
+ :description: Voltage Segment 6 PDU B
118
+ :pdu: B
119
+ :meter_type: voltage
120
+ :store_key: segment_6
121
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.2.1:
122
+ :description: Current Segment 1 PDU B
123
+ :pdu: B
124
+ :meter_type: current
125
+ :store_key: segment_1
126
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.2.2:
127
+ :description: Current Segment 2 PDU B
128
+ :pdu: B
129
+ :meter_type: current
130
+ :store_key: segment_2
131
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.2.3:
132
+ :description: Current Segment 3 PDU B
133
+ :pdu: B
134
+ :meter_type: current
135
+ :store_key: segment_3
136
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.2.4:
137
+ :description: Current Segment 4 PDU B
138
+ :pdu: B
139
+ :meter_type: current
140
+ :store_key: segment_4
141
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.2.5:
142
+ :description: Current Segment 5 PDU B
143
+ :pdu: B
144
+ :meter_type: current
145
+ :store_key: segment_5
146
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.3.2.6:
147
+ :description: Current Segment 6 PDU B
148
+ :pdu: B
149
+ :meter_type: current
150
+ :store_key: segment_6
151
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.2.1:
152
+ :description: Load Segement 1 in % PDU B
153
+ :pdu: B
154
+ :meter_type: load
155
+ :store_key: segment_1
156
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.2.2:
157
+ :description: Load Segement 2 in % PDU B
158
+ :pdu: B
159
+ :meter_type: load
160
+ :store_key: segment_2
161
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.2.3:
162
+ :description: Load Segement 3 in % PDU B
163
+ :pdu: B
164
+ :meter_type: load
165
+ :store_key: segment_3
166
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.2.4:
167
+ :description: Load Segement 4 in % PDU B
168
+ :pdu: B
169
+ :meter_type: load
170
+ :store_key: segment_4
171
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.2.5:
172
+ :description: Load Segement 5 in % PDU B
173
+ :pdu: B
174
+ :meter_type: load
175
+ :store_key: segment_5
176
+ SNMPv2-SMI::enterprises.232.165.2.3.2.1.4.2.6:
177
+ :description: Load Segement 6 in % PDU B
178
+ :pdu: B
179
+ :meter_type: load
180
+ :store_key: segment_6
181
+ SNMPv2-SMI::enterprises.232.165.2.3.1.1.4.1:
182
+ :description: Total Power PDU A in Watt
183
+ :pdu: A
184
+ :meter_type: power
185
+ :store_key: total
186
+ SNMPv2-SMI::enterprises.232.165.2.3.1.1.4.2:
187
+ :description: Total Power PDU B in Watt
188
+ :pdu: B
189
+ :meter_type: power
190
+ :store_key: total
191
+
data/lib/logging.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'log4r'
2
+
3
+ module Opstat
4
+ module Logging
5
+ def preconfig_logger
6
+ return @logger if @logger
7
+ @logger = Log4r::Logger.new self.class.to_s
8
+ @logger.level = @logger.levels.index('INFO')
9
+ outputter = Log4r::Outputter.stdout
10
+ outputter.formatter = Log4r::PatternFormatter.new(:pattern => "%l - %C - %m")
11
+ @logger.outputters << outputter
12
+ @logger
13
+ end
14
+ def oplogger
15
+ return @logger if @logger
16
+ @logger = Log4r::Logger.new self.class.to_s
17
+ @logger.level = @logger.levels.index(log_level)
18
+ outputter = Log4r::Outputter.stdout
19
+ outputter.formatter = Log4r::PatternFormatter.new(:pattern => "%l - %C - %m")
20
+ @logger.outputters << outputter
21
+ @logger
22
+ end
23
+ def log_level
24
+ @log_level ||= Opstat::Config.instance.get('client')['log_level']
25
+ @log_level
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,44 @@
1
+ require 'logging.rb'
2
+ module Opstat
3
+ module Plugins
4
+ def self.load_models
5
+ pwd = File.dirname(File.expand_path(__FILE__))
6
+ Dir.glob(File.expand_path("#{pwd}/app/models/*.rb")).each do |file|
7
+ puts "loading #{file}"
8
+ filename = File.basename(file, '.*')
9
+ class_name_symbol = filename.classify.to_sym
10
+ #autoload class_name_symbol, "#{pwd}/app/models/#{filename}"
11
+ require "#{pwd}/app/models/#{filename}"
12
+ end
13
+ end
14
+
15
+ def self.load_parsers(oplogger)
16
+ pwd = File.dirname(File.expand_path(__FILE__))
17
+ parsers = {}
18
+ Dir.glob(File.expand_path("#{pwd}/parsers/*.rb")).each do |file|
19
+ require file
20
+ plugin_name = File.basename(file,'.*')
21
+ plugin_class = "Opstat::Parsers::#{plugin_name.capitalize}"
22
+ oplogger.info "loading parser #{plugin_name}"
23
+ parsers[plugin_name] ||= Opstat::Common.constantize(plugin_class).new
24
+ end
25
+ return parsers
26
+ end
27
+
28
+ def self.load_parser(name)
29
+ pwd = File.dirname(File.expand_path(__FILE__))
30
+ require pwd + "/parsers/#{name}.rb"
31
+ end
32
+
33
+ def self.load_plugin(name)
34
+ pwd = File.dirname(File.expand_path(__FILE__))
35
+ require pwd + "/plugins/#{name}.rb"
36
+ end
37
+ module Models
38
+ attr_reader :data_type
39
+ def data_type(type)
40
+ @data_type = type
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ module Opstat
2
+ module Parsers
3
+ require 'json'
4
+ class Apache2
5
+ include Opstat::Logging
6
+
7
+ def parse_data(data:, time:)
8
+ return [] if data.nil?
9
+ reports = []
10
+ oplogger.debug data
11
+ json_data = JSON::parse(data)
12
+ json_data.each_pair do |vhost, stats|
13
+ reports << { :vhost_name => vhost, :stats => stats }
14
+ end
15
+ return reports
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Bsdnet
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ #TODO count num of interfaces - for now assuming only 1 interface
8
+ interface = data[2].split[3]
9
+ bytes_in_v4 = data[3].split[2].to_i
10
+ bytes_out_v4 = data[4].split[2].to_i
11
+ packets_passed_in_v4 = data[6].split[1].to_i
12
+ packets_blocked_in_v4 = data[7].split[1].to_i
13
+ packets_passed_out_v4 = data[9].split[1].to_i
14
+ packets_blocked_out_v4 = data[10].split[1].to_i
15
+ current_entries = data[13].split[2].to_i
16
+ return [{
17
+ :interface => interface,
18
+ :bytes_in_v4 => bytes_in_v4,
19
+ :bytes_out_v4 => bytes_out_v4,
20
+ :packets_passed_in_v4 => packets_passed_in_v4,
21
+ :packets_blocked_in_v4 => packets_blocked_in_v4,
22
+ :packets_passed_out_v4 => packets_passed_out_v4,
23
+ :packets_blocked_out_v4 => packets_blocked_out_v4,
24
+ :current_entries => current_entries
25
+ }]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Cpu
4
+ include Opstat::Logging
5
+
6
+ def parse_data(data:, time:)
7
+ reports = []
8
+ cpu_summary_report = {}
9
+ data.each do |line|
10
+ case line
11
+ when /(?<OPSTAT_TAG_cpu_id>cpu\S*)\s+(?<user>\d+)\s+(?<nice>\d+)\s+(?<system>\d+)\s+(?<idle>\d+)\s+(?<iowait>\d+)\s+(?<irq>\d+)\s+(?<softirq>\d+).*/
12
+ report = {
13
+ :OPSTAT_TAG_cpu_id => $~[:OPSTAT_TAG_cpu_id],
14
+ :user => $~[:user].to_i,
15
+ :nice => $~[:nice].to_i,
16
+ :system => $~[:system].to_i,
17
+ :idle => $~[:idle].to_i,
18
+ :iowait => $~[:iowait].to_i,
19
+ :irq => $~[:irq].to_i,
20
+ :softirq => $~[:softirq].to_i
21
+ }
22
+ if $~[:OPSTAT_TAG_cpu_id] == 'cpu'
23
+ cpu_summary_report = report
24
+ else
25
+ reports << report
26
+ end
27
+ when /procs_blocked\s+(?<processes_blocked>\d+)/
28
+ cpu_summary_report[:processes_blocked] = $~[:processes_blocked].to_i
29
+ when /procs_running\s+(?<processes_running>\d+)/
30
+ cpu_summary_report[:processes_running] = $~[:processes_running].to_i
31
+ when /processes\s+(?<processes>\d+)/
32
+ cpu_summary_report[:processes] = $~[:processes].to_i
33
+ when /ctxt\s+(?<context_switches>\d+)/
34
+ cpu_summary_report[:context_switches] = $~[:context_switches].to_i
35
+ end
36
+ end
37
+ reports << cpu_summary_report
38
+ return reports
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ require 'yaml'
2
+
3
+ # TODO connect client settings with master (version, etc)
4
+ # df --output='source,fstype,used,avail,itotal,iused,iavail,target'
5
+ module Opstat
6
+ module Parsers
7
+ FS_TYPES = ["ext2", "ext3", "ext4", "reiserfs", "xfs", "jfs"]
8
+ class Disk
9
+ include Opstat::Logging
10
+
11
+ def parse_data(data:, time:)
12
+ reports = []
13
+ oplogger.debug data
14
+ data['disk_space'].each do |line|
15
+ stats = line.split
16
+ if FS_TYPES.include?(stats[1]) and stats.count == 8
17
+ space_usage_report = get_space_usage_report(stats)
18
+ device = space_usage_report['device']
19
+ disk_io_report = get_disk_io_stats_for_device(device,data['disk_io'])
20
+ reports << space_usage_report.merge(disk_io_report)
21
+ end
22
+ end
23
+ return reports
24
+ end
25
+ def get_space_usage_report(stats)
26
+ space_usage_report = {
27
+ 'device' => stats[0].delete_prefix('/dev/'),
28
+ :inode_total => stats[4].to_i,
29
+ :inode_used => stats[5].to_i,
30
+ :inode_free => stats[6].to_i,
31
+ :block_total => stats[2].to_i + stats[3].to_i,
32
+ :block_used => stats[2].to_i,
33
+ :block_free => stats[3].to_i,
34
+ :fstype => stats[1],
35
+ :OPSTAT_TAG_mount => stats[7]
36
+ }
37
+ end
38
+
39
+ def get_disk_io_stats_for_device(device, data)
40
+ raw_disk_io_line = data.grep(/#{device}/).first
41
+ raw_disk_io_line.match(/^\s+(?<major_number>\d+)\s+(?<minor_number>\d+)\s+\S+\s+(?<reads_completed>\d+)\s+(?<reads_merged>\d+)\s+(?<sector_read>\d+)\s+(?<time_spent_reading_ms>\d+)\s+(?<writes_completed>\d+)\s+(?<writes_merged>\d+)\s+(?<sectors_written>\d+)\s+(?<time_spent_writing>\d+)\s+(?<io_in_progress>\d+)\s+(?<time_spent_doing_io_ms>\d+)\s+(?<weighted_time_doing_io>\d+)\s+.*/)
42
+ unless $~.nil?
43
+ return $~.names.zip($~.captures).map{|m| [m[0],m[1].to_i]}.to_h
44
+ end
45
+ return {}
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ module Opstat
2
+ module Parsers
3
+ # TODO - save changed only - is it possible?
4
+ class Facts
5
+ include Opstat::Logging
6
+
7
+ def parse_data(data:, time:)
8
+ [{ :facts => data }]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,31 @@
1
+ module Opstat
2
+ module Parsers
3
+ class Fpm
4
+ require 'json'
5
+ include Opstat::Logging
6
+
7
+ def parse_data(data:, time:)
8
+ begin
9
+ return [] if data.nil?
10
+ reports = []
11
+ data.each do |pool_stats|
12
+ values = JSON::parse(pool_stats[-1])
13
+ reports << {
14
+ :OPSTAT_TAG_pool => values['pool'],
15
+ :accepted_connections => values['accepted conn'],
16
+ :listen_queue => values['listen queue'],
17
+ :listen_queue_length => values['listen queue len'],
18
+ :listen_queue_max => values['max listen queue'],
19
+ :processes_idle => values['idle processes'],
20
+ :processes_active => values['active processes'],
21
+ :processes_active_max => values['max active processes'],
22
+ :children_max => values['max children reached']
23
+ }
24
+ end
25
+ end
26
+ #TODO - set some error message in db
27
+ return reports
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,63 @@
1
+ require 'xmlhasher'
2
+ require 'time'
3
+
4
+ XmlHasher.configure do |config|
5
+ config.snakecase = true
6
+ config.ignore_namespaces = true
7
+ config.string_keys = false
8
+ end
9
+
10
+ module Opstat
11
+ module Parsers
12
+ SKIP_FIFO_NAMES = ['manual_calls']
13
+ class FreeswitchFifos
14
+ include Opstat::Logging
15
+
16
+ def parse_data(data:, time:)
17
+ reports = []
18
+ XmlHasher.parse(data)[:fifo_report][:fifo].each do |fifo|
19
+ next if SKIP_FIFO_NAMES.include?(fifo[:name])
20
+ report = {}
21
+ report[:OPSTAT_TAG_fifo_name] = fifo[:name]
22
+ report[:waiting_calls] = fifo[:waiting_count].to_i
23
+ report[:outbound_per_cycle] = fifo[:outbound_per_cycle].to_i
24
+ if fifo[:outbound].nil?
25
+ report[:operators] = 0
26
+ else
27
+ if fifo[:outbound][:member].is_a?(String)
28
+ report[:operators] = 1
29
+ else
30
+ report[:operators] = fifo[:outbound][:member].count
31
+ end
32
+ end
33
+ if fifo[:bridges].nil?
34
+ report[:active_calls] = 0
35
+ else
36
+ if fifo[:bridges].is_a?(Hash)
37
+ report[:active_calls] = 1
38
+ else
39
+ report[:active_calls] = fifo[:bridges][:bridge].count
40
+ end
41
+ end
42
+
43
+ if fifo[:callers].nil?
44
+ report[:queue_max_waiting_time] = 0
45
+ else
46
+ if fifo[:callers][:caller].is_a?(Hash)
47
+ oldest_call_waiting_start_timestamp = fifo[:callers][:caller][:timestamp]
48
+ oldest_call_waiting_start_timestamp ||= time.to_s #due to some strange behaviour - there are data call without position and other needed params
49
+ else
50
+ oldest_call_waiting_start_timestamp = fifo[:callers][:caller].find{|call| call[:position].to_i == 1}[:timestamp]
51
+ end
52
+ report[:queue_max_waiting_time] = (time - Time.parse(oldest_call_waiting_start_timestamp)).to_i
53
+ end
54
+ reports << report
55
+ end
56
+
57
+ return reports
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+
@@ -0,0 +1,34 @@
1
+ require 'csv'
2
+ require 'yaml'
3
+ module Opstat
4
+ module Parsers
5
+ class Haproxy
6
+ include Opstat::Logging
7
+
8
+ def parse_data(data:, time:)
9
+ white_headers = [ :svname, :qcur, :qmax, :scur, :smax, :slim, :stot, :bin, :bout, :hrsp_1xx, :hrsp_2xx, :hrsp_3xx, :hrsp_4xx, :hrsp_5xx, :hrsp_other, :req_tot, :conn_tot]
10
+ parsed_data = CSV.parse(data.join, { headers: true, header_converters: :symbol, converters: :all}).map{|row| Hash[row.headers[0..-1].zip(row.fields[0..-1])]}.group_by{|row| row[:_pxname]}
11
+ report = []
12
+ yaml = []
13
+ parsed_data.each do |key,value|
14
+ if value.first[:svname] == "FRONTEND"
15
+ report << {:stats_type => :frontend, :name => value.first[:_pxname], :summary => value.first.select { |key, value| white_headers.include?(key)}}
16
+ elsif value.first[:_pxname].to_s.start_with?("backend")
17
+ backends = { :stats_type => :backend, :name => value.first[:_pxname] }
18
+ instances = []
19
+ value.each do |backend|
20
+ if backend[:svname] == "BACKEND"
21
+ backends[:summary] = backend.select { |key, value| white_headers.include?(key) }
22
+ else
23
+ backends[:details] = instances.push ( backend.select { |key, value| white_headers.include?(key) } )
24
+ end
25
+ end
26
+ report << backends
27
+ end
28
+ end
29
+ return report
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,25 @@
1
+ require 'csv'
2
+ require 'yaml'
3
+ module Opstat
4
+ module Parsers
5
+ class HaproxyTables
6
+ include Opstat::Logging
7
+ REGEX = /# table:\s+(?<OPSTAT_TAG_table>[^,]+), type:\s+[^,]+, size:(?<table_size>\d+), used:(?<table_used>\d+)/
8
+
9
+ def parse_data(data:, time:)
10
+ report = []
11
+ data.each do |line|
12
+ haproxy_table = REGEX.match(line)
13
+ if haproxy_table
14
+ captured_data = haproxy_table.named_captures
15
+ captured_data['table_size'] = captured_data['table_size'].to_i
16
+ captured_data['table_used'] = captured_data['table_used'].to_i
17
+ report << captured_data
18
+ end
19
+ end
20
+ return report
21
+ end
22
+ end
23
+ end
24
+ end
25
+