Module: Eye::Controller::Helpers

Included in:
Eye::Controller
Defined in:
lib/eye/controller/helpers.rb

Instance Method Summary collapse

Instance Method Details

#all_groupsObject



70
71
72
73
74
75
76
77
# File 'lib/eye/controller/helpers.rb', line 70

def all_groups
  groups = []
  @applications.each do |app|
    groups += app.groups.to_a
  end

  groups
end

#all_processesObject



61
62
63
64
65
66
67
68
# File 'lib/eye/controller/helpers.rb', line 61

def all_processes
  processes = []
  all_groups.each do |gr|
    processes += gr.processes.to_a
  end

  processes
end

#application_by_name(name) ⇒ Object



56
57
58
59
# File 'lib/eye/controller/helpers.rb', line 56

def application_by_name(name)
  name = name.to_s
  @applications.detect { |c| c.name == name }
end

#cache_strObject



17
18
19
# File 'lib/eye/controller/helpers.rb', line 17

def cache_str
  all_processes.map{ |p| "#{p.full_name}=#{p.state}" } * "\n"
end

#find_nearest_process(name, group_name = nil, app_name = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/eye/controller/helpers.rb', line 31

def find_nearest_process(name, group_name = nil, app_name = nil)
  return process_by_full_name(name) if name.include?(':')

  if app_name
    app = application_by_name(app_name)
    app.groups.each do |gr|
      p = gr.processes.detect { |c| c.name == name }
      return p if p
    end
  end

  if group_name
    gr = group_by_name(group_name)
    p = gr.processes.detect { |c| c.name == name }
    return p if p
  end

  process_by_name(name)
end

#group_by_name(name) ⇒ Object



51
52
53
54
# File 'lib/eye/controller/helpers.rb', line 51

def group_by_name(name)
  name = name.to_s
  all_groups.detect { |c| c.name == name }
end

#process_by_full_name(name) ⇒ Object



26
27
28
29
# File 'lib/eye/controller/helpers.rb', line 26

def process_by_full_name(name)
  name = name.to_s
  all_processes.detect { |c| c.full_name == name }
end

#process_by_name(name) ⇒ Object



21
22
23
24
# File 'lib/eye/controller/helpers.rb', line 21

def process_by_name(name)
  name = name.to_s
  all_processes.detect { |c| c.name == name }
end

#save_cacheObject



11
12
13
14
15
# File 'lib/eye/controller/helpers.rb', line 11

def save_cache
  File.open(Eye::Local.cache_path, 'w') { |f| f.write(cache_str) }
rescue => ex
  log_ex(ex)
end

#set_proc_lineObject



3
4
5
6
7
8
9
# File 'lib/eye/controller/helpers.rb', line 3

def set_proc_line
  str = Eye::PROCLINE
  str += " [#{@applications.map(&:name) * ', '}]" if @applications.present?
  str += " (v #{ENV['EYE_V']})" if ENV['EYE_V']
  str += " (in #{Eye::Local.dir})"
  $0 = str
end

#short_treeObject

=> {‘group_name’ => {‘process_name’ => ‘pid_file’}}



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/eye/controller/helpers.rb', line 80

def short_tree
  res = {}
  @applications.each do |app|
    res2 = {}

    app.groups.each do |group|
      res3 = {}

      group.processes.each do |process|
        res3[process.name] = process[:pid_file_ex]
      end

      res2[group.name] = res3
    end

    res[app.name] = res2
  end

  res
end