#!/bin/bash

[ "$2" == "" ] && exec echo "Usage: $0 <Type: header/common/world> <ms_id/ws_id_start> <ws_id_end>"

TYPE=$1
START=$2
END=$3

DIR_NAME_DIRECTORY=$(dirname $(pwd) | sed "s|$HOME/www|/var/www/html|")

case $TYPE in
    header)
cat <<EOF
WorkDir: ${DIR_NAME_DIRECTORY}/set${START}
LogDir: ${DIR_NAME_DIRECTORY}/set${START}
ThreshDir: ${DIR_NAME_DIRECTORY}/set${START}     
EOF
echo
        ;;
    common)
echo "$(cat <<EOF
Target[mission_cpu_${START}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ms${START} "COLUMNS=200 top -c -b -n 1" |awk /MissionServer${START}\$/'{print \$9}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ms${START} "COLUMNS=200 top -c -b -n 1" |awk /MissionServer${START}\$/'{print \$9}'\`
MaxBytes[mission_cpu_${START}]: 100
Options[mission_cpu_${START}]: gauge, nopercent, growright
YLegend[mission_cpu_${START}]: CPU Loading (%)
ShortLegend[mission_cpu_${START}]: %
LegendO[mission_cpu_${START}]: CPU user:
LegendI[mission_cpu_${START}]: CPU user:
Title[mission_cpu_${START}]: MissionServer${START} CPU Loading
PageTop[mission_cpu_${START}]: <H1>MissionServer${START} CPU Loading</H1>

Target[mission_mem_${START}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ms${START} ps -aux |grep -v awk |awk /MissionServer${START}\$/'{print \$6/1024}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ms${START} ps -aux |grep -v awk |awk /MissionServer${START}\$/'{print \$6/1024}'\`
MaxBytes[mission_mem_${START}]: 99999
Options[mission_mem_${START}]: gauge, nopercent, growright
YLegend[mission_mem_${START}]: MEM Usage (MB)
ShortLegend[mission_mem_${START}]: MB
LegendO[mission_mem_${START}]: MEM Usage:
LegendI[mission_mem_${START}]: MEM Usage:
Title[mission_mem_${START}]: MissionServer${START} MEM Usage
PageTop[mission_mem_${START}]: <H1>MissionServer${START} MEM Usage</H1>

Target[gamedbs_cpu_${START}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null gds${START} "COLUMNS=200 top -c -b -n 1" |awk /GameDBServer${START}\$/'{print \$9}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null gds${START} "COLUMNS=200 top -c -b -n 1" |awk /GameDBServer${START}\$/'{print \$9}'\`
MaxBytes[gamedbs_cpu_${START}]: 100
Options[gamedbs_cpu_${START}]: gauge, nopercent, growright
YLegend[gamedbs_cpu_${START}]: CPU Loading (%)
ShortLegend[gamedbs_cpu_${START}]: %
LegendO[gamedbs_cpu_${START}]: CPU user:
LegendI[gamedbs_cpu_${START}]: CPU user:
Title[gamedbs_cpu_${START}]: GameDBServer${START} CPU Loading
PageTop[gamedbs_cpu_${START}]: <H1>GameDBServer${START} CPU Loading</H1>

Target[gamedbs_mem_${START}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null gds${START} ps -aux |grep -v awk |awk /GameDBServer${START}\$/'{print \$6/1024}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null gds${START} ps -aux |grep -v awk |awk /GameDBServer${START}\$/'{print \$6/1024}'\`
MaxBytes[gamedbs_mem_${START}]: 99999
Options[gamedbs_mem_${START}]: gauge, nopercent, growright
YLegend[gamedbs_mem_${START}]: MEM Usage (MB)
ShortLegend[gamedbs_mem_${START}]: MB
LegendO[gamedbs_mem_${START}]: MEM Usage:
LegendI[gamedbs_mem_${START}]: MEM Usage:
Title[gamedbs_mem_${START}]: GameDBServer${START} MEM Usage
PageTop[gamedbs_mem_${START}]: <H1>GameDBServer${START} MEM Usage</H1>

Target[ranks_cpu_${START}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ranks${START} "COLUMNS=200 top -c -b -n 1" |awk /RankServer${START}\$/'{print \$9}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ranks${START} "COLUMNS=200 top -c -b -n 1" |awk /RankServer${START}\$/'{print \$9}'\`
MaxBytes[ranks_cpu_${START}]: 100
Options[ranks_cpu_${START}]: gauge, nopercent, growright
YLegend[ranks_cpu_${START}]: CPU Loading (%)
ShortLegend[ranks_cpu_${START}]: %
LegendO[ranks_cpu_${START}]: CPU user:
LegendI[ranks_cpu_${START}]: CPU user:
Title[ranks_cpu_${START}]: RankServer${START} CPU Loading
PageTop[ranks_cpu_${START}]: <H1>RankServer${START} CPU Loading</H1>

Target[ranks_mem_${START}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ranks${START} ps -aux |grep -v awk |awk /RankServer${START}\$/'{print \$6/1024}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ranks${START} ps -aux |grep -v awk |awk /RankServer${START}\$/'{print \$6/1024}'\`
MaxBytes[ranks_mem_${START}]: 99999
Options[ranks_mem_${START}]: gauge, nopercent, growright
YLegend[ranks_mem_${START}]: MEM Usage (MB)
ShortLegend[ranks_mem_${START}]: MB
LegendO[ranks_mem_${START}]: MEM Usage:
LegendI[ranks_mem_${START}]: MEM Usage:
Title[ranks_mem_${START}]: RankServer${START} MEM Usage
PageTop[ranks_mem_${START}]: <H1>RankServer${START} MEM Usage</H1>
EOF
)"
echo
        ;;
    world)
for ws_id in $(seq ${START} ${END}); do
echo "$(cat <<EOF
Target[world_cpu_${ws_id}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ws${ws_id} "COLUMNS=200 top -c -b -n 1" |awk /WorldServer${ws_id}\$/'{print \$9}' ;ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ws${ws_id} "COLUMNS=200 top -c -b -n 1" |awk /WorldServer${ws_id}\$/'{print \$9}'\`
MaxBytes[world_cpu_${ws_id}]: 100
Options[world_cpu_${ws_id}]: gauge, nopercent, growright
YLegend[world_cpu_${ws_id}]: CPU Loading (%)
ShortLegend[world_cpu_${ws_id}]: %
LegendO[world_cpu_${ws_id}]: CPU user:
LegendI[world_cpu_${ws_id}]: CPU user:
Title[world_cpu_${ws_id}]: WorldServer${ws_id} CPU Loading
PageTop[world_cpu_${ws_id}]: <H1>WorldServer${ws_id} CPU Loading</H1>

Target[world_mem_${ws_id}]:  \`ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ws${ws_id} ps -aux |grep -v awk |awk /WorldServer${ws_id}\$/'{print \$6/1024}';ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ws${ws_id} ps -aux |grep -v awk |awk /WorldServer${ws_id}\$/'{print \$6/1024}'\`
MaxBytes[world_mem_${ws_id}]: 99999
Options[world_mem_${ws_id}]: gauge, nopercent, growright
YLegend[world_mem_${ws_id}]: MEM Usage (MB)
ShortLegend[world_mem_${ws_id}]: MB
LegendO[world_mem_${ws_id}]: MEM Usage:
LegendI[world_mem_${ws_id}]: MEM Usage:
Title[world_mem_${ws_id}]: WorldServer${ws_id} MEM Usage
PageTop[world_mem_${ws_id}]: <H1>WorldServer${ws_id} MEM Usage</H1>
EOF
)"
echo
done
        ;;
esac
