influxdb/tests/siege/urlgen

108 lines
2.4 KiB
Plaintext
Raw Normal View History

2015-02-28 00:05:53 +00:00
#!/bin/bash -e
2015-01-29 05:46:49 +00:00
# Calculate start time as unix timestamp.
PLATFORM=`uname`
2015-01-29 18:01:55 +00:00
_date_to_unix_timestamp () {
if [ "$PLATFORM" = "Darwin" ] ; then
date -j -f "%b %d %T %Z %Y" "$1" "+%s"
2015-01-29 18:01:55 +00:00
elif [ "$PLATFORM" = "Linux" ] ; then
date -d "$1" "+%s"
else
echo "I don't know if your date can read a format and a time, failing"
exit 99
fi
}
2015-01-29 18:01:55 +00:00
_timestamp_to_time_string () {
if [ "$PLATFORM" = "Darwin" ] ; then
date -j -f "%s" "$1" +"%Y-%m-%dT%H:%M:%SZ"
elif [ "$PLATFORM" = "Linux" ] ; then
date -d "@$1" +"%Y-%m-%dT%H:%M:%SZ"
fi
}
# Starting the test at "Jan 01 00:00:00 GMT 2000"
TIME=`_date_to_unix_timestamp "Jan 01 00:00:00 GMT 2000"`
2015-01-29 05:46:49 +00:00
# Set defaults.
2015-01-29 07:13:57 +00:00
INTERVAL=10 # 1s
NUMCLIENTS=10
2015-01-29 05:46:49 +00:00
NUMSERIES=1
# Parse arguments
2015-01-29 07:13:57 +00:00
while getopts "s:c:i:h" opt; do
2015-01-29 05:46:49 +00:00
case $opt in
i)
INTERVAL=$OPTARG
;;
2015-01-29 07:13:57 +00:00
c)
NUMCLIENTS=$OPTARG
;;
2015-01-29 05:46:49 +00:00
s)
NUMSERIES=$OPTARG
;;
h)
echo "urlgen is a utility for generating URL files for siege."
echo ""
echo "Usage:"
echo " urlgen.sh [OPTIONS]"
echo ""
echo "The following arguments can be specified:"
echo ""
echo " -i seconds"
2015-01-29 07:13:57 +00:00
echo " Interval between requests."
echo " Defaults to 10 seconds."
2015-01-29 05:46:49 +00:00
echo ""
echo " -s num"
echo " Number of unique series to generate."
2015-01-29 06:10:10 +00:00
echo " Defaults to 1 series."
2015-01-29 05:46:49 +00:00
echo ""
2015-01-29 07:13:57 +00:00
echo " -c num"
echo " Number of clients to simulate."
echo " One request per client."
echo " Defaults to 10 clients."
2015-01-29 05:46:49 +00:00
echo ""
exit 1
;;
esac
done
2015-01-29 07:13:57 +00:00
# Generate a new request every interval per client.
for i in `seq 1 $NUMCLIENTS`;
2015-01-29 05:46:49 +00:00
do
# Move forward the current time.
2015-01-29 18:01:55 +00:00
TIME=$((TIME+INTERVAL))
TIMESTAMP=`_timestamp_to_time_string $TIME`
2015-01-29 05:46:49 +00:00
# Generate a URL for each series.
for series in `seq 1 $NUMSERIES`;
do
2015-01-29 07:13:57 +00:00
# Generate a URL for each second in the interval.
POINTS=""
for j in `seq 0 $INTERVAL`;
do
# Format the timestamp to ISO 8601.
let CURRTIME=TIME+j
2015-02-28 00:05:53 +00:00
TIMESTAMP=`_timestamp_to_time_string $CURRTIME`
2015-01-29 07:13:57 +00:00
# Add comma separator.
if [ "$j" -ne "0" ]
then
POINTS=$POINTS,
fi
# Append the point.
2015-04-23 17:44:16 +00:00
POINTS=$POINTS'{"name": "cpu", "tags": {"host": "server'$series'"}, "time": "'$TIMESTAMP'","fields": {"value": 100}}'
2015-01-29 07:13:57 +00:00
done
# Write out point.
echo 'http://localhost:8086/write POST {"database" : "db", "retentionPolicy" : "raw", "points": ['$POINTS']}'
2015-01-29 05:46:49 +00:00
done
2015-01-29 07:13:57 +00:00
# Move forward the current time.
let TIME=TIME+INTERVAL
2015-01-29 05:46:49 +00:00
done