Skip to content

Instantly share code, notes, and snippets.

@rvolosatovs
Created June 17, 2020 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvolosatovs/447af78a3aea11cff6cc285ff0c89e2e to your computer and use it in GitHub Desktop.
Save rvolosatovs/447af78a3aea11cff6cc285ff0c89e2e to your computer and use it in GitHub Desktop.
This is why you don't use Influx. This is necessary, because otherwise DB crashes.
#!/usr/bin/env bash
set -o pipefail
#set -x
days=${1:-7}
mins=`expr ${days} '*' 24 '*' 60`
interval=1440
now=`date +%s%N`
db='noc_171212'
d=/tti/noc/export/"${now}"
mkdir -p "${d}"
echo "Creating export at:" 1>&2
echo "${d}"
for table in 'gateway_status' 'gateway_uplink' 'gateway_downlink' 'broker_uplink' 'broker_downlink' 'handler_uplink' 'handler_downlink'; do
path="${d}/${table}.csv"
echo "Extracting data from ${db}.${table} to ${path}" 1>&2
for i in `seq $(expr ${mins} '/' ${interval})`; do
while : ; do
if [ $i == 1 ]; then
echo "From ${interval}m ago" 1>&2
( influx -format 'csv' -database "${db}" -execute "select * from ${table} where time >= ${now} - ${interval}m" || { echo ""; exit 1; } ) > "$path"
else
echo "From `expr ${i} '*' ${interval}` m ago to `expr ${interval} '*' '(' ${i} '-' 1 ')'`m ago" 1>&2
( influx -format 'csv' -database "${db}" -execute "select * from ${table} where time >= ${now} - `expr ${interval} '*' ${i}`m and time < ${now} - `expr ${interval} '*' '(' ${i} '-' 1 ')'`m" || { echo ""; exit 1; } ) | sed '1d' >> "$path"
fi
if [ $? == 0 ] ; then
break
fi
echo "Repeating in 5 sec..." 1>&2
sleep 5
done
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment