File: proc.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (704 lines) | stat: -rw-r--r-- 23,103 bytes parent folder | download | duplicates (3)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
#!@@PERL@@
# -*- perl -*-
#
# proc_ - Munin plugin to for Process information
# Copyright (C) 2009-2010 Redpill Linpro AS
#
# Author: Trygve Vea <tv@redpill-linpro.com>
# Author: Kristian Lyngstøl <kristian@redpill-linpro.com>
#
# 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.

=head1 NAME

proc - Munin plugin to monitor various aspects of named processes

=head1 APPLICABLE SYSTEMS

Processes running under Linux for a longer timespan.

=head1 CONFIGURATION

The plugin needs to be able to parse the /proc-filesystem.

The plugin is configured by supplying a pipe-delimitered list of parameters
through environment variables.
  [proc]
     env.procname proc1|proc2|proc3
     env.procargs |--run|
     env.procuser joe||mary
     env.procaspect cpu|memory|ctxt_switches|threads|processes|io


env.procname defines the processname as seen inside the paranthesis of the
second column in /proc/pid/stat. If you don't get the data you expect, you
can check if the value is what you expect here. This is what's used for the
first filter, and args/user-filters are then applied on top of this filter.

env.procargs defines a string which is matched against the command line of the
process.  It's a wildcard match, so you don't have to provide the entire
argument list if there's only one key option you care about filtering on.

env.procuser defines the user the process has to run as. If nothing is
provided, processes ran by any user are included.

env.procaspect defines which graphs to render. Per default, all graphs are
included. You don't have to set this unless you want to exclude graphs.

=head1 INTERPRETATION

Each graph uses data from the proc filesystem.

=head1 MAGIC MARKERS

 #%# family=manual
 #%# capabilities=autoconf multigraph

=head1 BUGS

The graphs will be misleading in an event where you have multiple
processes monitored, but less then all of them is restarted (or exits). This
is due to the nature of counters, and I need to track state of individual
processes to do this in a reliable way. It's on my TODO, but has a low priority
as I consider this plugin something for graphing daemons.

=head1 PATCHES-TO

The munin-project.

=head1 AUTHOR

Trygve Vea <tv@redpill-linpro.com>
Kristian Lyngstøl <kristian@varnish-software.com>

=head1 THANKS

Thanks to Kristian Lyngstøl, I stole most of the initial code in this plugin
from his varnish_-plugin, which is a really nice outline of how a
wildcardplugin should look like. I've added some weird hacks to make it output
multigraph. It's pretty ugly, but it works.

=head1 LICENSE

GPLv2

=cut

use strict;
use Munin::Plugin;

# Set to 1 to enable output when a variable is defined in a graph but
# omitted because it doesn't exist in varnishstat.
my $DEBUG = 0;

# You should set the env-var "procname" to filter processes of their name.
# This will default to "init" unless you specify anything else.
my @procname = split(/\|/, $ENV{'procname'});
my @procargs = split(/\|/, $ENV{'procargs'});
my @procuser = split(/\|/, $ENV{'procuser'});
my @procaspect = exists $ENV{'procaspect'} ? split(/\|/, $ENV{'procaspect'}) : ('cpu', 'memory', 'ctxt_switches', 'threads', 'processes', 'io');
my @proctitlec;
my @procuniq;

#my $procname = exists $ENV{'procname'} ? $ENV{'procname'} : "init";

# You can set the env-var "procargs" to filter processes of their running
# arguments.
#my $args = exists $ENV{'procargs'} ? $ENV{'procargs'} : undef;

# You can set the env-var "category" to override the default category.
my $category = exists $ENV{'category'} ? $ENV{'category'} : "Process info";

my %procstats = ();
my $self;
my $i = 0;


# Parameters that can be defined on top level of a graph. Config will print
# them as "graph_$foo $value\n"
my @graph_parameters = ('title','total','order','scale','vlabel','args');

# Parameters that can be defined on a value-to-value basis and will be
# blindly passed to config. Printed as "$fieldname.$param $value\n".
my @field_parameters = ('graph', 'min', 'max', 'draw', 'cdef', 'warning',
                        'colour', 'info', 'type', 'negative');
# Data structure that defines all possible graphs (aspects) and how they
# are to be plotted. Every top-level entry is a graph/aspect. Each top-level graph
# MUST have title set and 'values'.
#
# 'rpn' on values allows easy access to graphs consisting of multiple
# values from procstats. (Reverse polish notation). The RPN
# implementation only accepts +-*/ and procstats-values.
#
# Any value left undefined will be left up to Munin to define/ignore/yell
# about.
#
# See munin documentation or rrdgraph/rrdtool for more information.
my %ASPECTS = (
    'cpu' => {
        'title' => "CPU Usage",
        'vlabel' => '%',
        'order' => 'stime utime',
        'args' => '-l 0',
        'values' => {
            'utime' => {
                'type' => 'DERIVE',
                'min' => '0',
                'label' => 'User time',
                'draw' => 'AREASTACK'
            },
            'stime' => {
                'type' => 'DERIVE',
                'min' => '0',
                'label' => 'System time',
                'draw' => 'AREASTACK'
            }
        }
    },
    'ctxt_switches' => {
        'title' => "Context switches",
        'vlabel' => 'ctxt switches p.s.',
        'values' => {
            'voluntary_ctxt_switches' => {
                'type' => 'DERIVE',
                'min' => '0',
                'label' => 'Voluntary Context Switches'
            },
            'nonvoluntary_ctxt_switches' => {
                'type' => 'DERIVE',
                'min' => '0',
                'label' => 'Nonvoluntary Context Switches'
            }
        }
    },
    'threads' => {
        'title' => "Thread count",
        'vlabel' => 'count',
        'values' => {
            'threads' => {
                'type' => 'GAUGE',
                'label' => 'Number of threads'
            }
        }
    },
    'processes' => {
        'title' => "Process count",
        'vlabel' => 'count',
        'values' => {
            'processes' => {
                'type' => 'GAUGE',
                'label' => 'Number of processes'
            }
        }
    },
    'memory' => {
        'title' => "Memory usage",
        'vlabel' => 'bytes',
        'order' => 'VmStk VmExe VmLib VmData VmRSS VmSize',
        'args' => '-l 0',
        'values' => {
            'VmSize' => {
                'type' => 'GAUGE',
                'label' => 'Virtual Memory Size'
            },
            'VmRSS' => {
                'type' => 'GAUGE',
                'label' => 'Resident set size',
            },
            'VmData' => {
                'type' => 'GAUGE',
                'label' => 'Data size',
            },
            'VmStk' => {
                'type' => 'GAUGE',
                'label' => 'Stack size',
            },
            'VmExe' => {
                'type' => 'GAUGE',
                'label' => 'Segments size',
            },
            'VmLib' => {
                'type' => 'GAUGE',
                'label' => 'Shared library size',
            }
        }
    },
    'io' => {
        'title' => "I/O activity",
        'vlabel' => '(-) reads / (+) writes',
        'args' => '-l 0',
        'values' => {
            'rchar' => {
                'type' => 'DERIVE',
                'label' => 'bytes read',
                'min' => '0',
                'graph' => 'no'
            },
            'wchar' => {
                'type' => 'DERIVE',
                'label' => 'characters',
                'min' => '0',
#                'label' => 'bytes written',
                'negative' => 'rchar'
            },
            'syscr' => {
                'type' => 'DERIVE',
                'label' => 'read syscalls',
                'min' => '0',
                'graph' => 'no'
            },
            'syscw' => {
                'type' => 'DERIVE',
                'label' => 'syscalls',
                'min' => '0',
#                'label' => 'write syscalls',
                'negative' => 'syscr'
            },
            'read_bytes' => {
                'type' => 'DERIVE',
                'label' => 'read bytes',
                'min' => '0',
                'graph' => 'no'
            },
            'write_bytes' => {
                'type' => 'DERIVE',
                'label' => 'bytes',
                'min' => '0',
#                'label' => 'write bytes',
                'negative' => 'read_bytes'
#            },
#            'cancelled_write_bytes' => {
#                'type' => 'DERIVE',
#                'label' => 'Cancelled write bytes'
            }
        }
    }
);

# Open file and return contents.  If called in scalar context, return
# as one string.  If called in list context, return array of lines.
sub slurp {
    my $file = shift;
    open(my $fh, "<", $file) or return;
    my @content = <$fh>;
    close($fh);
    return wantarray ? @content : join("", @content);
}

# Populate %procstats with values.
sub populate_stats
{
    my $i = -1;
    foreach (@procname) {
        $i++;
        $procstats{$procuniq[$i]}{"utime"} = 0;
        $procstats{$procuniq[$i]}{"stime"} = 0;
        $procstats{$procuniq[$i]}{"threads"} = 0;
        $procstats{$procuniq[$i]}{"vsize"} = 0;
        $procstats{$procuniq[$i]}{"rss"} = 0;
        $procstats{$procuniq[$i]}{"processes"} = 0;
        $procstats{$procuniq[$i]}{"voluntary_ctxt_switches"} = 0;
        $procstats{$procuniq[$i]}{"nonvoluntary_ctxt_switches"} = 0;
        $procstats{$procuniq[$i]}{"VmSize"} = 0;
        $procstats{$procuniq[$i]}{"VmRSS"} = 0;
        $procstats{$procuniq[$i]}{"VmData"} = 0;
        $procstats{$procuniq[$i]}{"VmStk"} = 0;
        $procstats{$procuniq[$i]}{"VmExe"} = 0;
        $procstats{$procuniq[$i]}{"VmLib"} = 0;
        $procstats{$procuniq[$i]}{"rchar"} = 0;
        $procstats{$procuniq[$i]}{"wchar"} = 0;
        $procstats{$procuniq[$i]}{"syscr"} = 0;
        $procstats{$procuniq[$i]}{"syscw"} = 0;
        $procstats{$procuniq[$i]}{"read_bytes"} = 0;
        $procstats{$procuniq[$i]}{"write_bytes"} = 0;
        $procstats{$procuniq[$i]}{"cancelled_write_bytes"} = 0;
        my $procuid = getpwnam($procuser[$i]); # may return undef

    STATLINE:
        foreach my $line(`grep -Fh '($procname[$i])' /proc/[0-9]*/stat`) {
            my ($pid) = $line =~ /^(\d+)/;

            my $cmduid = (lstat("/proc/$pid"))[4];

            if ( $procargs[$i] ) {
              my $cmdline = slurp("/proc/$pid/cmdline") or next STATLINE;
              $cmdline =~ tr{\0}{ };

              next STATLINE if $procargs[$i] and $cmdline !~ /$procargs[$i]/;
            }
            next STATLINE if defined $procuid and $cmduid != $procuid;

            if ($line =~ /^\d+ \(.*\) . \-?\d+ \-?\d+ \-?\d+ \-?\d+ \-?\d+ \d+ \d+ \d+ \d+ \d+ (\d+) (\d+) \d+ \d+ \-?\d+ \-?\d+ (\d+) \-?\d+ \d+ (\d+) (\d+)/) {
                $procstats{$procuniq[$i]}{"utime"} += $1;
                $procstats{$procuniq[$i]}{"stime"} += $2;
                $procstats{$procuniq[$i]}{"threads"} += $3;
                $procstats{$procuniq[$i]}{"vsize"} += $4;
                $procstats{$procuniq[$i]}{"rss"} += $5;
                $procstats{$procuniq[$i]}{"processes"} += 1;
                foreach my $line (slurp("/proc/$pid/status")){
                    if ($line =~ /^(Vm.*):\s+(\d+) kB$/){
                        $procstats{$procuniq[$i]}{$1} += ($2*1024);
                    }
                    if ($line =~ /^(.*_ctxt_switches):\s+(\d+)$/){
                        $procstats{$procuniq[$i]}{$1} += $2;
                    }
                }
                foreach my $line (slurp("/proc/$pid/io")){
                    if ( $line =~ /^(.*):\s+(\d+)$/ ) {
                        $procstats{$procuniq[$i]}{$1} += $2;
                    }
                }
            }
        }
    }
}

# Bail-function.
sub usage
{
    if (@_) {
        print STDERR "@_" . "\n\n";
    }
    print STDERR "Known arguments: config.\n";
    exit 1;
}

# Print the value of a two-dimensional hash if it exist.
# Returns false if non-existant.
#
# Output is formatted for plugins if arg4 is blank, otherwise arg4 is used
# as the title/name of the field (ie: arg4=graph_title).
sub print_if_exist
{
    my %values = %{$_[0]};
    my $value = $_[1];
    my $field = $_[2];
    my $title = "$value.$field";
    if (defined($_[3])) {
        $title = $_[3];
    }
    if (defined($values{$value}{$field})) {
        if ( $field eq 'title'&& defined($_[4]) ) {
            print "$title $values{$value}{$field} '$proctitlec[$i]'\n";
        }
        else {
            print "$title $values{$value}{$field}\n";
        }
    } else {
        return 0;
    }
}

# Walk through the relevant aspect and print all top-level configuration
# values and value-definitions.
sub get_config
{
    my $graph = $_[0];
    my $uniqname = $_[1];

    # Need to double-check since set_aspect only checks this if there
    # is no argument
    if (!defined($ASPECTS{$graph})) {
        usage "No such aspect ( $graph )";
    }
    if ( $uniqname == -1 ) {
        print "multigraph proc_$graph\n";
        print "graph_category $category\n";
        foreach my $field (@graph_parameters) {
            print_if_exist(\%ASPECTS,$graph,$field,"graph_$field");
        }
        print "\n";

        if ( $graph eq 'cpu' ) {
            $i = 0;
            foreach (@procname) {
                print "$procuniq[$i].label $proctitlec[$i]\n";
                print "$procuniq[$i].type DERIVE\n";
                print "$procuniq[$i].info System + User CPU-time.\n";
                print "$procuniq[$i].min 0\n";
                print "$procuniq[$i].draw LINE2\n";
                $i++;
            }
        }
        if ( $graph eq 'ctxt_switches' ) {
            $i = 0;
            foreach (@procname) {
                print "$procuniq[$i].label $proctitlec[$i]\n";
                print "$procuniq[$i].type DERIVE\n";
                print "$procuniq[$i].info Voluntary + Nonvoluntary context switches.\n";
                print "$procuniq[$i].min 0\n";
                print "$procuniq[$i].draw LINE2\n";
                $i++;
            }
        }
        if ( $graph eq 'threads' ) {
            $i = 0;
            foreach (@procname) {
                print "$procuniq[$i].label $proctitlec[$i]\n";
                print "$procuniq[$i].type GAUGE\n";
                print "$procuniq[$i].info Threads.\n";
                print "$procuniq[$i].min 0\n";
                print "$procuniq[$i].draw LINE2\n";
                $i++;
            }
        }
        if ( $graph eq 'processes' ) {
            $i = 0;
            foreach (@procname) {
                print "$procuniq[$i].label $proctitlec[$i]\n";
                print "$procuniq[$i].type GAUGE\n";
                print "$procuniq[$i].info Processes.\n";
                print "$procuniq[$i].min 0\n";
                print "$procuniq[$i].draw LINE2\n";
                $i++;
            }
        }
        if ( $graph eq 'memory' ) {
            $i = 0;
            foreach (@procname) {
                print "$procuniq[$i].label $proctitlec[$i]\n";
                print "$procuniq[$i].type GAUGE\n";
                print "$procuniq[$i].info Resident memory.\n";
                print "$procuniq[$i].min 0\n";
                print "$procuniq[$i].draw LINE2\n";
                $i++;
            }
        }
        if ( $graph eq 'io' ) {
            $i = 0;
            foreach (@procname) {
                print "$procuniq[$i]_rchar.label $proctitlec[$i]\n";
                print "$procuniq[$i]_rchar.type DERIVE\n";
                print "$procuniq[$i]_rchar.info writes.\n";
                print "$procuniq[$i]_rchar.min 0\n";
                print "$procuniq[$i]_rchar.graph no\n";
#                print "$procuniq[$i]_rchar.draw LINE2\n";
                print "$procuniq[$i]_wchar.label $proctitlec[$i]\n";
                print "$procuniq[$i]_wchar.type DERIVE\n";
                print "$procuniq[$i]_wchar.info Resident memory.\n";
                print "$procuniq[$i]_wchar.min 0\n";
                print "$procuniq[$i]_wchar.draw LINE2\n";
                print "$procuniq[$i]_wchar.negative $procuniq[$i]_rchar\n";
                $i++;
            }
        }


        print "\n";

        return;
    }

    print "multigraph proc_$graph.$uniqname\n";
    my %values = %{$ASPECTS{$graph}{'values'}};

    print "graph_category $category\n";
    foreach my $field (@graph_parameters) {
        print_if_exist(\%ASPECTS,$graph,$field,"graph_$field",1);
    }
    print "\n";
    foreach my $value (sort keys %values) {
        # Need either RPN definition or a procstats value.
        if (!defined($procstats{$procuniq[$i]}{$value}) &&
            !defined($values{$value}{'rpn'})) {
                if ($DEBUG) {
                    print "ERROR: $value not part of procstats.\n"
                }
                next;
        }

        if (!print_if_exist(\%values,$value,'label')) {
            print "$value.label ".$ASPECTS{$graph}{'values'}{$value}{'label'}."\n";
        }
        foreach my $field (@field_parameters) {
            print_if_exist(\%values,$value,$field);
        }
    }
    print "\n";
}

# Set the run
sub set_run
{
    my $i = 0;
    foreach(@procname) {
        $proctitlec[$i] = "$procname[$i]";
        $procuniq[$i] = clean_fieldname("$procname[$i]");
        if (length($procargs[$i]) > 0 ) {
            $proctitlec[$i] = "$proctitlec[$i] $procargs[$i]";
            $procuniq[$i] = $procuniq[$i]."_".clean_fieldname($procargs[$i]);
        }
        if (length($procuser[$i]) > 0 ) {
            $proctitlec[$i] = "$proctitlec[$i] by $procuser[$i]";
            $procuniq[$i] = $procuniq[$i]."___".clean_fieldname($procuser[$i]);
        }
        $i++;
    }
}

# Read and verify the aspect ($self).
sub set_aspect
{
    $self = $0;
    $self =~ s/^.*proc_//;
    if (!defined($ASPECTS{$self}) && @ARGV == 0) {
        usage "No such aspect";
    }
}

# Handle arguments (config)
# Populate stats for config is necessary
sub check_args
{
    if (@ARGV && $ARGV[0] eq '') {
        shift @ARGV;
    }
    if (@ARGV == 1) {
        if ($ARGV[0] eq "config") {
            populate_stats;
            foreach(@procaspect) {
                my $asp = $_;
                get_config($asp,-1);
            $i = 0;
                foreach (@procname) {
                    get_config($asp,$procuniq[$i]);
                    $i++;
                }
            }
            exit 0;
        } elsif ($ARGV[0] eq "autoconf") {
            if (-r "/proc/self/cmdline") {
                print "yes\n";
            } else {
                print "no (failed to access 'cmdline' for process below /proc/)\n";
            }
            exit 0;
        } else {
            usage "Unknown argument";
        }
    }
}

# Braindead RPN: +,-,/,* will pop two items from @stack, and perform
# the relevant operation on the items. If the item in the array isn't one
# of the 4 basic math operations, a value from procstats is pushed on to
# the stack. IE: 'client_req','client_conn','/' will leave the value of
# "client_req/client_conn" on the stack.
#
# If only one item is left on the stack, it is printed. Otherwise, an error
# message is printed.
sub rpn
{
    my @stack;
    my $left;
    my $right;
    foreach my $item (@{$_[0]}) {
        if ($item eq "+") {
            $right = pop(@stack);
            $left = pop(@stack);
            push(@stack,$left+$right);
        } elsif ($item eq "-") {
            $right = pop(@stack);
            $left = pop(@stack);
            push(@stack,$left-$right);
        } elsif ($item eq "/") {
            $right = pop(@stack);
            $left = pop(@stack);
            push(@stack,$left/$right);
        } elsif ($item eq "*") {
            $right = pop(@stack);
            $left = pop(@stack);
            push(@stack,$left*$right);
        } else {
            push(@stack,int($procstats{$item}));
        }
    }
    if (@stack > 1)
    {
        print STDERR "RPN error: Stack has more than one item left.\n";
        print STDERR "@stack\n";
        exit 255;
    }
    print "@stack";
    print "\n";
}

################################
# Execution starts here        #
################################

need_multigraph();
set_run;
#set_aspect;
check_args;
populate_stats;

# We only get here if we're supposed to.

# Walks through the relevant values and either prints the procstat, or
# if the 'rpn' variable is set, calls rpn() to execute ... the rpn.

foreach (@procaspect) {
    my $asp = $_;
    $i = 0;
    print "multigraph proc_$asp\n";
    foreach (@procname) {
        if ( $asp eq 'cpu' ) {
            print "$procuniq[$i].value " .
                  ($procstats{$procuniq[$i]}{'utime'} +
                   $procstats{$procuniq[$i]}{'stime'})."\n";
        }
        if ( $asp eq 'ctxt_switches' ) {
            print "$procuniq[$i].value " .
                  ($procstats{$procuniq[$i]}{'voluntary_ctxt_switches'} +
                   $procstats{$procuniq[$i]}{'nonvoluntary_ctxt_switches'})."\n";
        }
        if ( $asp eq 'threads' ) {
            print "$procuniq[$i].value $procstats{$procuniq[$i]}{'threads'}\n";
        }
        if ( $asp eq 'processes' ) {
            print "$procuniq[$i].value $procstats{$procuniq[$i]}{'processes'}\n";
        }
        if ( $asp eq 'memory' ) {
            print "$procuniq[$i].value $procstats{$procuniq[$i]}{'VmRSS'}\n";
        }
        if ( $asp eq 'io' ) {
            print "$procuniq[$i]_rchar.value $procstats{$procuniq[$i]}{'rchar'}\n";
            print "$procuniq[$i]_wchar.value $procstats{$procuniq[$i]}{'wchar'}\n";
        }
        $i++;
    }
    print "\n";
    $i = 0;
    # Print the individual graph statistics
    foreach (@procname) {
        print "multigraph proc_$asp.$procuniq[$i]\n";
        foreach my $value (sort keys %{$ASPECTS{$asp}{'values'}}) {
            if (defined($ASPECTS{$asp}{'values'}{$value}{'rpn'})) {
                print "$value.value ";
                rpn($ASPECTS{$asp}{'values'}{$value}{'rpn'});
            } else {
                print "$value.value ";
                if (!defined($procstats{$procuniq[$i]}{$value})) {
                    print "0\n";
                    next;
                }
                print "$procstats{$procuniq[$i]}{$value}\n";
            }
        }
        print "\n";
        $i++;
    }
}