Module: HttpLoader::Harness::Formatter
- Extended by:
- T::Helpers, T::Sig
- Included in:
- HttpLoader::Harness
- Defined in:
- lib/http_loader/harness/formatter.rb
Overview
Formatter handles printing load test statistics dynamically and robustly.
Instance Method Summary collapse
- #extract_client_stats ⇒ Object
- #extract_server_stats ⇒ Object
- #format_kb_conn(kilo, connections, pid) ⇒ Object
- #log_table_row(params) ⇒ Object
- #print_combined_stats(active, c_cpu, c_th, c_m) ⇒ Object
- #print_startup_banner ⇒ Object
- #print_table_header ⇒ Object
Instance Method Details
#extract_client_stats ⇒ Object
75 76 77 78 79 |
# File 'lib/http_loader/harness/formatter.rb', line 75 def extract_client_stats c_cpu, c_mem, _c_kb, c_th = @monitor.process_stats(@pm.client_pid) active_c = @monitor.count_established_connections(@pm.client_pid) [active_c, c_cpu, c_th, c_mem] end |
#extract_server_stats ⇒ Object
67 68 69 70 71 72 |
# File 'lib/http_loader/harness/formatter.rb', line 67 def extract_server_stats s_cpu, s_mem, s_kb, s_th = @monitor.process_stats(@pm.server_pid) active_s = @monitor.count_established_connections(@pm.server_pid) s_conn = format_kb_conn(s_kb, active_s, @pm.server_pid) [s_cpu, s_mem, s_th, s_conn] end |
#format_kb_conn(kilo, connections, pid) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/http_loader/harness/formatter.rb', line 46 def format_kb_conn(kilo, connections, pid) return 'EXTERNAL' if pid.nil? return 'N/A' if connections.zero? || connections.negative? "#{(kilo / connections).round(2)} KB" end |
#log_table_row(params) ⇒ Object
39 40 41 42 43 |
# File 'lib/http_loader/harness/formatter.rb', line 39 def log_table_row(params) puts format('%<t>-10s | %<ac>-11s | %<sc>-16s | %<sm>-14s | %<sk>-14s | %<cc>-16s | %<cm>-14s | %<ck>-14s', t: params[:t], ac: params[:ac], sc: params[:sc], sm: params[:sm], sk: params[:sk], cc: params[:cc], cm: params[:cm], ck: params[:ck]) end |
#print_combined_stats(active, c_cpu, c_th, c_m) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/http_loader/harness/formatter.rb', line 54 def print_combined_stats(active, c_cpu, c_th, c_m) s_cpu, s_mem, s_th, s_conn = extract_server_stats _cc, _cm, c_kb, _ct = @monitor.process_stats(@pm.client_pid) c_conn = format_kb_conn(c_kb, active, @pm.client_pid) log_table_row( t: Time.now.utc.strftime('%H:%M:%S'), ac: active.to_s, sc: "#{s_cpu}% / #{s_th}", sm: s_mem, sk: s_conn, cc: "#{c_cpu}% / #{c_th}", cm: c_m, ck: c_conn ) end |
#print_startup_banner ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/http_loader/harness/formatter.rb', line 16 def msg = if @config.target_urls.size > 1 "**MULTIPLE TARGETS** (#{@config.target_urls.size} URLs)." elsif @config.target_urls.size == 1 "**EXTERNAL URL** #{@config.target_urls.first}." elsif @config.use_https '**HTTPS**.' else '**HTTP**.' end puts "[Harness] Starting test with #{@config.connections} connections to #{msg}" end |
#print_table_header ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/http_loader/harness/formatter.rb', line 30 def print_table_header puts '[Harness] Monitoring resources (Press Ctrl+C to stop)...' puts '-' * 125 puts 'Time (UTC) | Real Conns | Srv CPU/Thrds | Srv Mem | Srv Mem/Conn | ' \ 'Cli CPU/Thrds | Cli Mem | Cli Mem/Conn ' puts '-' * 125 end |