qa: update 660 to generate index.html, fixing pcp-testsuite runs
[pcp.git] / qa / src / archinst.c
blob8c1819702371e6392b5f42cda1d05a63d6e57f4f
1 /*
2 * Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved.
3 */
5 #include <unistd.h>
6 #include <pcp/pmapi.h>
7 #include <pcp/impl.h>
9 int
10 dometric(char *name)
12 int i;
13 pmID pmidlist[] = { PM_ID_NULL };
14 pmDesc desc;
15 int sts;
16 char *iname;
17 int *ilist;
18 char **nlist;
20 if ((sts = pmLookupName(1, &name, pmidlist)) < 0)
21 return sts;
23 if ((sts = pmLookupDesc(pmidlist[0], &desc)) < 0)
24 return sts;
26 for (i = 0; i < 2; i++) {
27 iname = "no match";
28 printf("pm*InDom: inst=%d", i);
29 if ((sts = pmNameInDom(desc.indom, i, &iname)) < 0)
30 printf(" %s\n", pmErrStr(sts));
31 else {
32 printf(" iname=%s reverse lookup:", iname);
33 if ((sts = pmLookupInDom(desc.indom, iname)) < 0)
34 printf(" %s\n", pmErrStr(sts));
35 else
36 printf(" inst=%d\n", sts);
38 iname = "no match";
39 printf("pm*InDomArchive: inst=%d", i);
40 if ((sts = pmNameInDomArchive(desc.indom, i, &iname)) < 0)
41 printf(" %s\n", pmErrStr(sts));
42 else {
43 printf(" iname=%s reverse lookup:", iname);
44 if ((sts = pmLookupInDomArchive(desc.indom, iname)) < 0)
45 printf(" %s\n", pmErrStr(sts));
46 else
47 printf(" inst=%d\n", sts);
51 if ((sts = pmGetInDom(desc.indom, &ilist, &nlist)) < 0)
52 printf("pmGetInDom: %s\n", pmErrStr(sts));
53 else {
54 printf("pmGetInDom:\n");
55 for (i = 0; i < sts; i++) {
56 printf(" [%d] %s\n", ilist[i], nlist[i]);
58 free(ilist);
59 free(nlist);
62 if ((sts = pmGetInDomArchive(desc.indom, &ilist, &nlist)) < 0)
63 printf("pmGetInDomArchive: %s\n", pmErrStr(sts));
64 else {
65 printf("pmGetInDomArchive:\n");
66 for (i = 0; i < sts; i++) {
67 printf(" [%d] %s\n", ilist[i], nlist[i]);
69 free(ilist);
70 free(nlist);
72 return sts;
75 int
76 main(int argc, char **argv)
78 int c;
79 int sts;
80 int errflag = 0;
81 int type = 0;
82 int force = 0;
83 int verbose = 0;
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;
93 int samples = -1;
94 double delta = 1.0;
95 char *endnum;
97 __pmSetProgname(argv[0]);
99 while ((c = getopt(argc, argv, "a:c:D:fh:l:n:s:t:VzZ:?")) != EOF) {
100 switch (c) {
102 case 'a': /* archive name */
103 if (type != 0) {
104 fprintf(stderr, "%s: at most one of -a and/or -h allowed\n", pmProgname);
105 errflag++;
107 type = PM_CONTEXT_ARCHIVE;
108 host = optarg;
109 break;
111 case 'c': /* configfile */
112 if (configfile != (char *)0) {
113 fprintf(stderr, "%s: at most one -c option allowed\n", pmProgname);
114 errflag++;
116 configfile = optarg;
117 break;
119 #ifdef PCP_DEBUG
120 case 'D': /* debug flag */
121 sts = __pmParseDebug(optarg);
122 if (sts < 0) {
123 fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
124 pmProgname, optarg);
125 errflag++;
127 else
128 pmDebug |= sts;
129 break;
130 #endif
132 case 'f': /* force */
133 force++;
134 break;
136 case 'h': /* contact PMCD on this hostname */
137 if (type != 0) {
138 fprintf(stderr, "%s: at most one of -a and/or -h allowed\n", pmProgname);
139 errflag++;
141 host = optarg;
142 type = PM_CONTEXT_HOST;
143 break;
145 case 'l': /* logfile */
146 logfile = optarg;
147 break;
149 case 'n': /* alternative name space file */
150 namespace = optarg;
151 break;
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);
157 errflag++;
159 break;
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);
165 errflag++;
167 break;
169 case 'V': /* verbose */
170 verbose++;
171 break;
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);
176 errflag++;
178 zflag++;
179 break;
181 case 'Z': /* $TZ timezone */
182 if (zflag) {
183 fprintf(stderr, "%s: at most one of -Z and/or -z allowed\n", pmProgname);
184 errflag++;
186 tz = optarg;
187 break;
189 case '?':
190 default:
191 errflag++;
192 break;
196 if (zflag && type == 0) {
197 fprintf(stderr, "%s: -z requires an explicit -a or -h option\n", pmProgname);
198 errflag++;
201 if (errflag) {
202 fprintf(stderr,
203 "Usage: %s options ...\n\
205 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\
209 -f force .. \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",
218 pmProgname);
219 exit(1);
222 if (logfile != (char *)0) {
223 __pmOpenLog(pmProgname, logfile, stderr, &sts);
224 if (sts < 0) {
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));
232 exit(1);
236 if (type == 0) {
237 type = PM_CONTEXT_HOST;
238 gethostname(local, sizeof(local));
239 host = 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));
245 else
246 fprintf(stderr, "%s: Cannot open archive \"%s\": %s\n",
247 pmProgname, host, pmErrStr(sts));
248 exit(1);
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));
255 exit(1);
259 if (zflag) {
260 if ((tzh = pmNewContextZone()) < 0) {
261 fprintf(stderr, "%s: Cannot set context timezone: %s\n",
262 pmProgname, pmErrStr(tzh));
263 exit(1);
265 if (type == PM_CONTEXT_ARCHIVE)
266 printf("Note: timezone set to local timezone of host \"%s\" from archive\n\n",
267 label.ll_hostname);
268 else
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));
275 exit(1);
277 printf("Note: timezone set to \"TZ=%s\"\n\n", tz);
279 else
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]);
286 if (sts < 0)
287 printf("Error: %s\n", pmErrStr(sts));
288 optind++;
291 exit(0);