]> granicus.if.org Git - sysstat/blob - pcp_stats.c
f88294667439808b53ceab5dc64de04ac6471399
[sysstat] / pcp_stats.c
1 /*
2  * pcp_stats.c: Funtions used by sadf to create PCP archive files.
3  * (C) 2019 by Sebastien GODARD (sysstat <at> orange.fr)
4  *
5  ***************************************************************************
6  * This program is free software; you can redistribute it and/or modify it *
7  * under the terms of the GNU General Public License as published  by  the *
8  * Free Software Foundation; either version 2 of the License, or (at  your *
9  * option) any later version.                                              *
10  *                                                                         *
11  * This program is distributed in the hope that it  will  be  useful,  but *
12  * WITHOUT ANY WARRANTY; without the implied warranty  of  MERCHANTABILITY *
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
14  * for more details.                                                       *
15  *                                                                         *
16  * You should have received a copy of the GNU General Public License along *
17  * with this program; if not, write to the Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA              *
19  ***************************************************************************
20  */
21
22 #include "sa.h"
23 #include "pcp_stats.h"
24
25 #ifdef USE_NLS
26 #include <locale.h>
27 #include <libintl.h>
28 #define _(string) gettext(string)
29 #else
30 #define _(string) (string)
31 #endif
32
33 extern unsigned int flags;
34
35 #ifdef HAVE_PCP
36 #include <pcp/pmapi.h>
37 #include <pcp/import.h>
38 #endif
39
40 /*
41  ***************************************************************************
42  * Display CPU statistics in PCP format.
43  *
44  * IN:
45  * @a           Activity structure with statistics.
46  * @curr        Index in array for current sample statistics.
47  * @itv         Interval of time in 1/100th of a second.
48  * @record_hdr  Record header for current sample.
49  ***************************************************************************
50  */
51 __print_funct_t pcp_print_cpu_stats(struct activity *a, int curr, unsigned long long itv,
52                                     struct record_header *record_hdr)
53 {
54 #ifdef HAVE_PCP
55         int i;
56         unsigned long long deltot_jiffies = 1;
57         char buf[64], cpuno[64];
58         unsigned char offline_cpu_bitmap[BITMAP_SIZE(NR_CPUS)] = {0};
59         char *str;
60         struct stats_cpu *scc, *scp;
61
62         /*
63          * @nr[curr] cannot normally be greater than @nr_ini.
64          * Yet we have created PCP metrics only for @nr_ini CPU.
65          */
66         if (a->nr[curr] > a->nr_ini) {
67                 a->nr_ini = a->nr[curr];
68         }
69
70         /*
71          * Compute CPU "all" as sum of all individual CPU (on SMP machines)
72          * and look for offline CPU.
73          */
74         if (a->nr_ini > 1) {
75                 deltot_jiffies = get_global_cpu_statistics(a, !curr, curr,
76                                                            flags, offline_cpu_bitmap);
77         }
78
79         for (i = 0; (i < a->nr_ini) && (i < a->bitmap->b_size + 1); i++) {
80
81                 /* Should current CPU (including CPU "all") be displayed? */
82                 if (!(a->bitmap->b_array[i >> 3] & (1 << (i & 0x07))) ||
83                     offline_cpu_bitmap[i >> 3] & (1 << (i & 0x07)))
84                         /* Don't display CPU */
85                         continue;
86
87                 scc = (struct stats_cpu *) ((char *) a->buf[curr]  + i * a->msize);
88                 scp = (struct stats_cpu *) ((char *) a->buf[!curr] + i * a->msize);
89
90                 if (!i) {
91                         /* This is CPU "all" */
92                         str = NULL;
93
94                         if (a->nr_ini == 1) {
95                                 /*
96                                  * This is a UP machine. In this case
97                                  * interval has still not been calculated.
98                                  */
99                                 deltot_jiffies = get_per_cpu_interval(scc, scp);
100                         }
101                         if (!deltot_jiffies) {
102                                 /* CPU "all" cannot be tickless */
103                                 deltot_jiffies = 1;
104                         }
105                 }
106                 else {
107                         sprintf(cpuno, "cpu%d", i - 1);
108                         str = cpuno;
109
110                         /*
111                          * Recalculate interval for current proc.
112                          * If result is 0 then current CPU is a tickless one.
113                          */
114                         deltot_jiffies = get_per_cpu_interval(scc, scp);
115
116                         if (!deltot_jiffies) {
117                                 /* Current CPU is tickless */
118                                 pmiPutValue("kernel.percpu.cpu.user", cpuno, "0");
119                                 pmiPutValue("kernel.percpu.cpu.nice", cpuno, "0");
120                                 pmiPutValue("kernel.percpu.cpu.sys", cpuno, "0");
121                                 pmiPutValue("kernel.percpu.cpu.iowait", cpuno, "0");
122                                 pmiPutValue("kernel.percpu.cpu.steal", cpuno, "0");
123                                 pmiPutValue("kernel.percpu.cpu.hardirq", cpuno, "0");
124                                 pmiPutValue("kernel.percpu.cpu.softirq", cpuno, "0");
125                                 pmiPutValue("kernel.percpu.cpu.guest", cpuno, "0");
126                                 pmiPutValue("kernel.percpu.cpu.guest_nice", cpuno, "0");
127                                 pmiPutValue("kernel.percpu.cpu.idle", cpuno, "100");
128
129                                 continue;
130                         }
131                 }
132
133                 snprintf(buf, sizeof(buf), "%f",
134                          (scc->cpu_user - scc->cpu_guest) < (scp->cpu_user - scp->cpu_guest) ?
135                          0.0 :
136                          ll_sp_value(scp->cpu_user - scp->cpu_guest,
137                                      scc->cpu_user - scc->cpu_guest, deltot_jiffies));
138                 pmiPutValue(i ? "kernel.percpu.cpu.user" : "kernel.all.cpu.user", str, buf);
139
140                 snprintf(buf, sizeof(buf), "%f",
141                          (scc->cpu_nice - scc->cpu_guest_nice) < (scp->cpu_nice - scp->cpu_guest_nice) ?
142                          0.0 :
143                          ll_sp_value(scp->cpu_nice - scp->cpu_guest_nice,
144                                      scc->cpu_nice - scc->cpu_guest_nice, deltot_jiffies));
145                 pmiPutValue(i ? "kernel.percpu.cpu.nice" : "kernel.all.cpu.nice", str, buf);
146
147                 snprintf(buf, sizeof(buf), "%f",
148                          ll_sp_value(scp->cpu_sys, scc->cpu_sys, deltot_jiffies));
149                 pmiPutValue(i ? "kernel.percpu.cpu.sys" : "kernel.all.cpu.sys", str, buf);
150
151                 snprintf(buf, sizeof(buf), "%f",
152                          ll_sp_value(scp->cpu_iowait, scc->cpu_iowait, deltot_jiffies));
153                 pmiPutValue(i ? "kernel.percpu.cpu.iowait" : "kernel.all.cpu.iowait", str, buf);
154
155                 snprintf(buf, sizeof(buf), "%f",
156                          ll_sp_value(scp->cpu_steal, scc->cpu_steal, deltot_jiffies));
157                 pmiPutValue(i ? "kernel.percpu.cpu.steal" : "kernel.all.cpu.steal", str, buf);
158
159                 snprintf(buf, sizeof(buf), "%f",
160                          ll_sp_value(scp->cpu_hardirq, scc->cpu_hardirq, deltot_jiffies));
161                 pmiPutValue(i ? "kernel.percpu.cpu.hardirq" : "kernel.all.cpu.hardirq", str, buf);
162
163                 snprintf(buf, sizeof(buf), "%f",
164                          ll_sp_value(scp->cpu_softirq, scc->cpu_softirq, deltot_jiffies));
165                 pmiPutValue(i ? "kernel.percpu.cpu.softirq" : "kernel.all.cpu.softirq", str, buf);
166
167                 snprintf(buf, sizeof(buf), "%f",
168                          ll_sp_value(scp->cpu_guest, scc->cpu_guest, deltot_jiffies));
169                 pmiPutValue(i ? "kernel.percpu.cpu.guest" : "kernel.all.cpu.guest", str, buf);
170
171                 snprintf(buf, sizeof(buf), "%f",
172                          ll_sp_value(scp->cpu_guest_nice, scc->cpu_guest_nice, deltot_jiffies));
173                 pmiPutValue(i ? "kernel.percpu.cpu.guest_nice" : "kernel.all.cpu.guest_nice", str, buf);
174
175                 snprintf(buf, sizeof(buf), "%f",
176                          scc->cpu_idle < scp->cpu_idle ?
177                          0.0 :
178                          ll_sp_value(scp->cpu_idle, scc->cpu_idle, deltot_jiffies));
179                 pmiPutValue(i ? "kernel.percpu.cpu.idle" : "kernel.all.cpu.idle", str, buf);
180         }
181 #endif  /* HAVE_PCP */
182 }
183
184 /*
185  ***************************************************************************
186  * Display task creation and context switch statistics in PCP format.
187  *
188  * IN:
189  * @a           Activity structure with statistics.
190  * @curr        Index in array for current sample statistics.
191  * @itv         Interval of time in 1/100th of a second.
192  * @record_hdr  Record header for current sample.
193  ***************************************************************************
194  */
195 __print_funct_t pcp_print_pcsw_stats(struct activity *a, int curr, unsigned long long itv,
196                                      struct record_header *record_hdr)
197 {
198 #ifdef HAVE_PCP
199         char buf[64];
200         struct stats_pcsw
201                 *spc = (struct stats_pcsw *) a->buf[curr],
202                 *spp = (struct stats_pcsw *) a->buf[!curr];
203
204         snprintf(buf, sizeof(buf), "%f",
205                  S_VALUE(spp->context_switch, spc->context_switch, itv));
206         pmiPutValue("kernel.all.pswitch", NULL, buf);
207
208         snprintf(buf, sizeof(buf), "%f",
209                  S_VALUE(spp->processes, spc->processes, itv));
210         pmiPutValue("kernel.all.proc", NULL, buf);
211 #endif  /* HAVE_PCP */
212 }
213
214 /*
215  ***************************************************************************
216  * Display interrupts statistics in PCP format.
217  *
218  * IN:
219  * @a           Activity structure with statistics.
220  * @curr        Index in array for current sample statistics.
221  * @itv         Interval of time in 1/100th of a second.
222  * @record_hdr  Record header for current sample.
223  ***************************************************************************
224  */
225 __print_funct_t pcp_print_irq_stats(struct activity *a, int curr, unsigned long long itv,
226                                     struct record_header *record_hdr)
227 {
228 #ifdef HAVE_PCP
229         char buf[64];
230         struct stats_irq
231                 *sic = (struct stats_irq *) a->buf[curr],
232                 *sip = (struct stats_irq *) a->buf[!curr];
233
234         snprintf(buf, sizeof(buf), "%f",
235                  S_VALUE(sip->irq_nr, sic->irq_nr, itv));
236         pmiPutValue("kernel.all.intr", NULL, buf);
237 #endif  /* HAVE_PCP */
238 }
239
240 /*
241  ***************************************************************************
242  * Display swapping statistics in PCP format.
243  *
244  * IN:
245  * @a           Activity structure with statistics.
246  * @curr        Index in array for current sample statistics.
247  * @itv         Interval of time in 1/100th of a second.
248  * @record_hdr  Record header for current sample.
249  ***************************************************************************
250  */
251 __print_funct_t pcp_print_swap_stats(struct activity *a, int curr, unsigned long long itv,
252                                      struct record_header *record_hdr)
253 {
254 #ifdef HAVE_PCP
255         char buf[64];
256         struct stats_swap
257                 *ssc = (struct stats_swap *) a->buf[curr],
258                 *ssp = (struct stats_swap *) a->buf[!curr];
259
260         snprintf(buf, sizeof(buf), "%f",
261                  S_VALUE(ssp->pswpin, ssc->pswpin, itv));
262         pmiPutValue("swap.pagesin", NULL, buf);
263
264         snprintf(buf, sizeof(buf), "%f",
265                  S_VALUE(ssp->pswpout, ssc->pswpout, itv));
266         pmiPutValue("swap.pagesout", NULL, buf);
267 #endif  /* HAVE_PCP */
268 }
269
270 /*
271  ***************************************************************************
272  * Display paging statistics in PCP format.
273  *
274  * IN:
275  * @a           Activity structure with statistics.
276  * @curr        Index in array for current sample statistics.
277  * @itv         Interval of time in 1/100th of a second.
278  * @record_hdr  Record header for current sample.
279  ***************************************************************************
280  */
281 __print_funct_t pcp_print_paging_stats(struct activity *a, int curr, unsigned long long itv,
282                                        struct record_header *record_hdr)
283 {
284 #ifdef HAVE_PCP
285         char buf[64];
286         struct stats_paging
287                 *spc = (struct stats_paging *) a->buf[curr],
288                 *spp = (struct stats_paging *) a->buf[!curr];
289
290         snprintf(buf, sizeof(buf), "%f",
291                  S_VALUE(spp->pgpgin, spc->pgpgin, itv));
292         pmiPutValue("mem.vmstat.pgpgin", NULL, buf);
293
294         snprintf(buf, sizeof(buf), "%f",
295                  S_VALUE(spp->pgpgout, spc->pgpgout, itv));
296         pmiPutValue("mem.vmstat.pgpgout", NULL, buf);
297
298         snprintf(buf, sizeof(buf), "%f",
299                  S_VALUE(spp->pgfault, spc->pgfault, itv));
300         pmiPutValue("mem.vmstat.pgfault", NULL, buf);
301
302         snprintf(buf, sizeof(buf), "%f",
303                  S_VALUE(spp->pgmajfault, spc->pgmajfault, itv));
304         pmiPutValue("mem.vmstat.pgmajfault", NULL, buf);
305
306         snprintf(buf, sizeof(buf), "%f",
307                  S_VALUE(spp->pgfree, spc->pgfree, itv));
308         pmiPutValue("mem.vmstat.pgfree", NULL, buf);
309
310         snprintf(buf, sizeof(buf), "%f",
311                  S_VALUE(spp->pgscan_kswapd, spc->pgscan_kswapd, itv));
312         pmiPutValue("mem.vmstat.pgscank", NULL, buf);
313
314         snprintf(buf, sizeof(buf), "%f",
315                  S_VALUE(spp->pgscan_direct, spc->pgscan_direct, itv));
316         pmiPutValue("mem.vmstat.pgscand", NULL, buf);
317
318         snprintf(buf, sizeof(buf), "%f",
319                  S_VALUE(spp->pgsteal, spc->pgsteal, itv));
320         pmiPutValue("mem.vmstat.pgsteal", NULL, buf);
321 #endif  /* HAVE_PCP */
322 }
323
324 /*
325  ***************************************************************************
326  * Display I/O and transfer rate statistics in PCP format.
327  *
328  * IN:
329  * @a           Activity structure with statistics.
330  * @curr        Index in array for current sample statistics.
331  * @itv         Interval of time in 1/100th of a second.
332  * @record_hdr  Record header for current sample.
333  ***************************************************************************
334  */
335 __print_funct_t pcp_print_io_stats(struct activity *a, int curr, unsigned long long itv,
336                                    struct record_header *record_hdr)
337 {
338 #ifdef HAVE_PCP
339         char buf[64];
340         struct stats_io
341                 *sic = (struct stats_io *) a->buf[curr],
342                 *sip = (struct stats_io *) a->buf[!curr];
343
344         snprintf(buf, sizeof(buf), "%f",
345                  sic->dk_drive < sip->dk_drive ? 0.0
346                                                : S_VALUE(sip->dk_drive, sic->dk_drive, itv));
347         pmiPutValue("disk.all.total", NULL, buf);
348
349         snprintf(buf, sizeof(buf), "%f",
350                  sic->dk_drive_rio < sip->dk_drive_rio ? 0.0
351                                                        : S_VALUE(sip->dk_drive_rio, sic->dk_drive_rio, itv));
352         pmiPutValue("disk.all.read", NULL, buf);
353
354         snprintf(buf, sizeof(buf), "%f",
355                  sic->dk_drive_wio < sip->dk_drive_wio ? 0.0
356                                                        : S_VALUE(sip->dk_drive_wio, sic->dk_drive_wio, itv));
357         pmiPutValue("disk.all.write", NULL, buf);
358
359         snprintf(buf, sizeof(buf), "%f",
360                  sic->dk_drive_dio < sip->dk_drive_dio ? 0.0
361                                                        : S_VALUE(sip->dk_drive_dio, sic->dk_drive_dio, itv));
362         pmiPutValue("disk.all.discard", NULL, buf);
363
364         snprintf(buf, sizeof(buf), "%f",
365                  sic->dk_drive_rblk < sip->dk_drive_rblk ? 0.0
366                                                          : S_VALUE(sip->dk_drive_rblk, sic->dk_drive_rblk, itv) / 2);
367         pmiPutValue("disk.all.read_bytes", NULL, buf);
368
369         snprintf(buf, sizeof(buf), "%f",
370                  sic->dk_drive_wblk < sip->dk_drive_wblk ? 0.0
371                                                          : S_VALUE(sip->dk_drive_wblk, sic->dk_drive_wblk, itv) / 2);
372         pmiPutValue("disk.all.write_bytes", NULL, buf);
373
374         snprintf(buf, sizeof(buf), "%f",
375                  sic->dk_drive_dblk < sip->dk_drive_dblk ? 0.0
376                                                          : S_VALUE(sip->dk_drive_dblk, sic->dk_drive_dblk, itv) / 2);
377         pmiPutValue("disk.all.discard_bytes", NULL, buf);
378 #endif  /* HAVE_PCP */
379 }
380
381 /*
382  ***************************************************************************
383  * Display memory statistics in PCP format.
384  *
385  * IN:
386  * @a           Activity structure with statistics.
387  * @curr        Index in array for current sample statistics.
388  * @itv         Interval of time in 1/100th of a second.
389  * @record_hdr  Record header for current sample.
390  ***************************************************************************
391  */
392 __print_funct_t pcp_print_memory_stats(struct activity *a, int curr, unsigned long long itv,
393                                        struct record_header *record_hdr)
394 {
395 #ifdef HAVE_PCP
396         char buf[64];
397         struct stats_memory
398                 *smc = (struct stats_memory *) a->buf[curr];
399         unsigned long long nousedmem;
400
401         if (DISPLAY_MEMORY(a->opt_flags)) {
402
403                 nousedmem = smc->frmkb + smc->bufkb + smc->camkb + smc->slabkb;
404                 if (nousedmem > smc->tlmkb) {
405                         nousedmem = smc->tlmkb;
406                 }
407
408                 snprintf(buf, sizeof(buf), "%llu", smc->frmkb);
409                 pmiPutValue("mem.util.free", NULL, buf);
410
411                 snprintf(buf, sizeof(buf), "%llu", smc->availablekb);
412                 pmiPutValue("mem.util.available", NULL, buf);
413
414                 snprintf(buf, sizeof(buf), "%llu", smc->tlmkb - nousedmem);
415                 pmiPutValue("mem.util.used", NULL, buf);
416
417                 snprintf(buf, sizeof(buf), "%f",
418                          smc->tlmkb ? SP_VALUE(nousedmem, smc->tlmkb, smc->tlmkb) : 0.0);
419                 pmiPutValue("mem.util.used_pct", NULL, buf);
420
421                 snprintf(buf, sizeof(buf), "%llu", smc->bufkb);
422                 pmiPutValue("mem.util.buffers", NULL, buf);
423
424                 snprintf(buf, sizeof(buf), "%llu", smc->camkb);
425                 pmiPutValue("mem.util.cached", NULL, buf);
426
427                 snprintf(buf, sizeof(buf), "%llu", smc->comkb);
428                 pmiPutValue("mem.util.commit", NULL, buf);
429
430                 snprintf(buf, sizeof(buf), "%f",
431                          (smc->tlmkb + smc->tlskb) ? SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb)
432                                                    : 0.0);
433                 pmiPutValue("mem.util.commit_pct", NULL, buf);
434
435                 snprintf(buf, sizeof(buf), "%llu", smc->activekb);
436                 pmiPutValue("mem.util.active", NULL, buf);
437
438                 snprintf(buf, sizeof(buf), "%llu", smc->inactkb);
439                 pmiPutValue("mem.util.inactive", NULL, buf);
440
441                 snprintf(buf, sizeof(buf), "%llu", smc->dirtykb);
442                 pmiPutValue("mem.util.dirty", NULL, buf);
443
444                 if (DISPLAY_MEM_ALL(a->opt_flags)) {
445
446                         snprintf(buf, sizeof(buf), "%llu", smc->anonpgkb);
447                         pmiPutValue("mem.util.anonpages", NULL, buf);
448
449                         snprintf(buf, sizeof(buf), "%llu", smc->slabkb);
450                         pmiPutValue("mem.util.slab", NULL, buf);
451
452                         snprintf(buf, sizeof(buf), "%llu", smc->kstackkb);
453                         pmiPutValue("mem.util.stack", NULL, buf);
454
455                         snprintf(buf, sizeof(buf), "%llu", smc->pgtblkb);
456                         pmiPutValue("mem.util.pageTables", NULL, buf);
457
458                         snprintf(buf, sizeof(buf), "%llu", smc->vmusedkb);
459                         pmiPutValue("mem.util.vmused", NULL, buf);
460                 }
461         }
462
463         if (DISPLAY_SWAP(a->opt_flags)) {
464
465                 snprintf(buf, sizeof(buf), "%llu", smc->frskb);
466                 pmiPutValue("mem.util.swapFree", NULL, buf);
467
468                 snprintf(buf, sizeof(buf), "%llu", smc->tlskb - smc->frskb);
469                 pmiPutValue("mem.util.swapUsed", NULL, buf);
470
471                 snprintf(buf, sizeof(buf), "%f",
472                          smc->tlskb ? SP_VALUE(smc->frskb, smc->tlskb, smc->tlskb) : 0.0);
473                 pmiPutValue("mem.util.swapUsed_pct", NULL, buf);
474
475                 snprintf(buf, sizeof(buf), "%llu", smc->caskb);
476                 pmiPutValue("mem.util.swapCached", NULL, buf);
477
478                 snprintf(buf, sizeof(buf), "%f",
479                          (smc->tlskb - smc->frskb) ? SP_VALUE(0, smc->caskb, smc->tlskb - smc->frskb)
480                                                    : 0.0);
481                 pmiPutValue("mem.util.swapCached_pct", NULL, buf);
482         }
483 #endif  /* HAVE_PCP */
484 }
485
486 /*
487  ***************************************************************************
488  * Display kernel tables statistics in PCP format.
489  *
490  * IN:
491  * @a           Activity structure with statistics.
492  * @curr        Index in array for current sample statistics.
493  * @itv         Interval of time in 1/100th of a second.
494  * @record_hdr  Record header for current sample.
495  ***************************************************************************
496  */
497 __print_funct_t pcp_print_ktables_stats(struct activity *a, int curr, unsigned long long itv,
498                                         struct record_header *record_hdr)
499 {
500 #ifdef HAVE_PCP
501         char buf[64];
502         struct stats_ktables
503                 *skc = (struct stats_ktables *) a->buf[curr];
504
505         snprintf(buf, sizeof(buf), "%llu", skc->dentry_stat);
506         pmiPutValue("vfs.dentry.count", NULL, buf);
507
508         snprintf(buf, sizeof(buf), "%llu", skc->file_used);
509         pmiPutValue("vfs.files.count", NULL, buf);
510
511         snprintf(buf, sizeof(buf), "%llu", skc->inode_used);
512         pmiPutValue("vfs.inodes.count", NULL, buf);
513
514         snprintf(buf, sizeof(buf), "%llu", skc->pty_nr);
515         pmiPutValue("kernel.all.pty", NULL, buf);
516 #endif  /* HAVE_PCP */
517 }
518
519 /*
520  ***************************************************************************
521  * Display queue and load statistics in PCP format
522  *
523  * IN:
524  * @a           Activity structure with statistics.
525  * @curr        Index in array for current sample statistics.
526  * @itv         Interval of time in 1/100th of a second.
527  * @record_hdr  Record header for current sample.
528  ***************************************************************************
529  */
530 __print_funct_t pcp_print_queue_stats(struct activity *a, int curr, unsigned long long itv,
531                                       struct record_header *record_hdr)
532 {
533 #ifdef HAVE_PCP
534         char buf[64];
535         struct stats_queue
536                 *sqc = (struct stats_queue *) a->buf[curr];
537
538         snprintf(buf, sizeof(buf), "%llu", sqc->nr_running);
539         pmiPutValue("proc.runq.runnable", NULL, buf);
540
541         snprintf(buf, sizeof(buf), "%llu", sqc->nr_threads);
542         pmiPutValue("proc.nprocs", NULL, buf);
543
544         snprintf(buf, sizeof(buf), "%llu", sqc->procs_blocked);
545         pmiPutValue("proc.blocked", NULL, buf);
546
547         snprintf(buf, sizeof(buf), "%f", (double) sqc->load_avg_1 / 100);
548         pmiPutValue("kernel.all.load", "1 min", buf);
549
550         snprintf(buf, sizeof(buf), "%f", (double) sqc->load_avg_5 / 100);
551         pmiPutValue("kernel.all.load", "5 min", buf);
552
553         snprintf(buf, sizeof(buf), "%f", (double) sqc->load_avg_15 / 100);
554         pmiPutValue("kernel.all.load", "15 min", buf);
555 #endif  /* HAVE_PCP */
556 }
557
558 /*
559  ***************************************************************************
560  * Display network interfaces statistics in PCP format.
561  *
562  * IN:
563  * @a           Activity structure with statistics.
564  * @curr        Index in array for current sample statistics.
565  * @itv         Interval of time in 1/100th of a second.
566  * @record_hdr  Record header for current sample.
567  ***************************************************************************
568  */
569 __print_funct_t pcp_print_net_dev_stats(struct activity *a, int curr, unsigned long long itv,
570                                         struct record_header *record_hdr)
571 {
572 #ifdef HAVE_PCP
573         int i, j;
574         struct stats_net_dev *sndc, *sndp, sndzero;
575         double rxkb, txkb, ifutil;
576         char buf[64];
577
578         memset(&sndzero, 0, STATS_NET_DEV_SIZE);
579
580         for (i = 0; i < a->nr[curr]; i++) {
581
582                 sndc = (struct stats_net_dev *) ((char *) a->buf[curr] + i * a->msize);
583
584                 if (a->item_list != NULL) {
585                         /* A list of devices has been entered on the command line */
586                         if (!search_list_item(a->item_list, sndc->interface))
587                                 /* Device not found */
588                                 continue;
589                 }
590
591                 j = check_net_dev_reg(a, curr, !curr, i);
592                 if (j < 0) {
593                         /* This is a newly registered interface. Previous stats are zero */
594                         sndp = &sndzero;
595                 }
596                 else {
597                         sndp = (struct stats_net_dev *) ((char *) a->buf[!curr] + j * a->msize);
598                 }
599
600                 rxkb = S_VALUE(sndp->rx_bytes, sndc->rx_bytes, itv);
601                 txkb = S_VALUE(sndp->tx_bytes, sndc->tx_bytes, itv);
602                 ifutil = compute_ifutil(sndc, rxkb, txkb);
603
604                 snprintf(buf, sizeof(buf), "%f",
605                          S_VALUE(sndp->rx_packets, sndc->rx_packets, itv));
606                 pmiPutValue("network.interface.in.packets", sndc->interface, buf);
607
608                 snprintf(buf, sizeof(buf), "%f",
609                          S_VALUE(sndp->tx_packets, sndc->tx_packets, itv));
610                 pmiPutValue("network.interface.out.packets", sndc->interface, buf);
611
612                 snprintf(buf, sizeof(buf), "%f", rxkb / 1024);
613                 pmiPutValue("network.interface.in.bytes", sndc->interface, buf);
614
615                 snprintf(buf, sizeof(buf), "%f", txkb / 1024);
616                 pmiPutValue("network.interface.out.bytes", sndc->interface, buf);
617
618                 snprintf(buf, sizeof(buf), "%f",
619                          S_VALUE(sndp->rx_compressed, sndc->rx_compressed, itv));
620                 pmiPutValue("network.interface.in.compressed", sndc->interface, buf);
621
622                 snprintf(buf, sizeof(buf), "%f",
623                          S_VALUE(sndp->tx_compressed, sndc->tx_compressed, itv));
624                 pmiPutValue("network.interface.out.compressed", sndc->interface, buf);
625
626                 snprintf(buf, sizeof(buf), "%f",
627                          S_VALUE(sndp->multicast, sndc->multicast, itv));
628                 pmiPutValue("network.interface.in.multicast", sndc->interface, buf);
629
630                 snprintf(buf, sizeof(buf), "%f", ifutil);
631                 pmiPutValue("network.interface.util", sndc->interface, buf);
632         }
633 #endif  /* HAVE_PCP */
634 }
635
636 /*
637  ***************************************************************************
638  * Display network interfaces errors statistics in PCP format.
639  *
640  * IN:
641  * @a           Activity structure with statistics.
642  * @curr        Index in array for current sample statistics.
643  * @itv         Interval of time in 1/100th of a second.
644  * @record_hdr  Record header for current sample.
645  ***************************************************************************
646  */
647 __print_funct_t pcp_print_net_edev_stats(struct activity *a, int curr, unsigned long long itv,
648                                         struct record_header *record_hdr)
649 {
650 #ifdef HAVE_PCP
651         int i, j;
652         struct stats_net_edev *snedc, *snedp, snedzero;
653         char buf[64];
654
655         memset(&snedzero, 0, STATS_NET_EDEV_SIZE);
656
657         for (i = 0; i < a->nr[curr]; i++) {
658
659                 snedc = (struct stats_net_edev *) ((char *) a->buf[curr] + i * a->msize);
660
661                 if (a->item_list != NULL) {
662                         /* A list of devices has been entered on the command line */
663                         if (!search_list_item(a->item_list, snedc->interface))
664                                 /* Device not found */
665                                 continue;
666                 }
667
668                 j = check_net_edev_reg(a, curr, !curr, i);
669                 if (j < 0) {
670                         /* This is a newly registered interface. Previous stats are zero */
671                         snedp = &snedzero;
672                 }
673                 else {
674                         snedp = (struct stats_net_edev *) ((char *) a->buf[!curr] + j * a->msize);
675                 }
676
677                 snprintf(buf, sizeof(buf), "%f",
678                          S_VALUE(snedp->rx_errors, snedc->rx_errors, itv));
679                 pmiPutValue("network.interface.in.errors", snedc->interface, buf);
680
681                 snprintf(buf, sizeof(buf), "%f",
682                          S_VALUE(snedp->tx_errors, snedc->tx_errors, itv));
683                 pmiPutValue("network.interface.out.errors", snedc->interface, buf);
684
685                 snprintf(buf, sizeof(buf), "%f",
686                          S_VALUE(snedp->collisions, snedc->collisions, itv));
687                 pmiPutValue("network.interface.out.collisions", snedc->interface, buf);
688
689                 snprintf(buf, sizeof(buf), "%f",
690                          S_VALUE(snedp->rx_dropped, snedc->rx_dropped, itv));
691                 pmiPutValue("network.interface.in.drops", snedc->interface, buf);
692
693                 snprintf(buf, sizeof(buf), "%f",
694                          S_VALUE(snedp->tx_dropped, snedc->tx_dropped, itv));
695                 pmiPutValue("network.interface.out.drops", snedc->interface, buf);
696
697                 snprintf(buf, sizeof(buf), "%f",
698                          S_VALUE(snedp->tx_carrier_errors, snedc->tx_carrier_errors, itv));
699                 pmiPutValue("network.interface.out.carrier", snedc->interface, buf);
700
701                 snprintf(buf, sizeof(buf), "%f",
702                          S_VALUE(snedp->rx_frame_errors, snedc->rx_frame_errors, itv));
703                 pmiPutValue("network.interface.in.frame", snedc->interface, buf);
704
705                 snprintf(buf, sizeof(buf), "%f",
706                          S_VALUE(snedp->rx_fifo_errors, snedc->rx_fifo_errors, itv));
707                 pmiPutValue("network.interface.in.fifo", snedc->interface, buf);
708
709                 snprintf(buf, sizeof(buf), "%f",
710                          S_VALUE(snedp->tx_fifo_errors, snedc->tx_fifo_errors, itv));
711                 pmiPutValue("network.interface.out.fifo", snedc->interface, buf);
712         }
713 #endif  /* HAVE_PCP */
714 }
715
716 /*
717  ***************************************************************************
718  * Display serial lines statistics in PCP format.
719  *
720  * IN:
721  * @a           Activity structure with statistics.
722  * @curr        Index in array for current sample statistics.
723  * @itv         Interval of time in 1/100th of a second.
724  * @record_hdr  Record header for current sample.
725  ***************************************************************************
726  */
727 __print_funct_t pcp_print_serial_stats(struct activity *a, int curr, unsigned long long itv,
728                                        struct record_header *record_hdr)
729 {
730 #ifdef HAVE_PCP
731         int i, j, j0, found;
732         char buf[64], serialno[64];
733         struct stats_serial *ssc, *ssp;
734
735         for (i = 0; i < a->nr[curr]; i++) {
736
737                 found = FALSE;
738
739                 if (a->nr[!curr] > 0) {
740                         ssc = (struct stats_serial *) ((char *) a->buf[curr] + i * a->msize);
741
742                         /* Look for corresponding serial line in previous iteration */
743                         j = i;
744
745                         if (j >= a->nr[!curr]) {
746                                 j = a->nr[!curr] - 1;
747                         }
748
749                         j0 = j;
750
751                         do {
752                                 ssp = (struct stats_serial *) ((char *) a->buf[!curr] + j * a->msize);
753                                 if (ssc->line == ssp->line) {
754                                         found = TRUE;
755                                         break;
756                                 }
757                                 if (++j >= a->nr[!curr]) {
758                                         j = 0;
759                                 }
760                         }
761                         while (j != j0);
762                 }
763
764                 if (!found)
765                         continue;
766
767                 sprintf(serialno, "serial%d", ssc->line);
768
769                 snprintf(buf, sizeof(buf), "%f",
770                          S_VALUE(ssp->rx, ssc->rx, itv));
771                 pmiPutValue("serial.in.interrupts", serialno, buf);
772
773                 snprintf(buf, sizeof(buf), "%f",
774                          S_VALUE(ssp->tx, ssc->tx, itv));
775                 pmiPutValue("serial.out.interrupts", serialno, buf);
776
777                 snprintf(buf, sizeof(buf), "%f",
778                          S_VALUE(ssp->frame, ssc->frame, itv));
779                 pmiPutValue("serial.frame", serialno, buf);
780
781                 snprintf(buf, sizeof(buf), "%f",
782                          S_VALUE(ssp->parity, ssc->parity, itv));
783                 pmiPutValue("serial.parity", serialno, buf);
784
785                 snprintf(buf, sizeof(buf), "%f",
786                          S_VALUE(ssp->brk, ssc->brk, itv));
787                 pmiPutValue("serial.breaks", serialno, buf);
788
789                 snprintf(buf, sizeof(buf), "%f",
790                          S_VALUE(ssp->overrun, ssc->overrun, itv));
791                 pmiPutValue("serial.overrun", serialno, buf);
792         }
793 #endif  /* HAVE_PCP */
794 }
795
796 /*
797  ***************************************************************************
798  * Display NFS client statistics in PCP format.
799  *
800  * IN:
801  * @a           Activity structure with statistics.
802  * @curr        Index in array for current sample statistics.
803  * @itv         Interval of time in 1/100th of a second.
804  * @record_hdr  Record header for current sample.
805  ***************************************************************************
806  */
807 __print_funct_t pcp_print_net_nfs_stats(struct activity *a, int curr, unsigned long long itv,
808                                         struct record_header *record_hdr)
809 {
810 #ifdef HAVE_PCP
811         char buf[64];
812         struct stats_net_nfs
813                 *snnc = (struct stats_net_nfs *) a->buf[curr],
814                 *snnp = (struct stats_net_nfs *) a->buf[!curr];
815
816         snprintf(buf, sizeof(buf), "%f",
817                 S_VALUE(snnp->nfs_rpccnt, snnc->nfs_rpccnt, itv));
818         pmiPutValue("network.fs.client.call", NULL, buf);
819
820         snprintf(buf, sizeof(buf), "%f",
821                 S_VALUE(snnp->nfs_rpcretrans, snnc->nfs_rpcretrans, itv));
822         pmiPutValue("network.fs.client.retrans", NULL, buf);
823
824         snprintf(buf, sizeof(buf), "%f",
825                 S_VALUE(snnp->nfs_readcnt, snnc->nfs_readcnt, itv));
826         pmiPutValue("network.fs.client.read", NULL, buf);
827
828         snprintf(buf, sizeof(buf), "%f",
829                 S_VALUE(snnp->nfs_writecnt, snnc->nfs_writecnt, itv));
830         pmiPutValue("network.fs.client.write", NULL, buf);
831
832         snprintf(buf, sizeof(buf), "%f",
833                 S_VALUE(snnp->nfs_accesscnt, snnc->nfs_accesscnt, itv));
834         pmiPutValue("network.fs.client.access", NULL, buf);
835
836         snprintf(buf, sizeof(buf), "%f",
837                 S_VALUE(snnp->nfs_getattcnt, snnc->nfs_getattcnt, itv));
838         pmiPutValue("network.fs.client.getattr", NULL, buf);
839 #endif  /* HAVE_PCP */
840 }
841
842 /*
843  ***************************************************************************
844  * Display NFS server statistics in PCP format.
845  *
846  * IN:
847  * @a           Activity structure with statistics.
848  * @curr        Index in array for current sample statistics.
849  * @itv         Interval of time in 1/100th of a second.
850  * @record_hdr  Record header for current sample.
851  ***************************************************************************
852  */
853 __print_funct_t pcp_print_net_nfsd_stats(struct activity *a, int curr, unsigned long long itv,
854                                          struct record_header *record_hdr)
855 {
856 #ifdef HAVE_PCP
857         char buf[64];
858         struct stats_net_nfsd
859                 *snndc = (struct stats_net_nfsd *) a->buf[curr],
860                 *snndp = (struct stats_net_nfsd *) a->buf[!curr];
861
862         snprintf(buf, sizeof(buf), "%f",
863                 S_VALUE(snndp->nfsd_rpccnt, snndc->nfsd_rpccnt, itv));
864         pmiPutValue("network.fs.server.call", NULL, buf);
865
866         snprintf(buf, sizeof(buf), "%f",
867                 S_VALUE(snndp->nfsd_rpcbad, snndc->nfsd_rpcbad, itv));
868         pmiPutValue("network.fs.server.badcall", NULL, buf);
869
870         snprintf(buf, sizeof(buf), "%f",
871                 S_VALUE(snndp->nfsd_netcnt, snndc->nfsd_netcnt, itv));
872         pmiPutValue("network.fs.server.packets", NULL, buf);
873
874         snprintf(buf, sizeof(buf), "%f",
875                 S_VALUE(snndp->nfsd_netudpcnt, snndc->nfsd_netudpcnt, itv));
876         pmiPutValue("network.fs.server.udp", NULL, buf);
877
878         snprintf(buf, sizeof(buf), "%f",
879                 S_VALUE(snndp->nfsd_nettcpcnt, snndc->nfsd_nettcpcnt, itv));
880         pmiPutValue("network.fs.server.tcp", NULL, buf);
881
882         snprintf(buf, sizeof(buf), "%f",
883                 S_VALUE(snndp->nfsd_rchits, snndc->nfsd_rchits, itv));
884         pmiPutValue("network.fs.server.hits", NULL, buf);
885
886         snprintf(buf, sizeof(buf), "%f",
887                 S_VALUE(snndp->nfsd_rcmisses, snndc->nfsd_rcmisses, itv));
888         pmiPutValue("network.fs.server.misses", NULL, buf);
889
890         snprintf(buf, sizeof(buf), "%f",
891                 S_VALUE(snndp->nfsd_readcnt, snndc->nfsd_readcnt, itv));
892         pmiPutValue("network.fs.server.read", NULL, buf);
893
894         snprintf(buf, sizeof(buf), "%f",
895                 S_VALUE(snndp->nfsd_writecnt, snndc->nfsd_writecnt, itv));
896         pmiPutValue("network.fs.server.write", NULL, buf);
897
898         snprintf(buf, sizeof(buf), "%f",
899                 S_VALUE(snndp->nfsd_accesscnt, snndc->nfsd_accesscnt, itv));
900         pmiPutValue("network.fs.server.access", NULL, buf);
901
902         snprintf(buf, sizeof(buf), "%f",
903                 S_VALUE(snndp->nfsd_getattcnt, snndc->nfsd_getattcnt, itv));
904         pmiPutValue("network.fs.server.getattr", NULL, buf);
905 #endif  /* HAVE_PCP */
906 }
907
908 /*
909  ***************************************************************************
910  * Display IP network statistics in PCP format.
911  *
912  * IN:
913  * @a           Activity structure with statistics.
914  * @curr        Index in array for current sample statistics.
915  * @itv         Interval of time in 1/100th of a second.
916  * @record_hdr  Record header for current sample.
917  ***************************************************************************
918  */
919 __print_funct_t pcp_print_net_ip_stats(struct activity *a, int curr, unsigned long long itv,
920                                        struct record_header *record_hdr)
921 {
922 #ifdef HAVE_PCP
923         char buf[64];
924         struct stats_net_ip
925                 *snic = (struct stats_net_ip *) a->buf[curr],
926                 *snip = (struct stats_net_ip *) a->buf[!curr];
927
928         snprintf(buf, sizeof(buf), "%f",
929                 S_VALUE(snip->InReceives, snic->InReceives, itv));
930         pmiPutValue("network.snmp.ip.ipInReceives", NULL, buf);
931
932         snprintf(buf, sizeof(buf), "%f",
933                 S_VALUE(snip->ForwDatagrams, snic->ForwDatagrams, itv));
934         pmiPutValue("network.snmp.ip.ipForwDatagrams", NULL, buf);
935
936         snprintf(buf, sizeof(buf), "%f",
937                 S_VALUE(snip->InDelivers, snic->InDelivers, itv));
938         pmiPutValue("network.snmp.ip.ipInDelivers", NULL, buf);
939
940         snprintf(buf, sizeof(buf), "%f",
941                 S_VALUE(snip->OutRequests, snic->OutRequests, itv));
942         pmiPutValue("network.snmp.ip.ipOutRequests", NULL, buf);
943
944         snprintf(buf, sizeof(buf), "%f",
945                 S_VALUE(snip->ReasmReqds, snic->ReasmReqds, itv));
946         pmiPutValue("network.snmp.ip.ipReasmReqds", NULL, buf);
947
948         snprintf(buf, sizeof(buf), "%f",
949                 S_VALUE(snip->ReasmOKs, snic->ReasmOKs, itv));
950         pmiPutValue("network.snmp.ip.ipReasmOKs", NULL, buf);
951
952         snprintf(buf, sizeof(buf), "%f",
953                 S_VALUE(snip->FragOKs, snic->FragOKs, itv));
954         pmiPutValue("network.snmp.ip.ipFragOKs", NULL, buf);
955
956         snprintf(buf, sizeof(buf), "%f",
957                 S_VALUE(snip->FragCreates, snic->FragCreates, itv));
958         pmiPutValue("network.snmp.ip.ipFragCreates", NULL, buf);
959 #endif  /* HAVE_PCP */
960 }
961
962 /*
963  ***************************************************************************
964  * Display IP network errors statistics in PCP format.
965  *
966  * IN:
967  * @a           Activity structure with statistics.
968  * @curr        Index in array for current sample statistics.
969  * @itv         Interval of time in 1/100th of a second.
970  * @record_hdr  Record header for current sample.
971  ***************************************************************************
972  */
973 __print_funct_t pcp_print_net_eip_stats(struct activity *a, int curr, unsigned long long itv,
974                                         struct record_header *record_hdr)
975 {
976 #ifdef HAVE_PCP
977         char buf[64];
978         struct stats_net_eip
979                 *sneic = (struct stats_net_eip *) a->buf[curr],
980                 *sneip = (struct stats_net_eip *) a->buf[!curr];
981
982         snprintf(buf, sizeof(buf), "%f",
983                 S_VALUE(sneip->InHdrErrors, sneic->InHdrErrors, itv));
984         pmiPutValue("network.snmp.ip.ipInHdrErrors", NULL, buf);
985
986         snprintf(buf, sizeof(buf), "%f",
987                 S_VALUE(sneip->InAddrErrors, sneic->InAddrErrors, itv));
988         pmiPutValue("network.snmp.ip.ipInAddrErrors", NULL, buf);
989
990         snprintf(buf, sizeof(buf), "%f",
991                 S_VALUE(sneip->InUnknownProtos, sneic->InUnknownProtos, itv));
992         pmiPutValue("network.snmp.ip.ipInUnknownProtos", NULL, buf);
993
994         snprintf(buf, sizeof(buf), "%f",
995                 S_VALUE(sneip->InDiscards, sneic->InDiscards, itv));
996         pmiPutValue("network.snmp.ip.ipInDiscards", NULL, buf);
997
998         snprintf(buf, sizeof(buf), "%f",
999                 S_VALUE(sneip->OutDiscards, sneic->OutDiscards, itv));
1000         pmiPutValue("network.snmp.ip.ipOutDiscards", NULL, buf);
1001
1002         snprintf(buf, sizeof(buf), "%f",
1003                 S_VALUE(sneip->OutNoRoutes, sneic->OutNoRoutes, itv));
1004         pmiPutValue("network.snmp.ip.ipOutNoRoutes", NULL, buf);
1005
1006         snprintf(buf, sizeof(buf), "%f",
1007                 S_VALUE(sneip->ReasmFails, sneic->ReasmFails, itv));
1008         pmiPutValue("network.snmp.ip.ipReasmFails", NULL, buf);
1009
1010         snprintf(buf, sizeof(buf), "%f",
1011                 S_VALUE(sneip->FragFails, sneic->FragFails, itv));
1012         pmiPutValue("network.snmp.ip.ipFragFails", NULL, buf);
1013 #endif  /* HAVE_PCP */
1014 }
1015
1016 /*
1017  ***************************************************************************
1018  * Display ICMP network statistics in PCP format.
1019  *
1020  * IN:
1021  * @a           Activity structure with statistics.
1022  * @curr        Index in array for current sample statistics.
1023  * @itv         Interval of time in 1/100th of a second.
1024  * @record_hdr  Record header for current sample.
1025  ***************************************************************************
1026  */
1027 __print_funct_t pcp_print_net_icmp_stats(struct activity *a, int curr, unsigned long long itv,
1028                                          struct record_header *record_hdr)
1029 {
1030 #ifdef HAVE_PCP
1031         char buf[64];
1032         struct stats_net_icmp
1033                 *snic = (struct stats_net_icmp *) a->buf[curr],
1034                 *snip = (struct stats_net_icmp *) a->buf[!curr];
1035
1036         snprintf(buf, sizeof(buf), "%f",
1037                 S_VALUE(snip->InMsgs, snic->InMsgs, itv));
1038         pmiPutValue("network.snmp.icmp.icmpInMsgs", NULL, buf);
1039
1040         snprintf(buf, sizeof(buf), "%f",
1041                 S_VALUE(snip->OutMsgs, snic->OutMsgs, itv));
1042         pmiPutValue("network.snmp.icmp.icmpOutMsgs", NULL, buf);
1043
1044         snprintf(buf, sizeof(buf), "%f",
1045                 S_VALUE(snip->InEchos, snic->InEchos, itv));
1046         pmiPutValue("network.snmp.icmp.icmpInEchos", NULL, buf);
1047
1048         snprintf(buf, sizeof(buf), "%f",
1049                 S_VALUE(snip->InEchoReps, snic->InEchoReps, itv));
1050         pmiPutValue("network.snmp.icmp.icmpInEchoReps", NULL, buf);
1051
1052         snprintf(buf, sizeof(buf), "%f",
1053                 S_VALUE(snip->OutEchos, snic->OutEchos, itv));
1054         pmiPutValue("network.snmp.icmp.icmpOutEchos", NULL, buf);
1055
1056         snprintf(buf, sizeof(buf), "%f",
1057                 S_VALUE(snip->OutEchoReps, snic->OutEchoReps, itv));
1058         pmiPutValue("network.snmp.icmp.icmpOutEchoReps", NULL, buf);
1059
1060         snprintf(buf, sizeof(buf), "%f",
1061                 S_VALUE(snip->InTimestamps, snic->InTimestamps, itv));
1062         pmiPutValue("network.snmp.icmp.icmpInTimestamps", NULL, buf);
1063
1064         snprintf(buf, sizeof(buf), "%f",
1065                 S_VALUE(snip->InTimestampReps, snic->InTimestampReps, itv));
1066         pmiPutValue("network.snmp.icmp.icmpInTimestampReps", NULL, buf);
1067
1068         snprintf(buf, sizeof(buf), "%f",
1069                 S_VALUE(snip->OutTimestamps, snic->OutTimestamps, itv));
1070         pmiPutValue("network.snmp.icmp.icmpOutTimestamps", NULL, buf);
1071
1072         snprintf(buf, sizeof(buf), "%f",
1073                 S_VALUE(snip->OutTimestampReps, snic->OutTimestampReps, itv));
1074         pmiPutValue("network.snmp.icmp.icmpOutTimestampReps", NULL, buf);
1075
1076         snprintf(buf, sizeof(buf), "%f",
1077                 S_VALUE(snip->InAddrMasks, snic->InAddrMasks, itv));
1078         pmiPutValue("network.snmp.icmp.icmpInAddrMasks", NULL, buf);
1079
1080         snprintf(buf, sizeof(buf), "%f",
1081                 S_VALUE(snip->InAddrMaskReps, snic->InAddrMaskReps, itv));
1082         pmiPutValue("network.snmp.icmp.icmpInAddrMaskReps", NULL, buf);
1083
1084         snprintf(buf, sizeof(buf), "%f",
1085                 S_VALUE(snip->OutAddrMasks, snic->OutAddrMasks, itv));
1086         pmiPutValue("network.snmp.icmp.icmpOutAddrMasks", NULL, buf);
1087
1088         snprintf(buf, sizeof(buf), "%f",
1089                 S_VALUE(snip->OutAddrMaskReps, snic->OutAddrMaskReps, itv));
1090         pmiPutValue("network.snmp.icmp.icmpOutAddrMaskReps", NULL, buf);
1091 #endif  /* HAVE_PCP */
1092 }
1093
1094
1095 /*
1096  ***************************************************************************
1097  * Display ICMP network errors statistics in PCP format.
1098  *
1099  * IN:
1100  * @a           Activity structure with statistics.
1101  * @curr        Index in array for current sample statistics.
1102  * @itv         Interval of time in 1/100th of a second.
1103  * @record_hdr  Record header for current sample.
1104  ***************************************************************************
1105  */
1106 __print_funct_t pcp_print_net_eicmp_stats(struct activity *a, int curr, unsigned long long itv,
1107                                           struct record_header *record_hdr)
1108 {
1109 #ifdef HAVE_PCP
1110         char buf[64];
1111         struct stats_net_eicmp
1112                 *sneic = (struct stats_net_eicmp *) a->buf[curr],
1113                 *sneip = (struct stats_net_eicmp *) a->buf[!curr];
1114
1115         snprintf(buf, sizeof(buf), "%f",
1116                 S_VALUE(sneip->InErrors, sneic->InErrors, itv));
1117         pmiPutValue("network.snmp.icmp.icmpInErrors", NULL, buf);
1118
1119         snprintf(buf, sizeof(buf), "%f",
1120                 S_VALUE(sneip->OutErrors, sneic->OutErrors, itv));
1121         pmiPutValue("network.snmp.icmp.icmpOutErrors", NULL, buf);
1122
1123         snprintf(buf, sizeof(buf), "%f",
1124                 S_VALUE(sneip->InDestUnreachs, sneic->InDestUnreachs, itv));
1125         pmiPutValue("network.snmp.icmp.icmpInDestUnreachs", NULL, buf);
1126
1127         snprintf(buf, sizeof(buf), "%f",
1128                 S_VALUE(sneip->OutDestUnreachs, sneic->OutDestUnreachs, itv));
1129         pmiPutValue("network.snmp.icmp.icmpOutDestUnreachs", NULL, buf);
1130
1131         snprintf(buf, sizeof(buf), "%f",
1132                 S_VALUE(sneip->InTimeExcds, sneic->InTimeExcds, itv));
1133         pmiPutValue("network.snmp.icmp.icmpInTimeExcds", NULL, buf);
1134
1135         snprintf(buf, sizeof(buf), "%f",
1136                 S_VALUE(sneip->OutTimeExcds, sneic->OutTimeExcds, itv));
1137         pmiPutValue("network.snmp.icmp.icmpOutTimeExcds", NULL, buf);
1138
1139         snprintf(buf, sizeof(buf), "%f",
1140                 S_VALUE(sneip->InParmProbs, sneic->InParmProbs, itv));
1141         pmiPutValue("network.snmp.icmp.icmpInParmProbs", NULL, buf);
1142
1143         snprintf(buf, sizeof(buf), "%f",
1144                 S_VALUE(sneip->OutParmProbs, sneic->OutParmProbs, itv));
1145         pmiPutValue("network.snmp.icmp.icmpOutParmProbs", NULL, buf);
1146
1147         snprintf(buf, sizeof(buf), "%f",
1148                 S_VALUE(sneip->InSrcQuenchs, sneic->InSrcQuenchs, itv));
1149         pmiPutValue("network.snmp.icmp.icmpInSrcQuenchs", NULL, buf);
1150
1151         snprintf(buf, sizeof(buf), "%f",
1152                 S_VALUE(sneip->OutSrcQuenchs, sneic->OutSrcQuenchs, itv));
1153         pmiPutValue("network.snmp.icmp.icmpOutSrcQuenchs", NULL, buf);
1154
1155         snprintf(buf, sizeof(buf), "%f",
1156                 S_VALUE(sneip->InRedirects, sneic->InRedirects, itv));
1157         pmiPutValue("network.snmp.icmp.icmpInRedirects", NULL, buf);
1158
1159         snprintf(buf, sizeof(buf), "%f",
1160                 S_VALUE(sneip->OutRedirects, sneic->OutRedirects, itv));
1161         pmiPutValue("network.snmp.icmp.icmpOutRedirects", NULL, buf);
1162 #endif  /* HAVE_PCP */
1163 }
1164
1165 /*
1166  ***************************************************************************
1167  * Display TCP network statistics in PCP format.
1168  *
1169  * IN:
1170  * @a           Activity structure with statistics.
1171  * @curr        Index in array for current sample statistics.
1172  * @itv         Interval of time in 1/100th of a second.
1173  * @record_hdr  Record header for current sample.
1174  ***************************************************************************
1175  */
1176 __print_funct_t pcp_print_net_tcp_stats(struct activity *a, int curr, unsigned long long itv,
1177                                         struct record_header *record_hdr)
1178 {
1179 #ifdef HAVE_PCP
1180         char buf[64];
1181         struct stats_net_tcp
1182                 *sntc = (struct stats_net_tcp *) a->buf[curr],
1183                 *sntp = (struct stats_net_tcp *) a->buf[!curr];
1184
1185         snprintf(buf, sizeof(buf), "%f",
1186                 S_VALUE(sntp->ActiveOpens, sntc->ActiveOpens, itv));
1187         pmiPutValue("network.snmp.tcp.tcpActiveOpens", NULL, buf);
1188
1189         snprintf(buf, sizeof(buf), "%f",
1190                 S_VALUE(sntp->PassiveOpens, sntc->PassiveOpens, itv));
1191         pmiPutValue("network.snmp.tcp.tcpPassiveOpens", NULL, buf);
1192
1193         snprintf(buf, sizeof(buf), "%f",
1194                 S_VALUE(sntp->InSegs, sntc->InSegs, itv));
1195         pmiPutValue("network.snmp.tcp.tcpInSegs", NULL, buf);
1196
1197         snprintf(buf, sizeof(buf), "%f",
1198                 S_VALUE(sntp->OutSegs, sntc->OutSegs, itv));
1199         pmiPutValue("network.snmp.tcp.tcpOutSegs", NULL, buf);
1200 #endif  /* HAVE_PCP */
1201 }
1202
1203 /*
1204  ***************************************************************************
1205  * Display TCP network errors statistics in PCP format.
1206  *
1207  * IN:
1208  * @a           Activity structure with statistics.
1209  * @curr        Index in array for current sample statistics.
1210  * @itv         Interval of time in 1/100th of a second.
1211  * @record_hdr  Record header for current sample.
1212  ***************************************************************************
1213  */
1214 __print_funct_t pcp_print_net_etcp_stats(struct activity *a, int curr, unsigned long long itv,
1215                                          struct record_header *record_hdr)
1216 {
1217 #ifdef HAVE_PCP
1218         char buf[64];
1219         struct stats_net_etcp
1220                 *snetc = (struct stats_net_etcp *) a->buf[curr],
1221                 *snetp = (struct stats_net_etcp *) a->buf[!curr];
1222
1223         snprintf(buf, sizeof(buf), "%f",
1224                 S_VALUE(snetp->AttemptFails, snetc->AttemptFails, itv));
1225         pmiPutValue("network.snmp.tcp.tcpAttemptFails", NULL, buf);
1226
1227         snprintf(buf, sizeof(buf), "%f",
1228                 S_VALUE(snetp->EstabResets, snetc->EstabResets, itv));
1229         pmiPutValue("network.snmp.tcp.tcpEstabResets", NULL, buf);
1230
1231         snprintf(buf, sizeof(buf), "%f",
1232                 S_VALUE(snetp->RetransSegs, snetc->RetransSegs, itv));
1233         pmiPutValue("network.snmp.tcp.tcpRetransSegs", NULL, buf);
1234
1235         snprintf(buf, sizeof(buf), "%f",
1236                 S_VALUE(snetp->InErrs, snetc->InErrs, itv));
1237         pmiPutValue("network.snmp.tcp.tcpInErrs", NULL, buf);
1238
1239         snprintf(buf, sizeof(buf), "%f",
1240                 S_VALUE(snetp->OutRsts, snetc->OutRsts, itv));
1241         pmiPutValue("network.snmp.tcp.tcpOutRsts", NULL, buf);
1242 #endif  /* HAVE_PCP */
1243 }
1244
1245 /*
1246  ***************************************************************************
1247  * Display UDP network statistics in PCP format.
1248  *
1249  * IN:
1250  * @a           Activity structure with statistics.
1251  * @curr        Index in array for current sample statistics.
1252  * @itv         Interval of time in 1/100th of a second.
1253  * @record_hdr  Record header for current sample.
1254  ***************************************************************************
1255  */
1256 __print_funct_t pcp_print_net_udp_stats(struct activity *a, int curr, unsigned long long itv,
1257                                         struct record_header *record_hdr)
1258 {
1259 #ifdef HAVE_PCP
1260         char buf[64];
1261         struct stats_net_udp
1262                 *snuc = (struct stats_net_udp *) a->buf[curr],
1263                 *snup = (struct stats_net_udp *) a->buf[!curr];
1264
1265         snprintf(buf, sizeof(buf), "%f",
1266                 S_VALUE(snup->InDatagrams, snuc->InDatagrams, itv));
1267         pmiPutValue("network.snmp.udp.udpInDatagrams", NULL, buf);
1268
1269         snprintf(buf, sizeof(buf), "%f",
1270                 S_VALUE(snup->OutDatagrams, snuc->OutDatagrams, itv));
1271         pmiPutValue("network.snmp.udp.udpOutDatagrams", NULL, buf);
1272
1273         snprintf(buf, sizeof(buf), "%f",
1274                 S_VALUE(snup->NoPorts, snuc->NoPorts, itv));
1275         pmiPutValue("network.snmp.udp.udpNoPorts", NULL, buf);
1276
1277         snprintf(buf, sizeof(buf), "%f",
1278                 S_VALUE(snup->InErrors, snuc->InErrors, itv));
1279         pmiPutValue("network.snmp.udp.udpInErrors", NULL, buf);
1280 #endif  /* HAVE_PCP */
1281 }