module GitLab::Exporter::Utils
Helper methods, some stuff was copied from ActiveSupport
Public Class Methods
camel_case_string(str)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 26 def camel_case_string(str) str.gsub(/(?:_|^)([a-z\d]*)/i) { $1.capitalize } # rubocop:disable Style/PerlBackrefs end
deep_symbolize_hash_keys(hash)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 31 def deep_symbolize_hash_keys(hash) deep_transform_keys_in_object(hash, &:to_sym) end
deep_transform_keys_in_object(object) { |key| ... }
click to toggle source
# File lib/gitlab_exporter/util.rb, line 36 def deep_transform_keys_in_object(object, &block) case object when Hash object.keys.each do |key| value = object.delete(key) object[yield(key)] = deep_transform_keys_in_object(value, &block) end object when Array object.map! { |e| deep_transform_keys_in_object(e, &block) } else object end end
exec_pgrep(pattern)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 61 def exec_pgrep(pattern) `pgrep -fl "#{pattern}"` end
pgrep(pattern)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 52 def pgrep(pattern) # pgrep will include the PID of the shell, so strip that out exec_pgrep(pattern).split("\n").each_with_object([]) do |line, arr| pid, name = line.split(" ") arr << pid if name != "sh" end end
system_uptime()
click to toggle source
# File lib/gitlab_exporter/util.rb, line 66 def system_uptime File.read("/proc/uptime").split(" ")[0].to_f end
wrap_in_array(object)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 71 def wrap_in_array(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary || [object] else [object] end end
Private Instance Methods
camel_case_string(str)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 26 def camel_case_string(str) str.gsub(/(?:_|^)([a-z\d]*)/i) { $1.capitalize } # rubocop:disable Style/PerlBackrefs end
deep_symbolize_hash_keys(hash)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 31 def deep_symbolize_hash_keys(hash) deep_transform_keys_in_object(hash, &:to_sym) end
deep_transform_keys_in_object(object) { |key| ... }
click to toggle source
# File lib/gitlab_exporter/util.rb, line 36 def deep_transform_keys_in_object(object, &block) case object when Hash object.keys.each do |key| value = object.delete(key) object[yield(key)] = deep_transform_keys_in_object(value, &block) end object when Array object.map! { |e| deep_transform_keys_in_object(e, &block) } else object end end
exec_pgrep(pattern)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 61 def exec_pgrep(pattern) `pgrep -fl "#{pattern}"` end
pgrep(pattern)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 52 def pgrep(pattern) # pgrep will include the PID of the shell, so strip that out exec_pgrep(pattern).split("\n").each_with_object([]) do |line, arr| pid, name = line.split(" ") arr << pid if name != "sh" end end
system_uptime()
click to toggle source
# File lib/gitlab_exporter/util.rb, line 66 def system_uptime File.read("/proc/uptime").split(" ")[0].to_f end
wrap_in_array(object)
click to toggle source
# File lib/gitlab_exporter/util.rb, line 71 def wrap_in_array(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary || [object] else [object] end end