diff --git a/resources/libraries/update_manager_config.rb b/resources/libraries/update_manager_config.rb index 0ca9d57..b8bc486 100644 --- a/resources/libraries/update_manager_config.rb +++ b/resources/libraries/update_manager_config.rb @@ -1,6 +1,6 @@ module Rbmonitor module Helpers - + def update_manager_config(resource) ########################## @@ -12,9 +12,9 @@ def update_manager_config(resource) monitor_dg = Chef::DataBagItem.load("rBglobal", "monitors") rescue monitor_dg={} snmp_monitors = [] begin - if monitor_dg["monitors"].nil? or monitor_dg["monitors"].include?("load_1") + if monitor_dg["monitors"].nil? or monitor_dg["monitors"].include?("load_1") snmp_monitors.push({"name": "load_1", "oid": "UCD-SNMP-MIB::laLoad.1", "unit": "%"},) - node.default[:redborder][:monitor][:count] = node.default[:redborder][:monitor][:count] + 1 + node.default[:redborder][:monitor][:count] = node.default[:redborder][:monitor][:count] + 1 end if monitor_dg["monitors"].nil? or monitor_dg["monitors"].include?("cpu") snmp_monitors.push({"name": "cpu_idle", "oid": "UCD-SNMP-MIB::ssCpuIdle.0", "send": 0, "unit": "%"},) @@ -79,21 +79,21 @@ def update_manager_config(resource) if monitor_dg["monitors"].nil? or monitor_dg["monitors"].include?("disk_raw_load") snmp_monitors.push({"name": "disk_raw_load", "system": "snmptable -v 2c -c redborder 127.0.0.1 diskIOTable|grep ' dm-2 ' | awk '{print $7}'", "unit": "%"},) node.default[:redborder][:monitor][:count] = node.default[:redborder][:monitor][:count] + 1 - end + end elsif File.exist?("/dev/mapper/vg_rbdata-lv_raw") if monitor_dg["monitors"].nil? or monitor_dg["monitors"].include?("disk_raw") snmp_monitors.push({"name": "disk_raw", "oid": "UCD-SNMP-MIB::dskPercent.2", "unit": "%"},) node.default[:redborder][:monitor][:count] = node.default[:redborder][:monitor][:count] + 1 end end - rescue + rescue puts "Error, can't access to SNMP monitors, skipping snmp monitors" end # IPMI monitors monitor_dg = Chef::DataBagItem.load("rBglobal", "monitors") rescue monitor_dg={} ipmi_monitors = [] - + begin if File.exist?("/dev/ipmi0") or File.exist?("/dev/ipmi/0") or File.exist?("/dev/ipmidev/0") if monitor_dg["monitors"].nil? or monitor_dg["monitors"].include?("system_temp") @@ -132,20 +132,28 @@ def update_manager_config(resource) #Calculate used memory per service memory_monitors = ["/* MEMORY PER SERVICE */"] begin - enabled_services = node.default["redborder"]["services"].map { |service| - service[0] if service[1] - } - enabled_services.delete_if { |service| service == nil } - enabled_services.each do |service| - service_list = %w[ druid-broker druid-coordinator druid-historical druid-middlemanager druid-overlord druid-realtime http2k kafka n2klocd redborder-nmsp redborder-postgresql webui zookeeper f2k ] - if service_list.include? service - serv = service.gsub("-", "_") - memory_monitors.push({ "name" => "memory_total_#{serv}", "unit" => "kB", "integer" => 1, "send" => 0, - "system" => "sudo /usr/lib/redborder/bin/rb_mem.sh -n #{service} 2>/dev/null" } ) - memory_monitors.push({ "name" => "memory_#{serv}", "op" => "100*(memory_total_#{serv})/memory_total", "unit" => "%"} ) - node.default[:redborder][:monitor][:count] = node.default[:redborder][:monitor][:count] + 2 + enabled_services = node.default["redborder"]["services"] + service_list = %w[druid-broker druid-coordinator druid-historical druid-middlemanager druid-overlord druid-realtime http2k kafka n2klocd redborder-nmsp redborder-postgresql webui zookeeper f2k] + + #In case user modifies a service + overwritten_services = node.attributes["redborder"]["services"] + overwritten_services.each do |service, value| + if value == false + enabled_services.delete(service) + elsif value == true && service_list.include?(service) + enabled_services[service] = true end end + + enabled_services.select! { |k,v| v==true && service_list.include?(k) } + + enabled_services.keys.each do |service| + serv = service.gsub("-", "_") + memory_monitors.push({ "name" => "memory_total_#{serv}", "unit" => "kB", "integer" => 1, "send" => 0, + "system" => "sudo /usr/lib/redborder/bin/rb_mem.sh -n #{service} 2>/dev/null" }) + memory_monitors.push({ "name" => "memory_#{serv}", "op" => "100*(memory_total_#{serv})/memory_total", "unit" => "%" }) + node.default[:redborder][:monitor][:count] += 2 + end rescue puts "Can't access to redborder service list, skipping memory services monitorization" end @@ -174,6 +182,6 @@ def update_manager_config(resource) node.default["redborder"]["monitor"]["config"][:sensors].push(manager_sensor) end - + end -end \ No newline at end of file +end