finish add stress test
This commit is contained in:
parent
41edf2108c
commit
8665f2838c
|
@ -1,29 +1,64 @@
|
|||
class Admin::PlowController < ApplicationController
|
||||
class Admin::PlowController < OrbitAdminController
|
||||
include ReverseProxy::Controller
|
||||
SocketFile = "#{Rails.root}/tmp/plow.sock"
|
||||
Binary = File.expand_path("../../../../bin/plow", __FILE__)
|
||||
LogFile = "#{Rails.root}/tmp/plow_summary.log"
|
||||
before_action :setup_setting, only: [:setting, :save_setting]
|
||||
|
||||
def index
|
||||
# Assuming the WordPress server is being hosted on port 8080
|
||||
reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: '/' do |config|
|
||||
# We got a 404!
|
||||
# config.on_missing do |code, response|
|
||||
# redirect_to root_url and return
|
||||
# end
|
||||
|
||||
# There's also other callbacks:
|
||||
# - on_set_cookies
|
||||
# - on_connect
|
||||
# - on_response
|
||||
# - on_set_cookies
|
||||
# - on_success
|
||||
# - on_redirect
|
||||
# - on_missing
|
||||
# - on_error
|
||||
# - on_complete
|
||||
end
|
||||
end
|
||||
def show
|
||||
path = request.env['ORIGINAL_FULLPATH']
|
||||
reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: '/' do |config|
|
||||
path = request.env['ORIGINAL_FULLPATH']#.gsub("/admin/plow", "")
|
||||
reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: path do |config|
|
||||
end
|
||||
end
|
||||
def setting
|
||||
if File.exist?(LogFile)
|
||||
@logContent = File.read(LogFile).gsub("\n", "<br>").html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def save_setting
|
||||
@setting.update_attributes(params[:plow_setting].permit!)
|
||||
if File.exist?(SocketFile)
|
||||
if @plow_pid
|
||||
Process.kill(:INT, @plow_pid)
|
||||
end
|
||||
`rm #{SocketFile}`
|
||||
end
|
||||
if params['act'] == 'Start Test'
|
||||
uri = URI.parse(@setting.url)
|
||||
host = uri.host
|
||||
ip = @setting.ip
|
||||
concurrent = @setting.concurrent
|
||||
scheme = uri.scheme
|
||||
Thread.new do
|
||||
if !ip.blank?
|
||||
`#{Binary} #{scheme}://#{ip}#{uri.request_uri} --host=#{host} --listen=#{SocketFile} -c#{concurrent} --summary > #{LogFile}`
|
||||
else
|
||||
`#{Binary} #{@setting.url} --listen=#{SocketFile} -c#{concurrent} --summary > #{LogFile}`
|
||||
end
|
||||
end
|
||||
max_wait = 10
|
||||
while 1
|
||||
sleep(1)
|
||||
setup_setting
|
||||
max_wait -= 1
|
||||
if @enable_plow
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to action: :setting
|
||||
end
|
||||
|
||||
private
|
||||
def setup_setting
|
||||
@setting = PlowSetting.first
|
||||
@plow_pid = `fuser #{SocketFile}`.gsub(/\n/, '').to_i
|
||||
@enable_plow = @plow_pid > 0
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class PlowSetting
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :concurrent, type: Integer, :default => 1
|
||||
field :ip, type: String
|
||||
field :url, type: String
|
||||
end
|
|
@ -0,0 +1,45 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<% end %>
|
||||
<h3 class="sub-title"><%= t('client_management.stress_test') %></h3>
|
||||
<%= form_for @setting, :url => {:action => :save_setting}, :html => {:class => "form-horizontal contract-form main-forms"} do |f| %>
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted" for="url">Test Url</label>
|
||||
<div class="controls">
|
||||
<%= f.text_field :url, :class => 'input-large' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label muted" for="ip">IP</label>
|
||||
<div class="controls">
|
||||
<%= f.text_field :ip, :class =>'input-large' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label muted" for="concurrent">User Number</label>
|
||||
<div class="controls">
|
||||
<%= f.number_field :concurrent, :class => 'input-large' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if !@logContent.blank? %>
|
||||
<div class="control-group">
|
||||
<label class="control-label muted">Summary</label>
|
||||
<div class="controls">
|
||||
<%= @logContent %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-actions">
|
||||
<% if @enable_plow %>
|
||||
<%= f.submit 'Stop Test', :name => 'act', :class => 'btn btn-primary' %>
|
||||
<iframe src="/admin/plow/" width="100%" onload='javascript:(function(o){o.style.height=o.contentWindow.document.body.scrollHeight+"px";}(this));' style="height:200px;width:100%;border:none;overflow:hidden;" scrolling="no"></iframe>
|
||||
<% else %>
|
||||
<%= f.submit 'Start Test', :name => 'act', :class => 'btn btn-primary' %>
|
||||
<% end %>
|
||||
</div>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -7,6 +7,7 @@ en:
|
|||
upload_cert: Upload Cert
|
||||
cert_management: Cert Management
|
||||
client_management:
|
||||
stress_test: Stress Test
|
||||
select_all: "Select All"
|
||||
deselect_all: "Deselect All"
|
||||
get_template: "Get Template"
|
||||
|
|
|
@ -7,6 +7,7 @@ zh_tw:
|
|||
upload_cert: 上傳憑證
|
||||
cert_management: 憑證管理
|
||||
client_management:
|
||||
stress_test: 壓力測試
|
||||
select_all: "全選"
|
||||
deselect_all: "取消全選"
|
||||
get_template: "獲取版型"
|
||||
|
|
|
@ -7,6 +7,8 @@ Rails.application.routes.draw do
|
|||
# get "client_managements/contracts", to: 'client_managements#contracts'
|
||||
|
||||
match 'plow' => 'plow#index', via: [:get, :post, :put, :patch, :delete]
|
||||
get 'plow/setting' => 'plow#setting'
|
||||
patch 'plow/save_setting' => 'plow#save_setting'
|
||||
match 'plow/*path' => 'plow#show', via: [:get, :post, :put, :patch, :delete]
|
||||
resources :client_managements do
|
||||
member do
|
||||
|
|
|
@ -10,9 +10,13 @@ module ClientManagement
|
|||
# frontend_enabled
|
||||
# data_count 1..30
|
||||
require File.expand_path('../../../app/models/server_ability', __FILE__)
|
||||
require File.expand_path('../../../app/models/plow_setting', __FILE__)
|
||||
if ServerAbility.count==0
|
||||
ServerAbility.create()
|
||||
end
|
||||
if PlowSetting.count==0
|
||||
PlowSetting.create()
|
||||
end
|
||||
set_keyword_contstraints ["/cpanel/"]
|
||||
side_bar do
|
||||
head_label_i18n 'client_management.client_management', icon_class: "icons-users"
|
||||
|
@ -65,6 +69,12 @@ module ClientManagement
|
|||
:priority=>1,
|
||||
:active_for_action=>{'admin/site_panel'=>"server_manager"},
|
||||
:available_for => 'admin'
|
||||
|
||||
context_link 'client_management.stress_test',
|
||||
:link_path=>"admin_plow_setting_path" ,
|
||||
:priority=>1,
|
||||
:active_for_action=>{'admin/plow'=>"setting"},
|
||||
:available_for => 'admin'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue