Class: Deployinator::Views::Stats

Inherits:
Layout show all
Defined in:
lib/deployinator/views/stats.rb

Constant Summary collapse

@@ignored_stacks =
Deployinator.stats_ignored_stacks || []

Constants included from Helpers::StackTailHelpers

Helpers::StackTailHelpers::STACK_TAIL_VERSION

Constants included from Helpers

Helpers::RUN_LOG_PATH

Instance Attribute Summary

Attributes included from Helpers::PluginHelpers

#plugins

Instance Method Summary collapse

Methods inherited from Layout

#additional_bottom_body_html, #additional_header_html, #additional_top_body_html, #disabled_override, partial, #push_order, #set_stack, #tailer_loading_message

Methods included from Helpers::GitHelpers

#build_git_cmd, #get_git_head_rev, #get_git_head_rev_from_ls_output, #git_bump_version, #git_checkout_path, #git_clone, #git_filter_shas, #git_freshen_clone, #git_freshen_or_clone, #git_head_rev, #git_info_for_stack, #git_show_changed_files, #git_url, #github_list_committers, #is_git_repo, #use_github_diff, #which_github_host

Methods included from Helpers::StackTailHelpers

get_stack_tail_version, #stack_tail_version, #stack_tail_websocket_port

Methods included from Helpers::VersionHelpers

curl_get_url, get_build, get_version, get_version_by_url

Methods included from Helpers

#all_eof, #all_push_lock_info, #all_pushes_locked?, #announce, #average_duration, #can_remove_stack_lock?, #censor_cmd, #check_command_safety, #clean, #deploy_host?, #dev_context?, #diff, #diff_url, #environments, #get_deploy_target_status, #get_from_cache, #get_log, #get_run_logs, #get_stack_select, #head_build, #help_url, #help_url?, #http_host, #hyperlink, #init, #is_admin?, #link_stack_logfile, #lock_all_pushes, #lock_pushes, #log, #log_and_shout, #log_and_stream, #log_and_stream_error, #log_entries, #log_error, #log_string_to_file, #move_stack_logfile, #nice_time, #nicify_env, #not_dev?, #now, #push_lock_all_path, #push_lock_info, #push_lock_path, #pushes_locked?, #run_cmd, #run_cmd_safely, #run_cmd_with_retries, #run_log_path, #run_log_url, #runlog_filename, #runlog_thread_filename, #send_email, #stack, #strip_ws_to_nil, #timing_log, #unlock_all_pushes, #unlock_pushes, #with_timeout, #write_file, #write_to_cache

Methods included from Helpers::PluginHelpers

#notify_plugins, #raise_event, #register_plugins

Methods included from Helpers::ViewHelpers

#allowed_to_push_to_prod?, #groups, #log_lines, #log_to_hash, #logout_url, #my_entries, #my_url, #username

Instance Method Details

#deploysObject


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/deployinator/views/stats.rb', line 11

def deploys
  @deploys ||= begin
    log_to_hash({
      :no_global => false,
      :stack => Deployinator.stats_included_stacks,
      :env => "production|search|prod",
      :extragrep => Deployinator.stats_extra_grep,
      :no_limit => true,
      :limit => 10000
    })
   end
    # note that the stack param will help but will send bring back extra lines that matched
end

#inject_renamed_stacks(renamed_stacks) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/deployinator/views/stats.rb', line 29

def inject_renamed_stacks(renamed_stacks)
  return if nil == renamed_stacks

  renamed_stacks.each do |ops|
    previous_stack = ops[:previous_stack]
    new_stack_name = ops[:new_name]

    renamed_stack_data = log_to_hash(previous_stack)

    renamed_stack_data.each do |data|
      data[:stack] = new_stack_name
      deploys.push(data)
    end
  end
end

#per_dayObject


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/deployinator/views/stats.rb', line 45

def per_day
  inject_renamed_stacks(Deployinator.stats_renamed_stacks)

  original_zone = ENV["TZ"]
  ENV["TZ"] = "US/Eastern"

  early_day = Time.now.strftime("%Y-%m-%d")
  stack_days = deploys.inject({}) do |h, deploy|
    if deploy[:time] && deploy[:stack]
      if @@ignored_stacks.include?(deploy[:stack])
        # puts "SKIPPING " + deploy[:stack]
        # something breaks if you just next here so don't
      else
        day = Date.parse(deploy[:time].localtime.strftime("%Y-%m-%d"))
        early_day = day if day.to_s < early_day.to_s
        h[deploy[:stack]] ||= {}
        h[deploy[:stack]][day] ||= 0
        h[deploy[:stack]][day] += 1
      end
    end
    h
  end

  # fill in zero days
  day_seconds = 24 * 60 * 60
  (0..((Time.now - Time.parse(early_day.to_s)) / day_seconds).to_i).each do |days_ago|
    stack_days.keys.each do |stack|

      next if @@ignored_stacks.include?(stack)
      day = Date.parse((Time.now - (day_seconds * days_ago)).strftime("%Y-%m-%d"))
      stack_days[stack][day] ||= 0
    end
  end

  n = stack_days.keys.map do |stack|
    next if @@ignored_stacks.include?(stack)

    data = []
    json = []
    stack_days[stack].sort.reverse.each do |d,c|
      data << {:date => d, :count => c}
      json << [d.strftime("%s").to_i * 1000, c]
    end
    {:stack => stack, :data => data, :json => json.to_json}
  end

  ENV["TZ"] = original_zone

  n
end

#timingsObject


25
26
27
# File 'lib/deployinator/views/stats.rb', line 25

def timings
  deploys
end