1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#!/bin/sh
#
# Copyright (c) 1995-2001,2004 Silicon Graphics, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Get standard environment
. $PCP_DIR/etc/pcp.env
_usage()
{
echo "Usage: mkaf [findopts] filename ..."
}
# check for magic numbers in a file that indicate it is a PCP archive
#
# if file(1) was reliable, this would be much easier, ... sigh
#
# if you need to change this, make consistent changes in all these
# places:
# _check_file() in src/pmafm/mkaf
# _is_archive() in src/pmafm/pmafm
# _is_archive() in src/pmview/front-ends/pmview-args
#
_is_archive()
{
dd ibs=1 count=7 if="$1" 2>/dev/null | od -X | $PCP_AWK_PROG '
BEGIN { sts = 1 }
NR == 1 && NF == 5 && $2 == "0000" && $3 == "0084" && $4 == "5005" && $5 == "2600" { sts = 0 }
NR == 1 && NF == 5 && $2 == "0000" && $3 == "8400" && $4 == "0550" && $5 == "0026" { sts = 0 }
NR == 1 && NF == 3 && $2 == "00000084" && $3 == "50052600" { sts = 0 }
NR == 1 && NF == 3 && $2 == "84000000" && $3 == "00260550" { sts = 0 }
END { exit sts }'
return $?
}
if [ $# -eq 0 ]
then
_usage
exit 1
fi
tmp=`mktemp -d /tmp/pcp.XXXXXXXXX` || exit 1
status=0
trap "rm -rf $tmp; exit \$status" 0 1 2 3 15
findopts=""
while [ $# -gt 0 ]
do
case $1
in
-?)
_usage
exit 1
;;
-*)
findopts="$findopts $1"
;;
*)
if [ -d $1 ]
then
[ -z "$findopts" ] && findopts="-follow"
$PCP_ECHO_PROG >&2 $PCP_ECHO_N "Searching \"find $1 $findopts ...\" $PCP_ECHO_C"
find $1 $findopts -type f -print \
| while read file
do
if _is_archive $file
then
echo $file >>$tmp/base
fi
done
$PCP_ECHO_PROG >&2 " done"
elif [ ! -f $1 ]
then
echo >&2 "mkaf: $1: No such file"
elif _is_archive $1
then
echo $1 >>$tmp/base
else
echo >&2 "mkaf: $1: Not a PCP archive file"
fi
;;
esac
shift
done
if [ ! -s $tmp/base ]
then
echo >&2 "mkaf: Warning: no PCP archives found, so no folio created"
status=1
exit
fi
host=somehost
which hostname >/dev/null 2>&1 && host=`hostname`
cat <<End-of-File
PCPFolio
Version: 1
# use pmafm(1) to process this PCP archive folio
#
Created: on $host at `date`
Creator: pmchart
# Host Basename
#
End-of-File
sed <$tmp/base \
-e 's/\.[0-9][0-9]*$//' \
-e 's/\.meta$//' \
-e 's/\.index$//' \
| sort -u \
| while read base
do
host=`pmdumplog -l $base 2>&1 | sed -n -e '/^Performance metrics/s/.* host //p'`
if [ -z "$host" ]
then
echo >&2 "mkaf: Warning: cannot extract hostname from archive \"$base\" ... skipped"
else
printf "%-15s %-23s %s\n" "Archive:" "$host" "$base"
fi
done
exit
|