├── Dockerfile ├── LICENSE ├── Makefile ├── README.md └── scripts ├── tsung-runner.sh └── tsung-update-hosts.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | # Tsung 2 | # 3 | # 4 | # VERSION 1.5.1 5 | 6 | FROM centos:centos6 7 | MAINTAINER Dragos Dascalita Haut 8 | 9 | RUN yum update -y 10 | RUN rpm -Uvh "http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm" 11 | RUN yum -y install tsung perl-Log-Log4perl-RRDs.noarch gnuplot perl-Template-Toolkit firefox 12 | 13 | # 14 | # setup SSH Access on Port 22, with the ssh clients using port 21 by default 15 | RUN yum -y install openssh openssh-server openssh-clients 16 | RUN ssh-keygen -N "" -f /root/.ssh/id_rsa && \ 17 | cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys && \ 18 | echo "Port 21" > /root/.ssh/config && \ 19 | echo "StrictHostKeyChecking no" >> /root/.ssh/config && \ 20 | echo "UserKnownHostsFile /dev/null" >> /root/.ssh/config 21 | 22 | RUN mkdir -p /var/log/tsung && echo "" > /var/log/tsung/tsung.log 23 | 24 | COPY ./scripts/tsung-runner.sh /usr/bin/tsung-runner 25 | RUN chmod +x /usr/bin/tsung-runner 26 | 27 | EXPOSE 22 28 | 29 | # EPMD port: http://www.erlang.org/doc/man/epmd.html#environment_variables 30 | EXPOSE 4369 31 | ENV ERL_EPMD_PORT=4369 32 | 33 | # Erlang needs this environment variable 34 | ENV BINDIR=/usr/lib64/erlang/erts-5.8.5/ 35 | 36 | # mount a location on the disk to access the test scripts 37 | RUN mkdir -p /usr/local/tsung 38 | VOLUME ["/usr/local/tsung"] 39 | 40 | 41 | EXPOSE 9001-9050 42 | # 43 | # make sure inet_dist_listen_* properties are available when Erlang runs 44 | # 45 | RUN sed -i.bak s/"64000"/"9001"/g /usr/bin/tsung 46 | RUN sed -i.bak s/"65500"/"9050"/g /usr/bin/tsung 47 | RUN printf "[{kernel,[{inet_dist_listen_min,9001},{inet_dist_listen_max,9050}]}]. \n\n" > /root/sys.config 48 | RUN sed -i.bak s/"erlexec"/"erlexec -config \/root\/sys "/g /usr/bin/erl 49 | 50 | # setup for auto-discovery of the tsung nodes 51 | RUN yum -y install crontabs 52 | COPY ./scripts/tsung-update-hosts.sh /usr/bin/tsung-update-hosts 53 | RUN chmod +x /usr/bin/tsung-update-hosts 54 | RUN mkdir -p /etc/tsung/ 55 | RUN echo "* * * * * /usr/bin/tsung-update-hosts >> /var/log/tsung/tsung-update-hosts.log 2>&1" > /etc/crontab 56 | RUN touch /var/log/tsung/tsung-update-hosts.log 57 | 58 | ENTRYPOINT ["tsung-runner"] 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | docker: 2 | docker build -t ddragosd/tsung-docker . 3 | 4 | .PHONY: docker-ssh 5 | docker-ssh: 6 | docker run -ti --entrypoint='bash' ddragosd/tsung-docker:latest 7 | 8 | .PHONY: docker-run 9 | docker-run: 10 | docker run -p 21:22 ddragosd/tsung-docker:latest 11 | 12 | .PHONY: docker-attach 13 | docker-attach: 14 | docker exec -i -t tsung-agent bash 15 | 16 | .PHONY: docker-stop 17 | docker-stop: 18 | docker stop tsung-agent 19 | docker rm tsung-agent 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tsung-docker 2 | ============ 3 | Docker image to run Tsung distributed load testing tool. 4 | 5 | ### Usage 6 | 7 | This Docker container is designed to execute `Tsung` in 3 modes: `SINGLE`, `MASTER` and `SLAVE`. 8 | 9 | #### Single Mode 10 | Use this single mode to test on the local box, with a single Tsung agent: 11 | 12 | ``` 13 | docker run \ 14 | -v /local/tests:/usr/local/tsung ddragosd/tsung-docker:latest \ 15 | -f /usr/local/tsung/mytest.xml \ 16 | -r \"ssh -p 22\" start 17 | ``` 18 | 19 | In this mode you can use a single Tsung client 20 | ``` ``` 21 | Note the `-r` flag setting `ssh` port to `22`. This is needed as the SSH runs on port `22` inside the docker container. 22 | In a `MASTER` / `SLAVE` scenarios, we'll have this port mapped to `21` as a convention. 23 | 24 | #### Master Mode 25 | This mode should be used on a local machine by mounting a folder containing the Tsung tests into the container, like in the following example: 26 | 27 | ``` 28 | docker run \ 29 | -p 21:22 \ 30 | -p 4369:4369 \ 31 | -p 9001-9050:9001-9050 \ 32 | -v /local/tests:/usr/local/tsung ddragosd/tsung-docker:latest \ 33 | -f /usr/local/tsung/mytest.xml start 34 | ``` 35 | 36 | where `/local/tests` is a folder containing an XML file `mytest.xml`. 37 | 38 | * Note: Master Node has to be accessible from all the Slave nodes. Be aware of this when running behind a firewall. 39 | 40 | #### Slave Mode 41 | Use this mode in the distributed mode. All the agents that the `MASTER` Tsung needs to connect to must be started in this mode. 42 | By convention, the Agents run SSHD on port `21` b/c port `22` might be taken by the hosts running the docker service. For this reason, in order to avoid conflicts, the agents expose ssh on port `21`. 43 | Erlang needs port `4369` open as its [EPMD](http://www.erlang.org/doc/man/epmd.html) Port and all Slaves and Master nodes need to be able to use this port. 44 | Erlang also uses other ports for communication and this container exposes ports in the range `9001-9050`. 45 | 46 | To start a Docker container in the Slave mode issue the following command: 47 | 48 | ``` 49 | docker run \ 50 | -p 21:22 \ 51 | -p 4369:4369 \ 52 | -p 9001-9050:9001-9050 \ 53 | -e "SLAVE=true" \ 54 | ddragosd/tsung-docker:latest 55 | ``` 56 | 57 | #### Running Tsung in a static environment 58 | When you know the IPs of the nodes running Tsung you can manually expose them to docker through the `--add-host` parameter. 59 | 60 | For the master node you can use: 61 | ``` 62 | docker run -d \ 63 | -p 21:22 \ 64 | -p 4369:4369 \ 65 | -p 9001-9050:9001-9050 \ 66 | --add-host tsung_slave1:10.132.35.108 \ 67 | --add-host tsung_slave2:10.132.35.109 \ 68 | --add-host target:10.132.35.110 \ 69 | -h tsung_master \ 70 | --name tsung \ 71 | ddragosd/tsung-docker:latest -f /usr/local/tsung/tsung.xml start 72 | ``` 73 | 74 | And for the tsung-slave nodes: 75 | 76 | ``` 77 | docker run -d \ 78 | -p 21:22 \ 79 | -p 4369:4369 \ 80 | -p 9001-9050:9001-9050 \ 81 | -e "SLAVE=true" \ 82 | -h tsung_slave1 \ 83 | --add-host tsung_master:10.132.35.107 \ 84 | --add-host target:10.132.35.110 \ 85 | --name tsung_slave \ 86 | ddragosd/tsung-docker:latest 87 | ``` 88 | 89 | ### Running in Apache Mesos and Marathon 90 | 91 | ![image](https://cloud.githubusercontent.com/assets/541933/7624252/9e98b2d2-f99a-11e4-9cdc-828fee71c30e.png) 92 | 93 | The main purpose of running a Docker container with Tsung is the ease of scale and Mesos with Marathon have great support for this. 94 | The containers need Marathon's base URL in order to auto-discover the nodes in the cluster; this is set in an environment variable : `MARATHON_URL`. 95 | 96 | * First step is to start the `tsung-master` node. It should be a single node. 97 | The configuration is almost identical to the Slaves with 2 differences: `id` and `parameters`. 98 | 99 | It's recommended to also mount a volume from the host machine to `/usr/local/tsung` inside the container and place the tsung logs in there. 100 | You can then expose that data via a web-server such as `nginx`. The directory on the host must be specified as an absolute path and if the directory doesn't exist Docker should automatically create it for you. 101 | 102 | Use Marathon API to make a POST to `http:///v2/apps` 103 | ```javascript 104 | curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' 105 | { 106 | "id": "tsung-master", 107 | "container": { 108 | "type": "DOCKER", 109 | "volumes": [ 110 | { 111 | "containerPath": "/usr/local/tsung", 112 | "hostPath": "/var/lib/log/tsung", 113 | "mode": "RW" 114 | } 115 | ], 116 | "docker": { 117 | "image": "ddragosd/tsung-docker:latest", 118 | "network": "BRIDGE", 119 | "portMappings": [ 120 | { "containerPort": 22, "hostPort": 1025, "protocol": "tcp" }, 121 | { "containerPort": 4369, "hostPort": 4369, "protocol": "tcp" }, 122 | { "containerPort": 9001, "hostPort": 9001, "protocol": "tcp" }, 123 | { "containerPort": 9002, "hostPort": 9002, "protocol": "tcp" }, 124 | { "containerPort": 9003, "hostPort": 9003, "protocol": "tcp" }, 125 | { "containerPort": 9004, "hostPort": 9004, "protocol": "tcp" }, 126 | { "containerPort": 9005, "hostPort": 9005, "protocol": "tcp" }, 127 | { "containerPort": 9006, "hostPort": 9006, "protocol": "tcp" }, 128 | { "containerPort": 9007, "hostPort": 9007, "protocol": "tcp" }, 129 | { "containerPort": 9008, "hostPort": 9008, "protocol": "tcp" }, 130 | { "containerPort": 9009, "hostPort": 9009, "protocol": "tcp" }, 131 | { "containerPort": 9010, "hostPort": 9010, "protocol": "tcp" }, 132 | { "containerPort": 9011, "hostPort": 9011, "protocol": "tcp" }, 133 | { "containerPort": 9012, "hostPort": 9012, "protocol": "tcp" }, 134 | { "containerPort": 9013, "hostPort": 9013, "protocol": "tcp" }, 135 | { "containerPort": 9014, "hostPort": 9014, "protocol": "tcp" }, 136 | { "containerPort": 9015, "hostPort": 9015, "protocol": "tcp" }, 137 | { "containerPort": 9016, "hostPort": 9016, "protocol": "tcp" }, 138 | { "containerPort": 9017, "hostPort": 9017, "protocol": "tcp" }, 139 | { "containerPort": 9018, "hostPort": 9018, "protocol": "tcp" }, 140 | { "containerPort": 9019, "hostPort": 9019, "protocol": "tcp" }, 141 | { "containerPort": 9020, "hostPort": 9020, "protocol": "tcp" }, 142 | { "containerPort": 9021, "hostPort": 9021, "protocol": "tcp" }, 143 | { "containerPort": 9022, "hostPort": 9022, "protocol": "tcp" }, 144 | { "containerPort": 9023, "hostPort": 9023, "protocol": "tcp" }, 145 | { "containerPort": 9024, "hostPort": 9024, "protocol": "tcp" }, 146 | { "containerPort": 9025, "hostPort": 9025, "protocol": "tcp" }, 147 | { "containerPort": 9026, "hostPort": 9026, "protocol": "tcp" }, 148 | { "containerPort": 9027, "hostPort": 9027, "protocol": "tcp" }, 149 | { "containerPort": 9028, "hostPort": 9028, "protocol": "tcp" }, 150 | { "containerPort": 9029, "hostPort": 9029, "protocol": "tcp" }, 151 | { "containerPort": 9030, "hostPort": 9030, "protocol": "tcp" }, 152 | { "containerPort": 9031, "hostPort": 9031, "protocol": "tcp" }, 153 | { "containerPort": 9032, "hostPort": 9032, "protocol": "tcp" }, 154 | { "containerPort": 9033, "hostPort": 9033, "protocol": "tcp" }, 155 | { "containerPort": 9034, "hostPort": 9034, "protocol": "tcp" }, 156 | { "containerPort": 9035, "hostPort": 9035, "protocol": "tcp" }, 157 | { "containerPort": 9036, "hostPort": 9036, "protocol": "tcp" }, 158 | { "containerPort": 9037, "hostPort": 9037, "protocol": "tcp" }, 159 | { "containerPort": 9038, "hostPort": 9038, "protocol": "tcp" }, 160 | { "containerPort": 9039, "hostPort": 9039, "protocol": "tcp" }, 161 | { "containerPort": 9040, "hostPort": 9040, "protocol": "tcp" }, 162 | { "containerPort": 9041, "hostPort": 9041, "protocol": "tcp" }, 163 | { "containerPort": 9042, "hostPort": 9042, "protocol": "tcp" }, 164 | { "containerPort": 9043, "hostPort": 9043, "protocol": "tcp" }, 165 | { "containerPort": 9044, "hostPort": 9044, "protocol": "tcp" }, 166 | { "containerPort": 9045, "hostPort": 9045, "protocol": "tcp" }, 167 | { "containerPort": 9046, "hostPort": 9046, "protocol": "tcp" }, 168 | { "containerPort": 9047, "hostPort": 9047, "protocol": "tcp" }, 169 | { "containerPort": 9048, "hostPort": 9048, "protocol": "tcp" }, 170 | { "containerPort": 9049, "hostPort": 9049, "protocol": "tcp" }, 171 | { "containerPort": 9050, "hostPort": 9050, "protocol": "tcp" } 172 | ], 173 | "parameters": [ 174 | { "key": "hostname", "value": "tsung_master" } 175 | ] 176 | } 177 | }, 178 | "cpus": 1, 179 | "mem": 512.0, 180 | "env": { 181 | "SLAVE": "true", 182 | "MARATHON_URL":"'${MARATHON_HOST}'" 183 | }, 184 | "constraints": [ [ "hostname", "UNIQUE" ] ], 185 | "ports": [ 186 | 1025, 187 | 4369, 188 | 9001,9002,9003,9004,9005,9006,9007,9008,9009,9010, 189 | 9011,9012,9013,9014,9015,9016,9017,9018,9019,9020, 190 | 9021,9022,9023,9024,9025,9026,9027,9028,9029,9030, 191 | 9031,9032,9033,9034,9035,9036,9037,9038,9039,9040, 192 | 9041,9042,9043,9044,9045,9046,9047,9048,9049,9050 193 | ], 194 | "instances": 1 195 | }' 196 | ``` 197 | 198 | * Once the master is up and running you can start the slave nodes: 199 | 200 | 201 | ```javascript 202 | curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' 203 | { 204 | "id": "tsung-slaves", 205 | "container": { 206 | "type": "DOCKER", 207 | "docker": { 208 | "image": "ddragosd/tsung-docker:latest", 209 | "network": "BRIDGE", 210 | "portMappings": [ 211 | { "containerPort": 22, "hostPort": 1025, "protocol": "tcp" }, 212 | { "containerPort": 4369, "hostPort": 4369, "protocol": "tcp" }, 213 | { "containerPort": 9001, "hostPort": 9001, "protocol": "tcp" }, 214 | { "containerPort": 9002, "hostPort": 9002, "protocol": "tcp" }, 215 | { "containerPort": 9003, "hostPort": 9003, "protocol": "tcp" }, 216 | { "containerPort": 9004, "hostPort": 9004, "protocol": "tcp" }, 217 | { "containerPort": 9005, "hostPort": 9005, "protocol": "tcp" }, 218 | { "containerPort": 9006, "hostPort": 9006, "protocol": "tcp" }, 219 | { "containerPort": 9007, "hostPort": 9007, "protocol": "tcp" }, 220 | { "containerPort": 9008, "hostPort": 9008, "protocol": "tcp" }, 221 | { "containerPort": 9009, "hostPort": 9009, "protocol": "tcp" }, 222 | { "containerPort": 9010, "hostPort": 9010, "protocol": "tcp" }, 223 | { "containerPort": 9011, "hostPort": 9011, "protocol": "tcp" }, 224 | { "containerPort": 9012, "hostPort": 9012, "protocol": "tcp" }, 225 | { "containerPort": 9013, "hostPort": 9013, "protocol": "tcp" }, 226 | { "containerPort": 9014, "hostPort": 9014, "protocol": "tcp" }, 227 | { "containerPort": 9015, "hostPort": 9015, "protocol": "tcp" }, 228 | { "containerPort": 9016, "hostPort": 9016, "protocol": "tcp" }, 229 | { "containerPort": 9017, "hostPort": 9017, "protocol": "tcp" }, 230 | { "containerPort": 9018, "hostPort": 9018, "protocol": "tcp" }, 231 | { "containerPort": 9019, "hostPort": 9019, "protocol": "tcp" }, 232 | { "containerPort": 9020, "hostPort": 9020, "protocol": "tcp" }, 233 | { "containerPort": 9021, "hostPort": 9021, "protocol": "tcp" }, 234 | { "containerPort": 9022, "hostPort": 9022, "protocol": "tcp" }, 235 | { "containerPort": 9023, "hostPort": 9023, "protocol": "tcp" }, 236 | { "containerPort": 9024, "hostPort": 9024, "protocol": "tcp" }, 237 | { "containerPort": 9025, "hostPort": 9025, "protocol": "tcp" }, 238 | { "containerPort": 9026, "hostPort": 9026, "protocol": "tcp" }, 239 | { "containerPort": 9027, "hostPort": 9027, "protocol": "tcp" }, 240 | { "containerPort": 9028, "hostPort": 9028, "protocol": "tcp" }, 241 | { "containerPort": 9029, "hostPort": 9029, "protocol": "tcp" }, 242 | { "containerPort": 9030, "hostPort": 9030, "protocol": "tcp" }, 243 | { "containerPort": 9031, "hostPort": 9031, "protocol": "tcp" }, 244 | { "containerPort": 9032, "hostPort": 9032, "protocol": "tcp" }, 245 | { "containerPort": 9033, "hostPort": 9033, "protocol": "tcp" }, 246 | { "containerPort": 9034, "hostPort": 9034, "protocol": "tcp" }, 247 | { "containerPort": 9035, "hostPort": 9035, "protocol": "tcp" }, 248 | { "containerPort": 9036, "hostPort": 9036, "protocol": "tcp" }, 249 | { "containerPort": 9037, "hostPort": 9037, "protocol": "tcp" }, 250 | { "containerPort": 9038, "hostPort": 9038, "protocol": "tcp" }, 251 | { "containerPort": 9039, "hostPort": 9039, "protocol": "tcp" }, 252 | { "containerPort": 9040, "hostPort": 9040, "protocol": "tcp" }, 253 | { "containerPort": 9041, "hostPort": 9041, "protocol": "tcp" }, 254 | { "containerPort": 9042, "hostPort": 9042, "protocol": "tcp" }, 255 | { "containerPort": 9043, "hostPort": 9043, "protocol": "tcp" }, 256 | { "containerPort": 9044, "hostPort": 9044, "protocol": "tcp" }, 257 | { "containerPort": 9045, "hostPort": 9045, "protocol": "tcp" }, 258 | { "containerPort": 9046, "hostPort": 9046, "protocol": "tcp" }, 259 | { "containerPort": 9047, "hostPort": 9047, "protocol": "tcp" }, 260 | { "containerPort": 9048, "hostPort": 9048, "protocol": "tcp" }, 261 | { "containerPort": 9049, "hostPort": 9049, "protocol": "tcp" }, 262 | { "containerPort": 9050, "hostPort": 9050, "protocol": "tcp" } 263 | ] 264 | } 265 | }, 266 | "cpus": 2, 267 | "mem": 2048.0, 268 | "env": { 269 | "SLAVE": "true", 270 | "MARATHON_URL":"'${MARATHON_HOST}'" 271 | }, 272 | "constraints": [ 273 | [ 274 | "hostname", 275 | "UNIQUE" 276 | ] 277 | ], 278 | "ports": [ 279 | 1025, 280 | 4369, 281 | 9001,9002,9003,9004,9005,9006,9007,9008,9009,9010, 282 | 9011,9012,9013,9014,9015,9016,9017,9018,9019,9020, 283 | 9021,9022,9023,9024,9025,9026,9027,9028,9029,9030, 284 | 9031,9032,9033,9034,9035,9036,9037,9038,9039,9040, 285 | 9041,9042,9043,9044,9045,9046,9047,9048,9049,9050 286 | ], 287 | "instances": 2 288 | }' 289 | ``` 290 | 291 | #### Exposing Tsung test results from Master via Nginx 292 | 293 | Use Marathon API to make a POST to `http:///v2/apps` 294 | Note: This container should run on the same host where `tsung-master` runs. 295 | You can use [constraints](https://github.com/mesosphere/marathon/blob/master/docs/docs/constraints.md) to achieve that. 296 | 297 | 298 | ```bash 299 | TSUNG_MASTER_HOST=$(curl -s ${MARATHON_HOST}/v2/tasks | grep tsung-master | grep 9050 | awk '{print $3}' | sed 's/\(\:[0-9].*\)//') \ 300 | && curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' 301 | { 302 | "id": "tsung-nginx", 303 | "cmd": "sed -i s/\"htm;\"/\"htm; autoindex on;\"/g /etc/nginx/conf.d/default.conf && nginx -g \"daemon off;\"", 304 | "container": { 305 | "type": "DOCKER", 306 | "volumes": [ 307 | { 308 | "containerPath": "/usr/share/nginx/html/tsung", 309 | "hostPath": "/var/lib/log/tsung", 310 | "mode": "RO" 311 | } 312 | ], 313 | "docker": { 314 | "image": "nginx", 315 | "network": "BRIDGE", 316 | "portMappings": [ 317 | { "containerPort": 80, "hostPort": 0, "protocol": "tcp" } 318 | ] 319 | } 320 | }, 321 | "cpus": 0.5, 322 | "mem": 512.0, 323 | "constraints": [["hostname", "CLUSTER", "'${TSUNG_MASTER_HOST}'"]], 324 | "ports": [ 325 | 0 326 | ], 327 | "instances": 1 328 | }' 329 | ``` 330 | 331 | By default the nginx server does not index directories. To fix this the Nginx container updates the default conf on start: 332 | ``` 333 | sed -i s/"htm;"/"htm; autoindex on;"/g /etc/nginx/conf.d/default.conf 334 | ``` 335 | -------------------------------------------------------------------------------- /scripts/tsung-runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Utility to run tsung and automatically generate reports 4 | 5 | # make sure SSHD is started in order to connect to other tsung agents 6 | service sshd start 7 | 8 | # start crontab to update tsung hosts found in the cluster 9 | echo ${MARATHON_URL} > /etc/tsung/marathon_url 10 | crontab /etc/crontab 11 | service crond start 12 | 13 | 14 | slave=$(echo $SLAVE) 15 | if [[ -n "${slave}" ]]; then 16 | echo "Running in SLAVE mode ..." 17 | tail -f /var/log/tsung/tsung-update-hosts.log 18 | exit 19 | fi 20 | 21 | # http://stackoverflow.com/questions/2369341/which-tcp-port-does-erlang-use-for-connecting-to-a-remote-node 22 | # erl -kernel inet_dist_listen_min 9001 inet_dist_listen_max 9005 23 | 24 | current_date=$(date +%Y%m%d-%H%M) 25 | echo "Tsung log directory should be ${current_date}" 26 | cmd='tsung -l /usr/local/tsung/ '$@ 27 | echo "Executin ${cmd} ..." 28 | ${cmd} 29 | cd /usr/local/tsung/${current_date}/ && /usr/lib64/tsung/bin/tsung_stats.pl 30 | 31 | -------------------------------------------------------------------------------- /scripts/tsung-update-hosts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # update /etc/hosts : auto-discover tsung_slaves 4 | # by convention look in Marathon API $(MARATHON_URL)/v2/apps/tsung-slaves 5 | 6 | echo "Discovering Tsung Hosts ... " 7 | echo `date` 8 | 9 | # the names of the Marathon apps for slave and master nodes 10 | tsung_slave_app_name=tsung-slaves 11 | tsung_master_app_name=tsung-master 12 | MARATHON_URL=$(cat /etc/tsung/marathon_url) 13 | 14 | if [[ -n "${MARATHON_URL}" ]]; then 15 | echo "Discovering tsung-slaves ..." 16 | #1. discover new tsung_slaves 17 | curl -s ${MARATHON_URL}/v2/apps/${tsung_slave_app_name} | grep -Po '"host":"\K.*?(?=")' | xargs dig +short | awk '{ print $1" tsung_slave"NR}' > /etc/tsung/tsung_slaves_hosts.conf 18 | #2. clean-up previous discovered tsung_slaves 19 | sed -r '/tsung_slave/d' /etc/hosts > /etc/hosts-temp 20 | # docker down not allow modifying /etc/hosts and the next line works around that 21 | cat /etc/hosts-temp | tee /etc/hosts > /dev/null 22 | #3. append the new list to /etc/hosts 23 | cat /etc/tsung/tsung_slaves_hosts.conf >> /etc/hosts 24 | cat /etc/tsung/tsung_slaves_hosts.conf 25 | echo "Discovering tsung-master ..." 26 | #1. discover tsung_master 27 | curl -s ${MARATHON_URL}/v2/apps/${tsung_master_app_name} | grep -Po '"host":"\K.*?(?=")' | xargs dig +short | awk '{ print $1" tsung_master"}' > /etc/tsung/tsung_master_hosts.conf 28 | #2. clean-up previous discovered tsung_master 29 | sed -r '/tsung_master/d' /etc/hosts > /etc/hosts-temp 30 | # docker down not allow modifying /etc/hosts and the next line works around that 31 | cat /etc/hosts-temp | tee /etc/hosts > /dev/null 32 | #3. append the new list to /etc/hosts 33 | cat /etc/tsung/tsung_master_hosts.conf >> /etc/hosts 34 | cat /etc/tsung/tsung_master_hosts.conf 35 | echo "DONE." 36 | fi 37 | 38 | --------------------------------------------------------------------------------