summaryrefslogtreecommitdiff
path: root/man/man3/pmdamain.3
blob: 41550a9e17406885b06bc61ff4b81c2a4370309e (plain)
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
'\"macro stdmacro
.\"
.\" Copyright (c) 2013 Red Hat.
.\" Copyright (c) 2000-2004 Silicon Graphics, Inc.  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.
.\" 
.\"
.TH PMDAMAIN 3 "PCP" "Performance Co-Pilot"
.SH NAME
\f3pmdaMain\f1,
\f3pmdaGetContext\f1,
\f3pmdaSetResultCallBack\f1,
\f3pmdaSetCheckCallBack\f1,
\f3pmdaSetDoneCallBack\f1,
\f3pmdaSetEndContextCallBack\f1 \- generic PDU processing for a PMDA
.SH "C SYNOPSIS"
.ft 3
#include <pcp/pmapi.h>
.br
#include <pcp/impl.h>
.br
#include <pcp/pmda.h>
.sp
cc ... \-lpcp_pmda \-lpcp
.sp
.ad l
.hy 0
.in +8n
.ti -8n
void pmdaMain(pmdaInterface *\fIdispatch\fP);
.br
.ti -8n
void pmdaSetCheckCallBack(pmdaInterface *\fIdispatch\fP, pmdaCheckCallBack\ \fIcallback\fP);
.br
.ti -8n
void pmdaSetDoneCallBack(pmdaInterface *\fIdispatch\fP, pmdaDoneCallBack\ \fIcallback\fP);
.br
.ti -8n
void pmdaSetResultCallBack(pmdaInterface *\fIdispatch\fP, pmdaResultCallBack\ \fIcallback\fP);
.br
.ti -8n
void pmdaSetEndContextCallBack(pmdaInterface *\fIdispatch\fP, pmdaEndContextCallBack\ \fIcallback\fP);
.br
.ti -8n
int pmdaGetContext(void);
.sp
.in
.hy
.ad
.ft 1
.SH DESCRIPTION
For Performance Metric Domain Agents 
.RB ( PMDA (3)) 
using the binary PDU protocols to communicate with
.BR pmcd (1),
the routine
.B pmdaMain
provides a generic implementation of the PDU-driven main loop. 
.PP
.I dispatch
describes how to process each incoming PDU. It
is a vector of function pointers, one per request PDU type,
as used in the DSO interface for a PMDA, namely:
.PP
.nf
.ft CW
/*
 * Interface Definitions for PMDA Methods
 */
typedef struct {
    int domain;         /* set/return performance metrics domain id here */
    struct {
        unsigned int    pmda_interface: 8; /* PMDA DSO interface version */
        unsigned int    pmapi_version : 8; /* PMAPI version */
        unsigned int    flags : 16;        /* optional feature flags */
    } comm;             /* set/return communication and version info */
    int status;         /* return initialization status here */

    union {
        struct {                              /* PMDA_INTERFACE_2 or _3 */
            pmdaExt *ext;
            int (*profile)(__pmProfile *, pmdaExt *);
            int (*fetch)(int, pmID *, pmResult **, pmdaExt *);
            int (*desc)(pmID, pmDesc *, pmdaExt *);
            int (*instance)(pmInDom, int, char *, __pmInResult **, pmdaExt *);
            int (*text)(int, int, char **, pmdaExt *);
            int (*store)(pmResult *, pmdaExt *);
        } two, three;

        struct {                              /* PMDA_INTERFACE_4 or _5 */
            pmdaExt *ext;
            int     (*profile)(__pmProfile *, pmdaExt *);
            int     (*fetch)(int, pmID *, pmResult **, pmdaExt *);
            int     (*desc)(pmID, pmDesc *, pmdaExt *);
            int     (*instance)(pmInDom, int, char *, __pmInResult **, pmdaExt *);
            int     (*text)(int, int, char **, pmdaExt *);
            int     (*store)(pmResult *, pmdaExt *);
            int     (*pmid)(char *, pmID *, pmdaExt *);
            int     (*name)(pmID, char ***, pmdaExt *);
            int     (*children)(char *, int, char ***, int **, pmdaExt *);
        } four, five;

        struct {                              /* PMDA_INTERFACE_6 */
            pmdaExt *ext;
            int     (*profile)(__pmProfile *, pmdaExt *);
            int     (*fetch)(int, pmID *, pmResult **, pmdaExt *);
            int     (*desc)(pmID, pmDesc *, pmdaExt *);
            int     (*instance)(pmInDom, int, char *, __pmInResult **, pmdaExt *);
            int     (*text)(int, int, char **, pmdaExt *);
            int     (*store)(pmResult *, pmdaExt *);
            int     (*pmid)(char *, pmID *, pmdaExt *);
            int     (*name)(pmID, char ***, pmdaExt *);
            int     (*children)(char *, int, char ***, int **, pmdaExt *);
            int     (*attribute)(int, int, const char *, int, pmdaExt *);
        } six;
    } version;

} pmdaInterface;
.fi
.PP
This structure has been extended to incorporate the multiple interface versions
that have evolved over time.
For
.BR pmdaMain,
.I dispatch->domain
and
.I dispatch->status
are ignored.  The 
.I comm.pmda_interface
field is used to determine the interface used by the PMDA.  Setting this field
to
.B PMDA_INTERFACE_2
or
.B PMDA_INTERFACE_3
will force 
.B pmdaMain
to use the callbacks in the
.I version.two
or
.I version.three
structure.
A setting of
.B PMDA_INTERFACE_4
or
.B PMDA_INTERFACE_5
will force 
.B pmdaMain
to use the callbacks in the
.I version.four
or
.I version.five
structure, and similarly a
.B PMDA_INTERFACE_6
setting forces
.B pmdaMain
to use the callbacks in the
.I version.six
structure.
Any other value will result in an error and termination of
.BR pmdaMain .
.PP
Note that the use of
.B dispatch
as the interface between the
.BR pmcd (1)
and the methods of the PMDA allows each PMDA to be implemented as
though it were a DSO, with
.B pmdaMain
providing a convenient wrapper that may be used to convert from the
DSO interface to the binary PDU (daemon PMDA) interface.
.PP
.B pmdaMain
executes as a continuous loop, returning only when an end of file
is encountered on the PDU input file descriptor.
.SH CALLBACKS
In addition to the individual PDU processing callbacks \-
.BR pmdaProfile (3),
.BR pmdaFetch (3),
.BR pmdaDesc (3),
.BR pmdaInstance (3),
.BR pmdaText (3),
.BR pmdaStore (3),
.BR pmdaPMID (3),
.BR pmdaName (3),
.BR pmdaChildren (3),
and
.BR pmdaAttribute (3)
there are other callbacks that can affect or inform all PDU
processing within a PMDA, namely
.IR check ,
.I done
and
.IR end .
These callbacks should be set with 
.BR pmdaSetCheckCallBack ,
.B pmdaSetDoneCallBack
and
.BR pmdaSetEndContextCallBack .
.PP
If not null, 
.I check 
is called after each PDU is received (but before it was processed), and 
.I done
is called after each PDU is sent.  
If
.I check
returns a value less than zero (typically PM_ERR_AGAIN),
the PDU processing is skipped and in most cases the
function value is returned as an error PDU to
.BR pmcd (1)
\- this may be used for
PMDAs that require some sort of deferred connection or reconnect
protocols for the underlying sources of performance metrics, e.g. a DBMS.
The error indication from
.I check
is not passed back to
.BR pmcd (1)
in the cases where no acknowledgment is expected, e.g. for a PDU_PROFILE.
.PP
The
.I end
callback allows a PMDA to keep track of state for individual clients that
are requesting it to perform actions (PDU processing).
Using
.B pmdaGetContext
a PMDA can determine, at any point, an integer identifier that uniquely
identifies the client tools at the remote end of PMCD (for local context
modes, this identifier is always zero).
This becomes very important for handling event metrics, where each
event must be propogated once only to each interested client.
It also underlies the mechanism whereby connection information is passed
to the PMDA, such as the the credentials (user and group identifiers) for
the client tool.
.PP
One final callback mechanism is provided for handling the
.B pmResult
built for a PDU_RESULT in response to a PDU_FETCH request.
By default,
.B pmdaMain
will free the
.B pmResult
once the result has been sent to the
.BR pmcd (1).
For some PMDAs this is inappropriate, e.g. the
.B pmResult
is statically allocated, or contains a hybrid of pinned PDU buffer
information and dynamically allocated information.
.B pmdaSetResultCallback
may be used to define an alternative
.B callback
from
.BR pmdaMain .
.SH DIAGNOSTICS
These messages may be appended to the PMDA's log file:
.TP 25
.BI "PMDA interface version " interface " not supported"
The
.I interface
version is not supported by 
.BR pmdaMain .
.TP
.B Unrecognized pdu type
The PMDA received a PDU from 
.B pmcd
that it does not recognize. This may indicate that the
.B pmcd
process is using a more advanced interface than
.BR pmdaMain .
.PP
If the 
.BR PMAPI (3)
debug control variable
.RB ( pmdebug )
has the DBG_TRACE_LIBPMDA flag set then each PDU that is received is reported
in the PMDA's log file.
.SH SEE ALSO
.BR pmcd (1),
.BR PMAPI (3),
.BR PMDA (3),
.BR pmdaProfile (3),
.BR pmdaFetch (3),
.BR pmdaDesc (3),
.BR pmdaInstance (3),
.BR pmdaText (3),
.BR pmdaStore (3),
.BR pmdaPMID (3),
.BR pmdaName (3),
.BR pmdaChildren (3),
and
.BR pmdaAttribute (3).