On 2/27/2008 6:44 PM, dnlchen@[EMAIL PROTECTED]
wrote:
> Input (MySQL status):
>
> | Com_select | 16653146213 |
> | Com_delete | 43654772 |
> | Com_insert | 637410971 |
> | Com_update | 673829655 |
>
> Output:
> Read Query #
> Write Query #
>
> Below script works, but I think there must be a concise AWK one.
>
> #!/bin/sh
>
> declare -i m n i j
>
> m=`awk '$2 == "Com_select" {print $4}' /var/log/mysql/status1`
> n=`awk '$2 == "Com_select" {print $4}' /var/log/mysql/status2`
>
> i=`awk '$2 == "Com_delete" || $2 == "Com_insert" || $2 ==
> "Com_update" {sum += $4} END {print sum}' /var/log/mysql/status1`
> j=`awk '$2 == "Com_delete" || $2 == "Com_insert" || $2 ==
> "Com_update" {sum += $4} END {print sum}' /var/log/mysql/status2`
>
> awk -v Read1=$m -v Read2=$n 'BEGIN { printf( "%.4f\n", (Read2 - Read1)/
> 300 ) }'
> awk -v Write1=$i -v Write2=$j 'BEGIN { printf( "%.4f\n", (Write2 -
> Write1)/300 ) }'
Something like this (untested):
awk '
$2=="Com_select" {read[NR==FNR] = $4}
$2~/^Com_(delete|insert|update)$/ {write[NR==FNR] += $4}
END {printf "%.4f\n%.f4\n", (read[0] - read[1])/300, (write[0] -
write[1])/300}
' /var/log/mysql/status1 /var/log/mysql/status2
If your posted input is truly all you have in the files (i.e. $2 is always
one
of the Com_* you show), then all you really need is:
awk '$2=="Com_select" {read[NR==FNR] = $4; next} {write[NR==FNR] += $4}
END {printf "%.4f\n%.f4\n", (read[0] - read[1])/300, (write[0] -
write[1])/300}
' /var/log/mysql/status1 /var/log/mysql/status2
Ed.


|