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
|
#
# Copyright (c) 2012 Red Hat.
# Copyright (c) 2008 Aconex. All Rights Reserved.
#
# 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.
#
use strict;
use warnings;
use PCP::PMDA;
use vars qw( $pmda $id );
my $probe_indom = 0;
my $probe_script = pmda_config('PCP_PMDAS_DIR') . '/systemtap/probes.stp';
my $probe_command = "/usr/bin/stap -m pmdasystemtap $probe_script";
my @probe_instances = ( 0 => 'sync', 1 => 'readdir' );
my ( $sync_count, $sync_pid, $sync_cmd ) = ( 0, 0, "(none)" );
my ( $readdir_count, $readdir_pid, $readdir_cmd ) = ( 0, 0, "(none)" );
sub systemtap_input_callback
{
( $id, $_ ) = @_;
# $pmda->log($_);
if (/^readdir: \((\d+)\) (.*)$/) {
( $readdir_pid, $readdir_cmd ) = ( $1, $2 );
$readdir_count++;
}
elsif (/^sync: \((\d+)\) (.*)$/) {
( $sync_pid, $sync_cmd ) = ( $1, $2 );
$sync_count++;
}
}
sub systemtap_fetch_callback
{
my ($cluster, $item, $inst) = @_;
if ($inst < 0 || $inst > 1) { return (PM_ERR_INST, 0); }
if ($cluster == 0) {
if ($item == 0) {
if ($inst == 0) { return ($sync_count, 1); }
else { return ($readdir_count, 1); }
}
elsif ($item == 1) {
if ($inst == 0) { return ($sync_pid, 1); }
else { return ($readdir_pid, 1); }
}
elsif ($item == 2) {
if ($inst == 0) { return ($sync_cmd, 1); }
else { return ($readdir_cmd, 1); }
}
}
return (PM_ERR_PMID, 0);
}
$pmda = PCP::PMDA->new('systemtap', 88);
$pmda->add_metric(pmda_pmid(0,0), PM_TYPE_U32, $probe_indom,
PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE),
'systemtap.probes.count',
'Number of times the probe has been observed', '');
$pmda->add_metric(pmda_pmid(0,1), PM_TYPE_32, $probe_indom,
PM_SEM_INSTANT, pmda_units(0,0,0,0,0,0),
'systemtap.probes.pid',
'The PID of the last process to pass the probe point', '');
$pmda->add_metric(pmda_pmid(0,2), PM_TYPE_STRING, $probe_indom,
PM_SEM_INSTANT, pmda_units(0,0,0,0,0,0),
'systemtap.probes.cmd',
'The name of the last process to pass the probe point', '');
$pmda->add_indom($probe_indom, \@probe_instances,
'Instance domain exporting each SystemTap probe', '');
$pmda->set_fetch_callback(\&systemtap_fetch_callback);
$pmda->add_pipe($probe_command, \&systemtap_input_callback, 0);
$pmda->set_user('pcp');
$pmda->run;
=pod
=head1 NAME
pmdasystemtap - Systemtap performance metrics domain agent (PMDA)
=head1 DESCRIPTION
B<pmdasystemtap> is a Performance Metrics Domain Agent (PMDA) which exports
metric values from the Linux Systemtap dynamic tracing toolkit.
This implementation uses the stap(1) tool, which is a front-end to
the Systemtap toolkit.
=head1 INSTALLATION
In order to access performance data exported by Systemtap from
with PCP, it is necessary to perform two configuration steps:
=over
=item 1.
Configure Systemtap probes, and verify them with stap(1).
These should be produced in a format that is easily parsed,
and then stored in the $PCP_PMDAS_DIR/systemtap/probes.stp
file.
=item 2.
Configure B<pmdasystemtap> to extract the values from the text
produced by stap. Two example probes are implemented in the
default systemtap PMDA script - readdir and sync traces (see
$PCP_PMDAS_DIR/systemtap/pmdasystemtap.pl for details).
=back
# cd $PCP_PMDAS_DIR/systemtap
# [ edit probes.stp, test /usr/bin/stap probes.stp ]
# [ edit pmdasystemtap.pl ]
Once this is setup, you can access the names and values for the
systemtap performance metrics by doing the following as root:
# cd $PCP_PMDAS_DIR/systemtap
# ./Install
If you want to undo the installation, do the following as root:
# cd $PCP_PMDAS_DIR/systemtap
# ./Remove
B<pmdasystemtap> is launched by pmcd(1) and should never be executed
directly. The Install and Remove scripts notify pmcd(1) when
the agent is installed or removed.
=head1 FILES
=over
=item $PCP_PMDAS_DIR/systemtap/probes.stp
probe configuration file for stap(1), run by B<pmdasystemtap>
=item $PCP_PMDAS_DIR/systemtap/Install
installation script for the B<pmdasystemtap> agent
=item $PCP_PMDAS_DIR/systemtap/Remove
undo installation script for the B<pmdasystemtap> agent
=item $PCP_LOG_DIR/pmcd/systemtap.log
default log file for error messages from B<pmdasystemtap>
=back
=head1 SEE ALSO
pmcd(1) and stap(1).
|