2 * Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
13 pmID pmidlist
[] = { PM_ID_NULL
};
20 if ((sts
= pmLookupName(1, &name
, pmidlist
)) < 0)
23 if ((sts
= pmLookupDesc(pmidlist
[0], &desc
)) < 0)
26 for (i
= 0; i
< 2; i
++) {
28 printf("pm*InDom: inst=%d", i
);
29 if ((sts
= pmNameInDom(desc
.indom
, i
, &iname
)) < 0)
30 printf(" %s\n", pmErrStr(sts
));
32 printf(" iname=%s reverse lookup:", iname
);
33 if ((sts
= pmLookupInDom(desc
.indom
, iname
)) < 0)
34 printf(" %s\n", pmErrStr(sts
));
36 printf(" inst=%d\n", sts
);
39 printf("pm*InDomArchive: inst=%d", i
);
40 if ((sts
= pmNameInDomArchive(desc
.indom
, i
, &iname
)) < 0)
41 printf(" %s\n", pmErrStr(sts
));
43 printf(" iname=%s reverse lookup:", iname
);
44 if ((sts
= pmLookupInDomArchive(desc
.indom
, iname
)) < 0)
45 printf(" %s\n", pmErrStr(sts
));
47 printf(" inst=%d\n", sts
);
51 if ((sts
= pmGetInDom(desc
.indom
, &ilist
, &nlist
)) < 0)
52 printf("pmGetInDom: %s\n", pmErrStr(sts
));
54 printf("pmGetInDom:\n");
55 for (i
= 0; i
< sts
; i
++) {
56 printf(" [%d] %s\n", ilist
[i
], nlist
[i
]);
62 if ((sts
= pmGetInDomArchive(desc
.indom
, &ilist
, &nlist
)) < 0)
63 printf("pmGetInDomArchive: %s\n", pmErrStr(sts
));
65 printf("pmGetInDomArchive:\n");
66 for (i
= 0; i
< sts
; i
++) {
67 printf(" [%d] %s\n", ilist
[i
], nlist
[i
]);
76 main(int argc
, char **argv
)
84 char *host
= NULL
; /* pander to gcc */
85 char *configfile
= (char *)0;
86 char *logfile
= (char *)0;
87 pmLogLabel label
; /* get hostname for archives */
88 int zflag
= 0; /* for -z */
89 char *tz
= (char *)0; /* for -Z timezone */
90 int tzh
; /* initial timezone handle */
91 char local
[MAXHOSTNAMELEN
];
92 char *namespace = PM_NS_DEFAULT
;
97 __pmSetProgname(argv
[0]);
99 while ((c
= getopt(argc
, argv
, "a:c:D:fh:l:n:s:t:VzZ:?")) != EOF
) {
102 case 'a': /* archive name */
104 fprintf(stderr
, "%s: at most one of -a and/or -h allowed\n", pmProgname
);
107 type
= PM_CONTEXT_ARCHIVE
;
111 case 'c': /* configfile */
112 if (configfile
!= (char *)0) {
113 fprintf(stderr
, "%s: at most one -c option allowed\n", pmProgname
);
120 case 'D': /* debug flag */
121 sts
= __pmParseDebug(optarg
);
123 fprintf(stderr
, "%s: unrecognized debug flag specification (%s)\n",
132 case 'f': /* force */
136 case 'h': /* contact PMCD on this hostname */
138 fprintf(stderr
, "%s: at most one of -a and/or -h allowed\n", pmProgname
);
142 type
= PM_CONTEXT_HOST
;
145 case 'l': /* logfile */
149 case 'n': /* alternative name space file */
153 case 's': /* sample count */
154 samples
= (int)strtol(optarg
, &endnum
, 10);
155 if (*endnum
!= '\0' || samples
< 0) {
156 fprintf(stderr
, "%s: -s requires numeric argument\n", pmProgname
);
161 case 't': /* delta seconds (double) */
162 delta
= strtod(optarg
, &endnum
);
163 if (*endnum
!= '\0' || delta
<= 0.0) {
164 fprintf(stderr
, "%s: -t requires floating point argument\n", pmProgname
);
169 case 'V': /* verbose */
173 case 'z': /* timezone from host */
174 if (tz
!= (char *)0) {
175 fprintf(stderr
, "%s: at most one of -Z and/or -z allowed\n", pmProgname
);
181 case 'Z': /* $TZ timezone */
183 fprintf(stderr
, "%s: at most one of -Z and/or -z allowed\n", pmProgname
);
196 if (zflag
&& type
== 0) {
197 fprintf(stderr
, "%s: -z requires an explicit -a or -h option\n", pmProgname
);
203 "Usage: %s options ...\n\
206 -a archive metrics source is an archive log\n\
207 -c configfile file to load configuration from\n\
208 -D debug standard PCP debug flag\n\
210 -h host metrics source is PMCD on host\n\
211 -l logfile redirect diagnostics and trace output\n\
212 -n namespace use an alternative PMNS\n\
213 -s samples terminate after this many iterations\n\
214 -t delta sample interval in seconds(float) [default 1.0]\n\
215 -V verbose/diagnostic output\n\
216 -z set reporting timezone to local time for host from -a or -h\n\
217 -Z timezone set reporting timezone\n",
222 if (logfile
!= (char *)0) {
223 __pmOpenLog(pmProgname
, logfile
, stderr
, &sts
);
225 fprintf(stderr
, "%s: Could not open logfile \"%s\"\n", pmProgname
, logfile
);
229 if (namespace != PM_NS_DEFAULT
) {
230 if ((sts
= pmLoadASCIINameSpace(namespace, 1)) < 0) {
231 printf("%s: Cannot load namespace from \"%s\": %s\n", pmProgname
, namespace, pmErrStr(sts
));
237 type
= PM_CONTEXT_HOST
;
238 gethostname(local
, sizeof(local
));
241 if ((sts
= pmNewContext(type
, host
)) < 0) {
242 if (type
== PM_CONTEXT_HOST
)
243 fprintf(stderr
, "%s: Cannot connect to PMCD on host \"%s\": %s\n",
244 pmProgname
, host
, pmErrStr(sts
));
246 fprintf(stderr
, "%s: Cannot open archive \"%s\": %s\n",
247 pmProgname
, host
, pmErrStr(sts
));
251 if (type
== PM_CONTEXT_ARCHIVE
) {
252 if ((sts
= pmGetArchiveLabel(&label
)) < 0) {
253 fprintf(stderr
, "%s: Cannot get archive label record: %s\n",
254 pmProgname
, pmErrStr(sts
));
260 if ((tzh
= pmNewContextZone()) < 0) {
261 fprintf(stderr
, "%s: Cannot set context timezone: %s\n",
262 pmProgname
, pmErrStr(tzh
));
265 if (type
== PM_CONTEXT_ARCHIVE
)
266 printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n",
269 printf("Note: timezone set to local timezone of host \"%s\"\n\n", host
);
271 else if (tz
!= (char *)0) {
272 if ((tzh
= pmNewZone(tz
)) < 0) {
273 fprintf(stderr
, "%s: Cannot set timezone to \"%s\": %s\n",
274 pmProgname
, tz
, pmErrStr(tzh
));
277 printf("Note: timezone set to \"TZ=%s\"\n\n", tz
);
280 tzh
= pmNewContextZone();
282 /* non-flag args are argv[optind] ... argv[argc-1] */
283 while (optind
< argc
) {
284 printf("%s:\n", argv
[optind
]);
285 sts
= dometric(argv
[optind
]);
287 printf("Error: %s\n", pmErrStr(sts
));