2 * chk_metric_types - check pmResult value types match pmDesc.
4 * Copyright (c) 1995-2001 Silicon Graphics, Inc. All Rights Reserved.
11 static void checkMetric(const char *);
14 main(int argc
, char **argv
)
21 char *host
= NULL
; /* pander to gcc */
22 int mode
= PM_MODE_INTERP
; /* mode for archives */
23 char *configfile
= NULL
;
25 pmLogLabel label
; /* get hostname for archives */
26 int zflag
= 0; /* for -z */
27 char *tz
= NULL
; /* for -Z timezone */
28 int tzh
; /* initial timezone handle */
29 char local
[MAXHOSTNAMELEN
];
30 char *pmnsfile
= PM_NS_DEFAULT
;
35 __pmSetProgname(argv
[0]);
37 while ((c
= getopt(argc
, argv
, "a:c:D:h:l:Ln:s:t:U:VzZ:?")) != EOF
) {
40 case 'a': /* archive name */
42 fprintf(stderr
, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname
);
45 type
= PM_CONTEXT_ARCHIVE
;
49 case 'c': /* configfile */
50 if (configfile
!= NULL
) {
51 fprintf(stderr
, "%s: at most one -c option allowed\n", pmProgname
);
57 case 'D': /* debug flag */
58 sts
= __pmParseDebug(optarg
);
60 fprintf(stderr
, "%s: unrecognized debug flag specification (%s)\n",
68 case 'h': /* contact PMCD on this hostname */
70 fprintf(stderr
, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname
);
74 type
= PM_CONTEXT_HOST
;
77 case 'L': /* LOCAL, no PMCD */
79 fprintf(stderr
, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname
);
83 type
= PM_CONTEXT_LOCAL
;
84 putenv("PMDA_LOCAL_PROC="); /* if proc PMDA needed */
85 putenv("PMDA_LOCAL_SAMPLE="); /* if sampledso PMDA needed */
88 case 'l': /* logfile */
92 case 'n': /* alternative name space file */
96 case 's': /* sample count */
97 samples
= (int)strtol(optarg
, &endnum
, 10);
98 if (*endnum
!= '\0' || samples
< 0) {
99 fprintf(stderr
, "%s: -s requires numeric argument\n", pmProgname
);
104 case 't': /* delta seconds (double) */
105 delta
= strtod(optarg
, &endnum
);
106 if (*endnum
!= '\0' || delta
<= 0.0) {
107 fprintf(stderr
, "%s: -t requires floating point argument\n", pmProgname
);
112 case 'U': /* uninterpolated archive log */
114 fprintf(stderr
, "%s: at most one of -a, -h, -L and -U allowed\n", pmProgname
);
117 type
= PM_CONTEXT_ARCHIVE
;
122 case 'V': /* verbose */
126 case 'z': /* timezone from host */
128 fprintf(stderr
, "%s: at most one of -Z and/or -z allowed\n", pmProgname
);
134 case 'Z': /* $TZ timezone */
136 fprintf(stderr
, "%s: at most one of -Z and/or -z allowed\n", pmProgname
);
149 if (zflag
&& type
== 0) {
150 fprintf(stderr
, "%s: -z requires an explicit -a, -h or -U option\n", pmProgname
);
156 "Usage: %s options ...\n\
159 -a archive metrics source is an archive log\n\
160 -c configfile file to load configuration from\n\
161 -D debug standard PCP debug flag\n\
162 -h host metrics source is PMCD on host\n\
163 -l logfile redirect diagnostics and trace output\n\
164 -L use local context instead of PMCD\n\
165 -n pmnsfile use an alternative PMNS\n\
166 -s samples terminate after this many iterations\n\
167 -t delta sample interval in seconds(float) [default 1.0]\n\
168 -U archive metrics source is an uninterpolated archive log\n\
169 -V verbose/diagnostic output\n\
170 -z set reporting timezone to local time for host from -a, -h or -U\n\
171 -Z timezone set reporting timezone\n",
176 if (logfile
!= NULL
) {
177 __pmOpenLog(pmProgname
, logfile
, stderr
, &sts
);
179 fprintf(stderr
, "%s: Could not open logfile \"%s\"\n", pmProgname
, logfile
);
183 if (pmnsfile
!= PM_NS_DEFAULT
&& (sts
= pmLoadASCIINameSpace(pmnsfile
, 1)) < 0) {
184 printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname
,
185 pmnsfile
, pmErrStr(sts
));
190 type
= PM_CONTEXT_HOST
;
191 gethostname(local
, sizeof(local
));
194 if ((sts
= pmNewContext(type
, host
)) < 0) {
195 if (type
== PM_CONTEXT_HOST
)
196 fprintf(stderr
, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
197 pmProgname
, host
, pmErrStr(sts
));
199 fprintf(stderr
, "%s: Cannot open archive \"%s\": %s\n",
200 pmProgname
, host
, pmErrStr(sts
));
204 if (type
== PM_CONTEXT_ARCHIVE
) {
205 if ((sts
= pmGetArchiveLabel(&label
)) < 0) {
206 fprintf(stderr
, "%s: Cannot get archive label record: %s\n",
207 pmProgname
, pmErrStr(sts
));
210 if (mode
!= PM_MODE_INTERP
) {
211 if ((sts
= pmSetMode(mode
, &label
.ll_start
, 0)) < 0) {
212 fprintf(stderr
, "%s: pmSetMode: %s\n", pmProgname
, pmErrStr(sts
));
220 if ((tzh
= pmNewContextZone()) < 0) {
221 fprintf(stderr
, "%s: Cannot set context timezone: %s\n",
222 pmProgname
, pmErrStr(tzh
));
225 if (type
== PM_CONTEXT_ARCHIVE
)
226 printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n",
229 printf("Note: timezone set to local timezone of host \"%s\"\n\n", host
);
231 else if (tz
!= NULL
) {
232 if ((tzh
= pmNewZone(tz
)) < 0) {
233 fprintf(stderr
, "%s: Cannot set timezone to \"%s\": %s\n",
234 pmProgname
, tz
, pmErrStr(tzh
));
237 printf("Note: timezone set to \"TZ=%s\"\n\n", tz
);
240 tzh
= pmNewContextZone();
242 /* non-flag args are argv[optind] ... argv[argc-1] */
243 if (optind
== argc
) {
244 if ((sts
= pmTraversePMNS(NULL
, checkMetric
)) < 0) {
245 fprintf(stderr
, "%s: pmTraversePMNS: %s\n", pmProgname
, pmErrStr(sts
));
250 while (optind
< argc
) {
251 if ((sts
= pmTraversePMNS(argv
[optind
], checkMetric
)) < 0) {
252 fprintf(stderr
, "%s: pmTraversePMNS: %s\n", pmProgname
, pmErrStr(sts
));
262 checkMetric(const char *metric
)
266 char *nameList
[] = { NULL
};
267 pmID pmidList
[] = { PM_IN_NULL
};
271 /* pmLookupName will not modify this string */
272 nameList
[0] = (char *)metric
;
274 if ((sts
= pmLookupName(1, nameList
, pmidList
)) < 0) {
275 fprintf(stderr
, "%s: pmLookupName: %s\n", pmProgname
, pmErrStr(sts
));
279 if ((sts
= pmLookupDesc(pmidList
[0], &desc
)) < 0) {
280 fprintf(stderr
, "%s: pmLookupDesc: %s\n", pmProgname
, pmErrStr(sts
));
284 if (desc
.type
== PM_TYPE_NOSUPPORT
)
287 if ((sts
= pmFetch(1, pmidList
, &result
)) < 0) {
288 fprintf(stderr
, "%s: pmfetch: %s\n", pmProgname
, pmErrStr(sts
));
292 if (result
->numpmid
> 0) {
293 for (i
=0; i
< result
->vset
[0]->numval
; i
++) {
294 if (result
->vset
[0]->valfmt
!= PM_VAL_INSITU
) {
295 pmValue
*val
= &result
->vset
[0]->vlist
[i
];
296 if (val
->value
.pval
->vtype
== PM_TYPE_UNKNOWN
) {
297 printf("metric \"%s\" vtype for instance %d is PM_TYPE_UNKNOWN\n",
301 if (val
->value
.pval
->vtype
!= desc
.type
) {
302 printf("metric \"%s\" vtype for instance %d, type (%s)",
303 metric
, val
->inst
, pmTypeStr(val
->value
.pval
->vtype
));
304 printf(" does not match descriptor (%s)\n", pmTypeStr(desc
.type
));
312 pmFreeResult(result
);