7. Producing Transaction Stats via SQL
SET NOCOUNT ON
;WITH Status_CTE (Axis, Label, Value, Color)
AS
(
SELECT
-- This gives the hour of the day, eg 08:00
convert(nvarchar,DATEPART(hour,GetDate()),2)+':'+
Right('00' +
convert(nvarchar,DATEPART(minute,GetDate()),2), 2)
AS Axis,
CASE Status
when 4 then 'Completed'
when 5 then 'Failed'
END as Label,
count(*) as Value,
CASE Status
when 4 then 'green'
when 5 then 'yellow'
END as Color
FROM Orders WITH (NOLOCK)
WHERE Created BETWEEN dateadd(DAY,0,
datediff(day,0, GETDATE())) AND
dateadd(DAY,1, datediff(day,0, GETDATE()))
GROUP BY Status
)
SELECT
Axis,
Label,
SUM(Value) as Value,
Color
FROM Status_CTE
GROUP BY Axis, Label, Color;
sqlcmd -S myserver.com -U user -P pass -d
dbname -i .xxxx_stats.sql -h-1 -s"|" -w 700 -W
-o xxxx_stats.txt
8. How data looks like
15:15|22.02|75.73|0.90
15:16|23.04|75.62|0.22
15:17|0.81|5.15|62.87
15:18|0.00|4.71|60.99
15:19|0.00|0.75|0.00
15:20|0.25|1.00|0.00
15:21|0.50|1.00|0.00
15:22|0.25|0.50|0.00
15:23|0.25|0.75|0.00
15:24|0.00|1.27|0.00
9. Producing System Stats
FILENAME=`hostname`_cpu.txt
sar -u 1 1 | tail -2 | head -n1 | awk '{print
substr($1,0,5)"|"$3"|"$5"|"$6}' >> $FILENAME
tail -10 $FILENAME > $FILENAME.tmp
mv $FILENAME.tmp $FILENAME
ftp -n -i myserver.com <<End-of-Session
user myserver.com|transactiondata "Transaction2014"
put $FILENAME
bye
End-of-Session
EOF