From cdde1300a86c626fb1dd96016c76a8ee08578423 Mon Sep 17 00:00:00 2001 From: weibomobile Date: Wed, 13 Jul 2016 10:58:26 +0800 Subject: [PATCH] add direct ip support, and you don't need set up hostname & ip relations within /etc/hosts file any more, without the dns server support now --- src/tsung_controller/ts_config.erl | 21 +++++++++++++++++---- tsung-1.0.dtd | 1 + tsung.sh.in | 18 ++++++++++++------ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/tsung_controller/ts_config.erl b/src/tsung_controller/ts_config.erl index c070c8fe9..0c3334748 100644 --- a/src/tsung_controller/ts_config.erl +++ b/src/tsung_controller/ts_config.erl @@ -214,6 +214,7 @@ parse(Element = #xmlElement{name=load, attributes=Attrs}, Conf) -> parse(Element = #xmlElement{name=client, attributes=Attrs}, Conf = #config{clients=CList}) -> Host = getAttr(Attrs, host), + HostIP = getAttr(Attrs, hostip), Weight = getAttr(integer,Attrs, weight,1), MaxUsers = getAttr(integer,Attrs, maxusers, 800), SingleNode = getAttr(atom, Attrs, use_controller_vm, false) or Conf#config.use_controller_vm, @@ -263,12 +264,24 @@ parse(Element = #xmlElement{name=client, attributes=Attrs}, 1; {Val, _} -> Val end, - %% must be hostname and not ip: - case ts_utils:is_ip(Host) of - true -> + %% if the node()'s hostname is ip, then we will got the hostip replace the host attr + {ok, MasterHostname} = ts_utils:node_to_hostname(node()), + case {ts_utils:is_ip(MasterHostname), ts_utils:is_ip(Host), ts_utils:is_ip(HostIP)} of + %% must be hostname and not ip: + {false, true, _} -> io:format(standard_error,"ERROR: client config: 'host' attribute must be a hostname, "++ "not an IP ! (was ~p)~n",[Host]), exit({error, badhostname}); - false -> + {true, true, _} -> + %% add a new client for each CPU + lists:duplicate(CPU,#client{host = Host, + weight = Weight/CPU, + maxusers = MaxUsers}); + {true, _, true} -> + %% add a new client for each CPU + lists:duplicate(CPU,#client{host = HostIP, + weight = Weight/CPU, + maxusers = MaxUsers}); + {_, _, _} -> %% add a new client for each CPU lists:duplicate(CPU,#client{host = Host, weight = Weight/CPU, diff --git a/tsung-1.0.dtd b/tsung-1.0.dtd index d94a8ef94..8a983e806 100644 --- a/tsung-1.0.dtd +++ b/tsung-1.0.dtd @@ -29,6 +29,7 @@ cpu NMTOKEN "1" type (machine | batch) "machine" host NMTOKEN #IMPLIED + hostip CDATA "" batch (torque | pbs | lsf | oar) #IMPLIED scan_intf NMTOKEN #IMPLIED maxusers NMTOKEN "800" diff --git a/tsung.sh.in b/tsung.sh.in index fa877b9c9..eed891bc3 100755 --- a/tsung.sh.in +++ b/tsung.sh.in @@ -30,6 +30,7 @@ PGSQL_SERVER_IP=127.0.0.1 PGSQL_SERVER_PORT=5432 NAME=tsung CONTROLLER=tsung_controller +CONTROLLER_EXTENDS="" SMP_DISABLE=true WARM_TIME=1 MAX_PROCESS=250000 @@ -60,7 +61,7 @@ stop() { view() { echo "Starting Tsung web only on port 8091" - $ERL $ERL_OPTS $ERL_RSH -noshell $PROTO_DIST $NAMETYPE $CONTROLLER -setcookie $COOKIE \ + $ERL $ERL_OPTS $ERL_RSH -noshell $PROTO_DIST $NAMETYPE $CONTROLLER$CONTROLLER_EXTENDS -setcookie $COOKIE \ +P $MAX_PROCESS \ -kernel inet_dist_listen_min $ERL_DIST_PORTS_MIN -kernel inet_dist_listen_max $ERL_DIST_PORTS_MAX \ -s ts_web \ @@ -72,7 +73,7 @@ view() { start() { echo "Starting Tsung" - $ERL $ERL_OPTS $ERL_RSH -noshell $PROTO_DIST $NAMETYPE $CONTROLLER -setcookie $COOKIE \ + $ERL $ERL_OPTS $ERL_RSH -noshell $PROTO_DIST $NAMETYPE $CONTROLLER$CONTROLLER_EXTENDS -setcookie $COOKIE \ +P $MAX_PROCESS \ -kernel inet_dist_listen_min $ERL_DIST_PORTS_MIN -kernel inet_dist_listen_max $ERL_DIST_PORTS_MAX \ -s tsung_controller \ @@ -91,7 +92,7 @@ start() { } debug() { - $ERL $ERL_OPTS $ERL_RSH $NAMETYPE $CONTROLLER $PROTO_DIST -setcookie $COOKIE \ + $ERL $ERL_OPTS $ERL_RSH $NAMETYPE $CONTROLLER$CONTROLLER_EXTENDS $PROTO_DIST -setcookie $COOKIE \ +P $MAX_PROCESS \ -kernel inet_dist_listen_min $ERL_DIST_PORTS_MIN -kernel inet_dist_listen_max $ERL_DIST_PORTS_MAX \ -s tsung_controller \ @@ -164,7 +165,7 @@ usage() { echo " -X add additional erlang load paths (multiple -X arguments allowed)" echo " -m write monitoring output on this file (default is tsung.log)" echo " (use - for standard output)" - echo " -F use long names (FQDN) for erlang nodes" + echo " -F use long names (FQDN) for erlang nodes; you can assign local bind available IP (not assign? default is the host's name)" echo " -L SSL session lifetime (600sec by default)" echo " -w warmup delay (default is 1 sec)" echo " -n disable web GUI (started by default on port 8091)" @@ -178,7 +179,7 @@ usage() { exit } -while getopts "6vhknf:l:d:r:i:Fsw:m:p:x:X:t:T:" Option +while getopts "6vhknf:l:d:r:i:F:sw:m:p:x:X:t:T:" Option do case $Option in f) CONF_OPT_FILE=$OPTARG;; @@ -201,7 +202,12 @@ do X) EXTRA_LOAD_PATHS="$EXTRA_LOAD_PATHS -pa $OPTARG";; r) ERL_RSH=" -rsh $OPTARG ";; 6) PROTO_DIST=" -proto_dist inet6_tcp ";; - F) NAMETYPE="-name";; + F) NAMETYPE="-name" + SERVER_IP=$OPTARG + if [ "$SERVER_IP" != "" ]; then + CONTROLLER_EXTENDS="@$SERVER_IP" + fi + ;; L) SSL_SESSION_LIFETIME=$OPTARG;; w) WARM_TIME=$OPTARG;; t) ERL_DIST_PORTS_MIN=$OPTARG;;