{"__v":3,"_id":"556b055230922f1700ad5d25","category":{"__v":2,"_id":"556b055230922f1700ad5cfe","pages":["556b055230922f1700ad5d19","556b055230922f1700ad5d1a","556b055230922f1700ad5d1b","556b055230922f1700ad5d1c","556b055230922f1700ad5d1d","556b055230922f1700ad5d1e","556b055230922f1700ad5d1f","556b055230922f1700ad5d20","556b055230922f1700ad5d21","556b055230922f1700ad5d22","556b055230922f1700ad5d23","556b055230922f1700ad5d24","556b055230922f1700ad5d25","556b055230922f1700ad5d26","556bc25f61c7f40d001ce059"],"project":"5563e51e2207bd2100a3d7fd","version":"556b055130922f1700ad5cfd","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-26T04:27:33.949Z","from_sync":false,"order":2,"slug":"api","title":"Flood API"},"parentDoc":null,"project":"5563e51e2207bd2100a3d7fd","user":"5563e5474e990b2100d425d1","version":{"__v":3,"_id":"556b055130922f1700ad5cfd","forked_from":"5563e51e2207bd2100a3d800","project":"5563e51e2207bd2100a3d7fd","createdAt":"2015-05-31T12:57:53.432Z","releaseDate":"2015-05-31T12:57:53.432Z","categories":["556b055230922f1700ad5cfe","556b055230922f1700ad5cff","556b055230922f1700ad5d00","556b055230922f1700ad5d01","556b055230922f1700ad5d02","556b055230922f1700ad5d03","556b07e9ab693b1900ce16d0","56fe562d3eaf300e00f7421c"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-31T12:45:24.374Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Using the Flood API and some simple bash scripting techniques it's possible to automate load testing from within your Continuous Integration pipeline. Following is a structured example or see [here](https://gist.github.com/90kts/0d3f655a89b34000d73d) for a more detailed approach:\n\n```\n#!/bin/bash\nset -e\n\n# Check we have the jq binary to make parsing JSON responses a bit easier\ncommand -v jq >/dev/null 2>&1 || \\\n{ echo >&2 \"Please install http://stedolan.github.io/jq/download/  Aborting.\"; exit 1; }\n\n# Start a flood\necho\necho \"[$(date +%FT%T)+00:00] Starting flood\"\nflood_uuid=$(curl -u abc123: -X POST https://api.flood.io/floods \\\n -F \"flood[tool]=jmeter\" \\\n -F \"flood[threads]=10\" \\\n -F \"flood[privacy]=public\" \\\n -F \"flood[name]=MyTest\" \\\n -F \"flood[tag_list]=ci,shakeout\" \\\n -F \"flood[meta]=$meta\" \\\n -F \"flood_files[]=:::at:::jmeter-with-plugins.jmx\" \\\n -F \"flood[grids][][infrastructure]=demand\" \\\n -F \"flood[grids][][instance_quantity]=1\" \\\n -F \"flood[grids][][region]=ap-southeast-2\" \\\n -F \"flood[grids][][instance_type]=m4.xlarge\" \\\n -F \"flood[grids][][stop_after]=60\" | jq -r \".uuid\")\n\n# Wait for flood to finish\necho \"[$(date +%FT%T)+00:00] Waiting for flood $flood_uuid\"\nwhile [ $(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid | \\\n  jq -r '.status == \"finished\"') = \"false\" ]; do\n  echo -n \".\"\n  sleep 3\ndone\n\n# Get the summary report\nflood_report=$(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/report | \\\n  jq -r \".summary\")\n\necho\necho \"[$(date +%FT%T)+00:00] Detailed results at https://flood.io/$flood_uuid\"\necho \"$flood_report\"\n\n# Optionally store the CSV results\necho\necho \"[$(date +%FT%T)+00:00] Storing CSV results at resuts.csv\"\ncurl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/result.csv > result.csv\n```","excerpt":"Learn how to use the Flood API","slug":"flood-api-example","type":"basic","title":"Bash usage example"}

Bash usage example

Learn how to use the Flood API

Using the Flood API and some simple bash scripting techniques it's possible to automate load testing from within your Continuous Integration pipeline. Following is a structured example or see [here](https://gist.github.com/90kts/0d3f655a89b34000d73d) for a more detailed approach: ``` #!/bin/bash set -e # Check we have the jq binary to make parsing JSON responses a bit easier command -v jq >/dev/null 2>&1 || \ { echo >&2 "Please install http://stedolan.github.io/jq/download/ Aborting."; exit 1; } # Start a flood echo echo "[$(date +%FT%T)+00:00] Starting flood" flood_uuid=$(curl -u abc123: -X POST https://api.flood.io/floods \ -F "flood[tool]=jmeter" \ -F "flood[threads]=10" \ -F "flood[privacy]=public" \ -F "flood[name]=MyTest" \ -F "flood[tag_list]=ci,shakeout" \ -F "flood[meta]=$meta" \ -F "flood_files[]=@jmeter-with-plugins.jmx" \ -F "flood[grids][][infrastructure]=demand" \ -F "flood[grids][][instance_quantity]=1" \ -F "flood[grids][][region]=ap-southeast-2" \ -F "flood[grids][][instance_type]=m4.xlarge" \ -F "flood[grids][][stop_after]=60" | jq -r ".uuid") # Wait for flood to finish echo "[$(date +%FT%T)+00:00] Waiting for flood $flood_uuid" while [ $(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid | \ jq -r '.status == "finished"') = "false" ]; do echo -n "." sleep 3 done # Get the summary report flood_report=$(curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/report | \ jq -r ".summary") echo echo "[$(date +%FT%T)+00:00] Detailed results at https://flood.io/$flood_uuid" echo "$flood_report" # Optionally store the CSV results echo echo "[$(date +%FT%T)+00:00] Storing CSV results at resuts.csv" curl --silent --user $FLOOD_API_TOKEN: https://api.flood.io/floods/$flood_uuid/result.csv > result.csv ```