cloudscale-monitor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/lib/cloudscale/monitor.rb +131 -0
- data/lib/cloudscale/monitor/agent/init.rb +95 -0
- data/lib/cloudscale/monitor/agent/init_components.rb +88 -0
- data/lib/cloudscale/monitor/agent/init_menus.rb +53 -0
- data/lib/cloudscale/monitor/agent/preops/general_preop.rb +35 -0
- data/lib/cloudscale/monitor/agent/preops/preop.rb +48 -0
- data/lib/cloudscale/monitor/model/agent/agent_instance.rb +33 -0
- data/lib/cloudscale/monitor/model/agent/agent_instance_settings.rb +26 -0
- data/lib/cloudscale/monitor/model/component/component.rb +29 -0
- data/lib/cloudscale/monitor/model/constants/agent_instance_store.rb +42 -0
- data/lib/cloudscale/monitor/model/constants/agent_store.rb +23 -0
- data/lib/cloudscale/monitor/model/constants/agent_unit_store.rb +69 -0
- data/lib/cloudscale/monitor/model/constants/setup/display_unit_store.rb +210 -0
- data/lib/cloudscale/monitor/model/constants/statistic_store.rb +67 -0
- data/lib/cloudscale/monitor/model/coredata/coredata.rb +32 -0
- data/lib/cloudscale/monitor/model/format/format.rb +69 -0
- data/lib/cloudscale/monitor/model/measurement/chart.rb +37 -0
- data/lib/cloudscale/monitor/model/measurement/measurement.rb +29 -0
- data/lib/cloudscale/monitor/model/measurement/statistic.rb +27 -0
- data/lib/cloudscale/monitor/model/measurement/unit.rb +31 -0
- data/lib/cloudscale/monitor/model/measurement/value.rb +32 -0
- data/lib/cloudscale/monitor/model/metric/metric.rb +29 -0
- data/lib/cloudscale/monitor/model/table/table.rb +34 -0
- data/lib/cloudscale/monitor/version.rb +11 -0
- data/lib/cloudscale/plugins/apache/apache2_server_status.rb +125 -0
- data/lib/cloudscale/plugins/cpu/sigar_cpu_info.rb +52 -0
- data/lib/cloudscale/plugins/cpu/sigar_cpu_perc.rb +69 -0
- data/lib/cloudscale/plugins/cpu/sigar_cpu_time.rb +48 -0
- data/lib/cloudscale/plugins/definition/plugin_components.rb +384 -0
- data/lib/cloudscale/plugins/definition/plugin_components_apache.rb +158 -0
- data/lib/cloudscale/plugins/definition/plugin_components_java.rb +68 -0
- data/lib/cloudscale/plugins/definition/plugin_components_mongodb.rb +358 -0
- data/lib/cloudscale/plugins/definition/plugin_components_postgres.rb +196 -0
- data/lib/cloudscale/plugins/definition/plugin_menus.rb +148 -0
- data/lib/cloudscale/plugins/definition/plugin_menus_apache.rb +85 -0
- data/lib/cloudscale/plugins/definition/plugin_menus_java.rb +67 -0
- data/lib/cloudscale/plugins/definition/plugin_menus_mongodb.rb +125 -0
- data/lib/cloudscale/plugins/definition/plugin_menus_postgres.rb +99 -0
- data/lib/cloudscale/plugins/disk/sigar_disk_iops.rb +71 -0
- data/lib/cloudscale/plugins/disk/sigar_disk_space.rb +67 -0
- data/lib/cloudscale/plugins/general/sigar_net_info.rb +55 -0
- data/lib/cloudscale/plugins/general/sigar_os_information.rb +45 -0
- data/lib/cloudscale/plugins/java/jvm_status.rb +110 -0
- data/lib/cloudscale/plugins/mongo/mongo_db_status.rb +74 -0
- data/lib/cloudscale/plugins/mongo/mongo_replica_status.rb +108 -0
- data/lib/cloudscale/plugins/mongo/mongo_server_status.rb +177 -0
- data/lib/cloudscale/plugins/net/sigar_byte_information.rb +64 -0
- data/lib/cloudscale/plugins/net/sigar_packet_information.rb +84 -0
- data/lib/cloudscale/plugins/plugin.rb +252 -0
- data/lib/cloudscale/plugins/postgres/postgres_server_status.rb +148 -0
- data/lib/cloudscale/plugins/preops/plugin_apache_preop.rb +48 -0
- data/lib/cloudscale/plugins/preops/plugin_mongodb_preop.rb +105 -0
- data/lib/cloudscale/plugins/preops/plugin_postgres_preop.rb +70 -0
- data/lib/cloudscale/plugins/preops/plugin_preop.rb +51 -0
- data/lib/cloudscale/plugins/ram/sigar_ram_usage.rb +61 -0
- data/lib/cloudscale/plugins/ram/sigar_swap_usage.rb +61 -0
- data/lib/cloudscale/rest/rest_client.rb +178 -0
- data/lib/cloudscale/rest/rest_client_helper.rb +70 -0
- data/lib/cloudscale/schedule.rb +45 -0
- data/lib/cloudscale/store/agent/agent.store +2 -0
- data/lib/cloudscale/store/agent/agent_instance.store +11 -0
- data/lib/cloudscale/store/charts/cpuPercCombinedAreaChart +0 -0
- data/lib/cloudscale/store/charts/cpuPercIdleAreaChart +0 -0
- data/lib/cloudscale/store/charts/cpuPercNiceAreaChart +0 -0
- data/lib/cloudscale/store/charts/cpuPercSysAreaChart +0 -0
- data/lib/cloudscale/store/charts/cpuPercWaitAreaChart +0 -0
- data/lib/cloudscale/store/charts/diskFreeAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskFreeAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/diskReadBytesPerSecondAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskReadBytesPerSecondAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/diskReadsPerSecondAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskReadsPerSecondAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/diskTotalAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskTotalAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/diskUsedAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskUsedAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/diskWriteBytesPerSecondAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskWriteBytesPerSecondAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/diskWritesPerSecondAreaChart- +0 -0
- data/lib/cloudscale/store/charts/diskWritesPerSecondAreaChart-dev +0 -0
- data/lib/cloudscale/store/charts/ramFreeAreaChart +0 -0
- data/lib/cloudscale/store/charts/ramTotalAreaChart +0 -0
- data/lib/cloudscale/store/charts/ramUsedAreaChart +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-en0 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-en1 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-en2 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-en4 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/receivedBytesChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-en0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-en1 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-en2 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-en4 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-en0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-en1 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-en2 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-en4 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsDroppedChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-en0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-en1 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-en2 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-en4 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/receivedPacketsErrorChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-en0 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-en1 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-en2 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-en4 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/sendBytesChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-en0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-en1 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-en2 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-en4 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-en0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-en1 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-en2 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-en4 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsDroppedChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-bridge0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-en0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-en1 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-en2 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-en4 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-lo0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-p2p0 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-vmnet1 +0 -0
- data/lib/cloudscale/store/charts/sendPacketsErrorChart-vmnet8 +0 -0
- data/lib/cloudscale/store/charts/swapFreeAreaChart +0 -0
- data/lib/cloudscale/store/charts/swapTotalAreaChart +0 -0
- data/lib/cloudscale/store/charts/swapUsedAreaChart +0 -0
- data/lib/cloudscale/store/data/agent_unit.store +21 -0
- data/lib/cloudscale/store/plugin/token +1 -0
- data/lib/cloudscale/store/plugin_components.store +268 -0
- data/lib/cloudscale/store/plugin_menu.store +80 -0
- data/lib/cloudscale/store/rest/settings.yml +3 -0
- data/lib/test/agent/init_test.rb +18 -0
- data/lib/test/dynamicops/test_dynamic_ops.rb +90 -0
- data/lib/test/dynamicops/test_static_ops.rb +81 -0
- data/lib/test/model/constants/agent_store_test.rb +20 -0
- data/lib/test/model/constants/agent_unit_store_test.rb +20 -0
- data/lib/test/model/constants/setup/display_unit_store_test.rb +22 -0
- data/lib/test/model/constants/statistic_store_test.rb +21 -0
- data/lib/test/model/measurement/settings/chart_settings_test.rb +33 -0
- data/lib/test/model/statistic/create_statistic_test.rb +28 -0
- data/lib/test/model/statistic/create_units_test.rb +49 -0
- data/lib/test/plugins/apache/apache2_server_status_test.rb +23 -0
- data/lib/test/plugins/java/jvm_status_test.rb +16 -0
- data/lib/test/plugins/mongo/mongo_db_stats.rb +17 -0
- data/lib/test/plugins/mongo/mongo_db_wrapper_test.rb +21 -0
- data/lib/test/plugins/mongo/mongo_server_replica_set.rb +17 -0
- data/lib/test/plugins/mongo/mongo_server_status_test.rb +37 -0
- data/lib/test/plugins/plugin_test.rb +74 -0
- data/lib/test/plugins/postgres/postgres_cluster_stats.rb +20 -0
- data/lib/test/plugins/postgres/postgres_wrapper_test.rb +20 -0
- data/lib/test/plugins/tomcat/tomcat_monitoring.rb +255 -0
- data/lib/test/rest/rest_client_test.rb +50 -0
- data/lib/test/sigar/sigar_test.rb +25 -0
- data/lib/test/stringUtils/common_test.rb +25 -0
- metadata +359 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/chart"
|
2
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/measurement"
|
3
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/value"
|
4
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/statistic"
|
5
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/unit"
|
6
|
+
require "#{File.dirname(__FILE__)}/../preops/plugin_preop"
|
7
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
8
|
+
|
9
|
+
##
|
10
|
+
#
|
11
|
+
# @author Johannes Hiemer, cloudscale.
|
12
|
+
#
|
13
|
+
##
|
14
|
+
module Cloudscale
|
15
|
+
module Plugins
|
16
|
+
class SigarNetByteInformation < Plugins::Plugin
|
17
|
+
attr_reader :menu, :receivedBytes, :sendBytes
|
18
|
+
|
19
|
+
def log
|
20
|
+
@log = Logger.new(STDOUT)
|
21
|
+
end
|
22
|
+
|
23
|
+
def is_enabled
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super
|
29
|
+
if is_enabled
|
30
|
+
menus = Plugins::PluginMenus.load_hash()
|
31
|
+
@menu = load_menu(menus["network"], "sendAndReceivedBytes")
|
32
|
+
|
33
|
+
hash = Plugins::PluginComponents.load_hash()
|
34
|
+
@receivedBytes = load_metric(hash["network"], "receivedBytes")
|
35
|
+
@sendBytes = load_metric(hash["network"], "sendBytes")
|
36
|
+
@sigar = Plugins::PluginPreop.instance.sigar
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def collect(agentInstanceId)
|
42
|
+
log.info("Calling Collect on SigarNetByteInformation")
|
43
|
+
iflist = @sigar.net_interface_list
|
44
|
+
|
45
|
+
iflist.each do |ifname|
|
46
|
+
ifconfig = @sigar.net_interface_config(ifname)
|
47
|
+
if (!ifname.include?(":"))
|
48
|
+
ifstat = @sigar.net_interface_stat(ifname)
|
49
|
+
begin
|
50
|
+
report(receivedBytes, menu, ifstat.rx_bytes, true, agentInstanceId, "receivedBytesChart-" + ifname,
|
51
|
+
"Received bytes " + ifname, "Total number of received bytes" , "area", "Time", "GB", "B", "s")
|
52
|
+
|
53
|
+
report(sendBytes, menu, ifstat.tx_bytes, true, agentInstanceId, "sendBytesChart-" + ifname,
|
54
|
+
"Send bytes " + ifname, "Total number of send bytes" , "area", "Time", "GB", "B", "s")
|
55
|
+
rescue Exception => e
|
56
|
+
puts e
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/chart"
|
2
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/measurement"
|
3
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/value"
|
4
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/statistic"
|
5
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/unit"
|
6
|
+
require "#{File.dirname(__FILE__)}/../preops/plugin_preop"
|
7
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
8
|
+
|
9
|
+
##
|
10
|
+
#
|
11
|
+
# @author Johannes Hiemer, cloudscale.
|
12
|
+
#
|
13
|
+
##
|
14
|
+
module Cloudscale
|
15
|
+
module Plugins
|
16
|
+
class SigarNetPacketInformation < Plugins::Plugin
|
17
|
+
attr_reader :menu, :receivedPackets, :receivedPacketsError, :receivedPacketsDropped, :sendPackets,
|
18
|
+
:sendPacketsError, :sendPacketsDropped
|
19
|
+
|
20
|
+
def log
|
21
|
+
@log = Logger.new(STDOUT)
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_enabled
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
super
|
30
|
+
if is_enabled
|
31
|
+
menus = Plugins::PluginMenus.load_hash()
|
32
|
+
@menu = load_menu(menus["network"], "packetStatistics")
|
33
|
+
|
34
|
+
hash = Plugins::PluginComponents.load_hash()
|
35
|
+
@receivedPackets = load_metric(hash["network"], "receivedPackets")
|
36
|
+
@receivedPacketsError = load_metric(hash["network"], "receivedPacketsError")
|
37
|
+
@receivedPacketsDropped = load_metric(hash["network"], "receivedPacketsDropped")
|
38
|
+
@sendPackets = load_metric(hash["network"], "sendPackets")
|
39
|
+
@sendPacketsError = load_metric(hash["network"], "sendPacketsError")
|
40
|
+
@sendPacketsDropped = load_metric(hash["network"], "sendPacketsDropped")
|
41
|
+
@sigar = Plugins::PluginPreop.instance.sigar
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def collect(agentInstanceId)
|
46
|
+
log.info("Calling Collect on SigarNetPacketInformation")
|
47
|
+
iflist = @sigar.net_interface_list
|
48
|
+
|
49
|
+
iflist.each do |ifname|
|
50
|
+
ifconfig = @sigar.net_interface_config(ifname)
|
51
|
+
if (!ifname.include?(":"))
|
52
|
+
ifstat = @sigar.net_interface_stat(ifname)
|
53
|
+
begin
|
54
|
+
report(receivedPackets, menu, ifstat.rx_packets, true, agentInstanceId, "receivedPacketsChart-" + ifname,
|
55
|
+
"Received packets " + ifname,
|
56
|
+
"Total number of received packets" , "area", "Time", "Number of Packets", "c", "s")
|
57
|
+
report(receivedPacketsError, menu, ifstat.rx_errors, true, agentInstanceId, "receivedPacketsErrorChart-" + ifname,
|
58
|
+
"Received packet errors " + ifname,
|
59
|
+
"Total number of received packet errors" , "area", "Time", "Number of Packets", "c", "s")
|
60
|
+
report(receivedPacketsDropped, menu, ifstat.rx_dropped, true, agentInstanceId, "receivedPacketsDroppedChart-" + ifname,
|
61
|
+
"Received packet dropped " + ifname,
|
62
|
+
"Total number of received packet dropped" , "area", "Time", "Number of Packets", "c", "s")
|
63
|
+
|
64
|
+
report(sendPackets, menu, ifstat.tx_packets, true, agentInstanceId, "sendPacketsChart-" + ifname,
|
65
|
+
"Send packets " + ifname,
|
66
|
+
"Total number of send packets" , "area", "Time", "Number of Packets", "c", "s")
|
67
|
+
report(sendPacketsError, menu, ifstat.tx_errors, true, agentInstanceId, "sendPacketsErrorChart-" + ifname,
|
68
|
+
"Send packet errors " + ifname,
|
69
|
+
"Total number of send packet errors" , "area", "Time", "Number of Packets", "c", "s")
|
70
|
+
|
71
|
+
report(sendPacketsDropped, menu, ifstat.tx_dropped, true, agentInstanceId, "sendPacketsDroppedChart-" + ifname,
|
72
|
+
"Send packet dropped " + ifname,
|
73
|
+
"Total number of send packet dropped" , "area", "Time", "Number of Packets", "c", "s")
|
74
|
+
rescue Exception => e
|
75
|
+
puts e
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
require "fsdb"
|
2
|
+
require "yaml/store"
|
3
|
+
require "logger"
|
4
|
+
require "#{File.dirname(__FILE__)}/../monitor/agent/init_components"
|
5
|
+
require "#{File.dirname(__FILE__)}/../monitor/agent/init_menus"
|
6
|
+
require "#{File.dirname(__FILE__)}/../monitor/model/constants/agent_instance_store"
|
7
|
+
require "#{File.dirname(__FILE__)}/../rest/rest_client"
|
8
|
+
|
9
|
+
##
|
10
|
+
#
|
11
|
+
# @author Johannes Hiemer, cloudscale.
|
12
|
+
#
|
13
|
+
##
|
14
|
+
module Cloudscale
|
15
|
+
module Plugins
|
16
|
+
class Plugin
|
17
|
+
|
18
|
+
attr_accessor :log, :plugins, :statistics, :units, :chartSettings, :client, :local_chart_db, :value_store
|
19
|
+
@plugins = Set.new
|
20
|
+
|
21
|
+
def self.log
|
22
|
+
@log = Logger.new(STDOUT)
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize()
|
26
|
+
@local_chart_db = FSDB::Database.new("#{File.dirname(__FILE__)}/../store/charts")
|
27
|
+
@value_store = Hash.new
|
28
|
+
@client = RestClientWrapper.instance
|
29
|
+
@statistics = client.list("statistics")
|
30
|
+
@units = client.list("units")
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.reset(agentInstanceId)
|
34
|
+
resetRestEndpoint('coredatas', agentInstanceId, 'Coredata')
|
35
|
+
resetRestEndpoint('tables', agentInstanceId, 'Table')
|
36
|
+
resetRestEndpoint('charts', agentInstanceId, 'Chart')
|
37
|
+
|
38
|
+
Monitor::InitComponents.remove_components()
|
39
|
+
Monitor::InitMenus.remove_menus()
|
40
|
+
|
41
|
+
remove_measurements(agentInstanceId)
|
42
|
+
remove_agenInstance(agentInstanceId)
|
43
|
+
|
44
|
+
|
45
|
+
local_chart_db = FSDB::Database.new("#{File.dirname(__FILE__)}/../store/charts/")
|
46
|
+
local_chart_db.fetch.each do | element |
|
47
|
+
local_chart_db.delete(element)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.remove(agentInstanceId)
|
52
|
+
reset(agentInstanceId)
|
53
|
+
|
54
|
+
resetRestEndpoint('components', agentInstanceId, 'Components')
|
55
|
+
resetRestEndpoint('agentInstanceMenus', agentInstanceId, 'Agent Insntance Menus')
|
56
|
+
|
57
|
+
Constants::AgentInstance.remove()
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.resetRestEndpoint(entityRel, agentInstanceId, entityName)
|
61
|
+
client = RestClientWrapper.instance
|
62
|
+
|
63
|
+
entities = client.searchAny(entityRel,"findByAgentInstanceId",
|
64
|
+
{ :agentInstanceId => agentInstanceId })
|
65
|
+
|
66
|
+
puts "Found #{entityName} elements for Agent (#{agentInstanceId}): #{entities["content"].length.to_s}"
|
67
|
+
puts " Starting to delete all elements..."
|
68
|
+
|
69
|
+
entities["content"].each do | entity |
|
70
|
+
client.delete(entityRel, RestClientWrapper.load_entity_id(entity))
|
71
|
+
end
|
72
|
+
|
73
|
+
puts " Deleting all elements was successful \n\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.remove_agenInstance(agentInstanceId)
|
77
|
+
puts "Removing AgentInstance completely:\n\n"
|
78
|
+
|
79
|
+
client = RestClientWrapper.instance
|
80
|
+
agent_instance = client.searchOne('agentInstances',
|
81
|
+
'findByAgentInstanceId', { :id => agentInstanceId })
|
82
|
+
|
83
|
+
client.delete('agentInstances', RestClientWrapper.load_entity_id(agent_instance))
|
84
|
+
|
85
|
+
puts " Deleting AgentInstance was successful \n\n"
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.remove_measurements(agentInstanceId)
|
89
|
+
puts "Removing Measurement elements for Agent (#{agentInstanceId}):\n\n"
|
90
|
+
puts " Starting to delete all elements..."
|
91
|
+
|
92
|
+
client = RestClientWrapper.instance
|
93
|
+
client.customDelete("measurements", "removeByAgentInstanceId", { :agentInstanceId => agentInstanceId })
|
94
|
+
|
95
|
+
puts " Deleting all elements was successful \n\n"
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.plugins
|
99
|
+
@plugins
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.inherited(klass)
|
103
|
+
@plugins << klass
|
104
|
+
#log.debug("Initialize for " << klass.to_s)
|
105
|
+
end
|
106
|
+
|
107
|
+
def load_metric(component, name)
|
108
|
+
component["metrics"].each { | metric |
|
109
|
+
if (metric["name"] == name)
|
110
|
+
return metric
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
def load_menu(menu, id)
|
116
|
+
menu["subItems"].each { | item |
|
117
|
+
if (item["menuId"] == id)
|
118
|
+
return item
|
119
|
+
end
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
def load_unit_id(id)
|
124
|
+
unit = load_unit(@units["content"], id)
|
125
|
+
if (unit != nil)
|
126
|
+
unit["unitId"]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def load_unit(units, id)
|
131
|
+
if (units.is_a?(Array))
|
132
|
+
units.each { | unit |
|
133
|
+
if (unit["unitId"] == id)
|
134
|
+
return unit
|
135
|
+
end
|
136
|
+
}
|
137
|
+
end
|
138
|
+
return nil
|
139
|
+
end
|
140
|
+
|
141
|
+
def load_statistic_id(id)
|
142
|
+
statistic = load_statistic(@statistics["content"], id)
|
143
|
+
if (statistic != nil)
|
144
|
+
statistic["statisticId"]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def load_statistic(statistics, id)
|
149
|
+
if (statistics.is_a?(Array))
|
150
|
+
statistics.each { | statistic |
|
151
|
+
if (statistic["statisticId"] == id)
|
152
|
+
return statistic
|
153
|
+
end
|
154
|
+
}
|
155
|
+
end
|
156
|
+
return nil
|
157
|
+
end
|
158
|
+
|
159
|
+
def store(key, chart)
|
160
|
+
local_chart_db[key] = chart.to_h
|
161
|
+
end
|
162
|
+
|
163
|
+
def load(key)
|
164
|
+
return local_chart_db[key]
|
165
|
+
end
|
166
|
+
|
167
|
+
def persist_table(table, agentInstanceId, menu)
|
168
|
+
persist_entity(table, 'tables', agentInstanceId, menu["menuId"])
|
169
|
+
end
|
170
|
+
|
171
|
+
def persist_coredata(coredata, agentInstanceId, menu)
|
172
|
+
persist_entity(coredata, 'coredatas', agentInstanceId, menu["menuId"])
|
173
|
+
end
|
174
|
+
|
175
|
+
def persist_measurement(measurement, entityId, agentInstanceId, metricId)
|
176
|
+
if (measurement != nil && agentInstanceId != nil && metricId != nil)
|
177
|
+
measurement.metricId = metricId
|
178
|
+
measurement.chartId = entityId
|
179
|
+
measurement.agentInstanceId = agentInstanceId
|
180
|
+
return client.post('measurements', measurement)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def persist_chart(chart, agentInstanceId, menu)
|
185
|
+
hash = load(chart.name)
|
186
|
+
if (hash == nil)
|
187
|
+
persist_entity(chart, 'charts', agentInstanceId, menu["menuId"])
|
188
|
+
store(chart.name, chart)
|
189
|
+
return chart.to_h
|
190
|
+
else
|
191
|
+
return hash
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def persist_entity(entity, entityRel, agentInstanceId, menuId)
|
196
|
+
timestamp = Time.now.to_i * 1000
|
197
|
+
|
198
|
+
if (entity != nil && agentInstanceId != nil && menuId != nil)
|
199
|
+
entity.menuId = menuId
|
200
|
+
entity.agentInstanceId = agentInstanceId
|
201
|
+
|
202
|
+
entity_exists = client.searchOne(entityRel,"findByAgentInstanceIdAndMenuIdAndEntityId",
|
203
|
+
{ :agentInstanceId => agentInstanceId, :menuId => menuId, :entityId => entity.entityId })
|
204
|
+
|
205
|
+
if (entity_exists)
|
206
|
+
return client.put(entityRel, RestClientWrapper.load_entity_id(entity_exists), entity)
|
207
|
+
else
|
208
|
+
return client.post(entityRel, entity)
|
209
|
+
end
|
210
|
+
else
|
211
|
+
raise "plugin.persist_entity(): Insufficient number of paramters, or parameter values"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def report(metric, menu, value, useStore, agentInstanceId, chartName, chartLabel, chartDescription, chartType, chartxaxis, chartyaxis, unit, divisor)
|
216
|
+
if (value_store.key?(chartName) && useStore)
|
217
|
+
result = (value - value_store[chartName]) / 30
|
218
|
+
elsif (!value_store.key?(chartName) && useStore)
|
219
|
+
result = nil
|
220
|
+
else
|
221
|
+
result = value
|
222
|
+
end
|
223
|
+
|
224
|
+
if (result != nil)
|
225
|
+
timestamp = Time.now.to_i * 1000
|
226
|
+
statistic = load_statistic_id("avg");
|
227
|
+
if (unit != nil)
|
228
|
+
unit = load_unit_id(unit);
|
229
|
+
end
|
230
|
+
|
231
|
+
if (divisor != nil)
|
232
|
+
divisor = load_unit_id(divisor);
|
233
|
+
end
|
234
|
+
|
235
|
+
values = [Monitor::Value.new(statistic, unit, divisor, result)]
|
236
|
+
measurement = Monitor::Measurement.new(timestamp, values.to_dh)
|
237
|
+
|
238
|
+
chart = Monitor::Chart.new(chartName, chartLabel, chartDescription, chartType, chartxaxis, chartyaxis)
|
239
|
+
chartHash = persist_chart(chart, agentInstanceId, menu)
|
240
|
+
if (chartHash != nil)
|
241
|
+
persist_measurement(measurement, chartHash["entityId"], agentInstanceId, metric["metricId"])
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
if (useStore)
|
246
|
+
value_store[chartName] = value
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/chart"
|
2
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/measurement"
|
3
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/value"
|
4
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/statistic"
|
5
|
+
require "#{File.dirname(__FILE__)}/../../monitor/model/measurement/unit"
|
6
|
+
#require "#{File.dirname(__FILE__)}/../preops/plugin_postgres_preop"
|
7
|
+
require "#{File.dirname(__FILE__)}/../plugin"
|
8
|
+
|
9
|
+
##
|
10
|
+
#
|
11
|
+
# @author Johannes Hiemer, cloudscale.
|
12
|
+
#
|
13
|
+
##
|
14
|
+
module Cloudscale
|
15
|
+
module Plugins
|
16
|
+
class PostgresServerStatus < Plugins::Plugin
|
17
|
+
attr_reader :menu_generalInformationm, :menu_numBackends, :menu_transactionInformation, :menu_bulkOps, :menu_rowStats,
|
18
|
+
:numBackends, :xactCommit, :xactRollback, :xactTotal, :blksRead, :blksHit,
|
19
|
+
:generalInformation, :rowsSelectIdx, :rowsSelectScan, :rowInserts, :rowUpdated, :rowDeleted, :rowTotal
|
20
|
+
def log
|
21
|
+
@log = Logger.new(STDOUT)
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_enabled
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
super
|
30
|
+
if is_enabled
|
31
|
+
menus = Plugins::PluginMenus.load_hash()
|
32
|
+
@menu_generalInformation = load_menu(menus["pgDatabaseStats"], "generalInformation")
|
33
|
+
@menu_numBackends = load_menu(menus["pgDatabaseStats"], "numBackends")
|
34
|
+
@menu_transactionInformation = load_menu(menus["pgDatabaseStats"], "transactionInformation")
|
35
|
+
@menu_bulkOps = load_menu(menus["pgDatabaseStats"], "bulkOps")
|
36
|
+
@menu_rowStats = load_menu(menus["pgTableStats"], "rowStats")
|
37
|
+
|
38
|
+
@connection = Plugins::PostgresDbWrapper.instance.connection
|
39
|
+
components = Plugins::PluginComponents.load_hash()
|
40
|
+
@numBackends = load_metric(components["pgDatabaseStats"], "numBackends")
|
41
|
+
@xactCommit = load_metric(components["pgDatabaseStats"], "xactCommit")
|
42
|
+
@xactRollback = load_metric(components["pgDatabaseStats"], "xactRollback")
|
43
|
+
@xactTotal = load_metric(components["pgDatabaseStats"], "xactTotal")
|
44
|
+
@blksRead = load_metric(components["pgDatabaseStats"], "blksRead")
|
45
|
+
@blksHit = load_metric(components["pgDatabaseStats"], "blksHit")
|
46
|
+
|
47
|
+
@generalInformation = load_metric(components["pgDatabaseStats"], "generalInformation")
|
48
|
+
|
49
|
+
@rowsSelectIdx = load_metric(components["pgTableStats"], "rowsSelectIdx")
|
50
|
+
@rowsSelectScan = load_metric(components["pgTableStats"], "rowsSelectScan")
|
51
|
+
@rowInserts = load_metric(components["pgTableStats"], "rowInserts")
|
52
|
+
@rowUpdated = load_metric(components["pgTableStats"], "rowUpdated")
|
53
|
+
@rowDeleted = load_metric(components["rowDeleted"], "rowDeleted")
|
54
|
+
@rowTotal = load_metric(components["rowTotal"], "rowTotal")
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def collect(agentInstanceId)
|
60
|
+
log.info("Calling Collect on MongoServerStatus")
|
61
|
+
report_general_information(agentInstanceId)
|
62
|
+
report_database_stats(agentInstanceId)
|
63
|
+
report_table_stats(agentInstanceId)
|
64
|
+
end
|
65
|
+
|
66
|
+
def report_database_stats(agentInstanceId)
|
67
|
+
result = @connection.exec('SELECT sum(idx_tup_fetch) AS "rows_select_idx",
|
68
|
+
sum(seq_tup_read) AS "rows_select_scan",
|
69
|
+
sum(n_tup_ins) AS "rows_insert",
|
70
|
+
sum(n_tup_upd) AS "rows_update",
|
71
|
+
sum(n_tup_del) AS "rows_delete",
|
72
|
+
(sum(idx_tup_fetch) + sum(seq_tup_read) + sum(n_tup_ins) + sum(n_tup_upd) + sum(n_tup_del)) AS "rows_total"
|
73
|
+
FROM pg_stat_all_tables;')
|
74
|
+
row = result[0]
|
75
|
+
|
76
|
+
report(rowsSelectIdx, menu_rowStats, row['rows_select_idx'], false, agentInstanceId, "rowsSelectIdxChart",
|
77
|
+
"Select indexes", "Select indexes across all tables in the database", "area", "Time", "Count", "c", nil)
|
78
|
+
|
79
|
+
report(rowsSelectScan, menu_rowStats, row['rows_select_scan'], false, agentInstanceId, "rowsSelectScanChart",
|
80
|
+
"Row select scan", "Row select scans across all tables in the database", "area", "Time", "Count", "c", nil)
|
81
|
+
|
82
|
+
report(rowInserts, menu_rowStats, row['rows_insert'], false, agentInstanceId, "rowInsertsChart",
|
83
|
+
"Row inserts", "Row inserts across all tables in the database", "area", "Time", "Count", "c", nil)
|
84
|
+
|
85
|
+
report(rowUpdated, menu_rowStats, row['rows_update'], false, agentInstanceId, "rowUpdatedChart",
|
86
|
+
"Row updates", "Row updates across all tables in the database", "area", "Time", "Count", "c", nil)
|
87
|
+
|
88
|
+
report(rowDeleted, menu_rowStats, row['rows_delete'], false, agentInstanceId, "rowDeletedChart",
|
89
|
+
"Row deletes", "Row deletes across all tables in the database", "area", "Time", "Count", "c", nil)
|
90
|
+
|
91
|
+
report(rowTotal, menu_rowStats, row['rows_total'], false, agentInstanceId, "rowTotalChart",
|
92
|
+
"Rows affected", "Rows affected across all tables in the database", "area", "Time", "Count", "c", nil)
|
93
|
+
end
|
94
|
+
|
95
|
+
def report_table_stats(agentInstanceId)
|
96
|
+
result = @connection.exec('SELECT sum(numbackends) AS "numbackends",
|
97
|
+
sum(xact_commit) AS "xact_commit",
|
98
|
+
sum(xact_rollback) AS "xact_rollback",
|
99
|
+
sum(xact_commit+xact_rollback) AS "xact_total",
|
100
|
+
sum(blks_read) AS "blks_read",
|
101
|
+
sum(blks_hit) AS "blks_hit"
|
102
|
+
FROM pg_stat_database;')
|
103
|
+
row = result[0]
|
104
|
+
|
105
|
+
report(xactCommit, menu_transactionInformation, row['xact_commit'], false, agentInstanceId, "xactCommitChart",
|
106
|
+
"Transaction commits", "Transaction commits across all tables in the database", "area", "Time", "Count", "c", nil)
|
107
|
+
|
108
|
+
report(xactRollback, menu_transactionInformation, row['xact_rollback'], false, agentInstanceId, "xactRollbackChart",
|
109
|
+
"Transaction rollback", "Transaction rollback across all tables in the database", "area", "Time", "Count", "c", nil)
|
110
|
+
|
111
|
+
report(xactTotal, menu_transactionInformation, row['xact_total'], false, agentInstanceId, "xactTotalChart",
|
112
|
+
"Transactions total", "Transactions total across all tables in the database", "area", "Time", "Count", "c", nil)
|
113
|
+
|
114
|
+
report(blksRead, menu_bulkOps, row['blks_read'], false, agentInstanceId, "blksReadChart",
|
115
|
+
"Bulk reads", "Bulk reads across all tables in the database", "area", "Time", "Count", "c", nil)
|
116
|
+
|
117
|
+
report(blksHit, menu_bulkOps, row['blks_hit'], false, agentInstanceId, "blksHitChart",
|
118
|
+
"Bulk hits", "Bulk hits across all tables in the database", "area", "Time", "Count", "c", nil)
|
119
|
+
end
|
120
|
+
|
121
|
+
def report_general_information(agentInstanceId)
|
122
|
+
result = @connection.exec('SELECT datid,
|
123
|
+
datname, pid, usesysid, usename,
|
124
|
+
client_addr, client_hostname,
|
125
|
+
client_port, backend_start, state, waiting
|
126
|
+
FROM pg_stat_activity;')
|
127
|
+
row = result[0]
|
128
|
+
|
129
|
+
body = Array.new
|
130
|
+
body.push(["DatId", row['datid']])
|
131
|
+
body.push(["Datname", row['datname']])
|
132
|
+
body.push(["Pid", row['pid']])
|
133
|
+
body.push(["Use Sysid", row['usesysid']])
|
134
|
+
body.push(["usename", row['usename']])
|
135
|
+
body.push(["client_addr", row['client_addr']])
|
136
|
+
body.push(["client_hostname", row['client_hostname']])
|
137
|
+
body.push(["client_port", row['client_port']])
|
138
|
+
body.push(["backend_start", row['backend_start']])
|
139
|
+
body.push(["state", row['state']])
|
140
|
+
body.push(["waiting", row['waiting']])
|
141
|
+
mongo_general_inf_table = Monitor::Table.new("generalInformationPostgres", "Postgres General Information", nil, body, "compact")
|
142
|
+
mongo_general_inf_table.caption = "General Information regarding your Postgres Instance"
|
143
|
+
|
144
|
+
persist_table(mongo_general_inf_table, agentInstanceId, menu_generalInformation)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|