1PMFETCH(3) Library Functions Manual PMFETCH(3)
2
3
4
6 pmFetch - get performance metric values
7
9 #include <pcp/pmapi.h>
10
11 int pmFetch(int numpmid, pmID *pmidlist, pmResult **result);
12
13 cc ... -lpcp
14
16 Given a list of Performance Metric Identifiers (PMID)s, e.g. as con‐
17 structed by pmLookupName(3), via pmidlist and numpmid, fetch the values
18 for these performance metrics.
19
20 The call to pmFetch is executed in the context of a source of metrics,
21 instance profile and collection time, previously established by calls
22 to the appropriate context and profile functions, namely some of pmNew‐
23 Context(3), pmDupContext(3), pmUseContext(3), pmAddProfile(3), pmDel‐
24 Profile(3) and pmSetMode(3).
25
26 The principal result from pmFetch is returned in the argument result as
27 a tree, using the following component data structures;
28
29 typedef struct {
30 unsigned int vtype : 8; /* value type (same as pmDesc.type) */
31 unsigned int vlen : 24; /* bytes for vtype/vlen + vbuf */
32 char vbuf[1]; /* one or more values */
33 } pmValueBlock;
34
35 typedef struct {
36 int inst; /* instance identifier */
37 union {
38 pmValueBlock *pval; /* pointer to value-block */
39 int lval; /* integer value insitu */
40 } value;
41 } pmValue;
42
43 typedef struct {
44 pmID pmid; /* metric identifier */
45 int numval; /* number of values or error code */
46 int valfmt; /* value style, insitu or ptr */
47 pmValue vlist[1]; /* set of instances/values */
48 } pmValueSet;
49
50 /* Result returned by pmFetch() */
51 typedef struct {
52 struct timeval timestamp; /* time stamped by collector */
53 int numpmid; /* number of PMIDs */
54 pmValueSet *vset[1]; /* set of value sets */
55 } pmResult;
56
57 To accommodate metrics with multiple value instances, the numval field
58 indicates how many values are returned for each requested PMID. The
59 field valfmt in the pmValueSet structure indicates if the values for
60 this metric are stored insitu in the lval field, i.e. a 32-bit integer
61 quantity (either int, unsigned int, long or unsigned long) or if the
62 values are held in associated pmValueBlock structures. The pmValue‐
63 Block structure is always used for floating point values (float or dou‐
64 ble) and also accommodates arbitrary sized binary data such as `string-
65 valued' metrics and metrics with aggregated or complex data types. The
66 maximum length of a pmValueBlock buffer is PM_VAL_VLEN_MAX bytes. If
67 the pmValueBlock format is used, the vtype field indicates the data
68 type of the value. This field has the same interpretation as the type
69 field in the pmDesc structure, see pmLookupDesc(3).
70
71 Note that the insitu value may be a signed or unsigned 32 bit integer,
72 signed or unsigned 32 bit long value (on 32 bit platforms), In the spe‐
73 cial cases described below, it may also be a 32 bit floating point
74 value. If the application needs to know the type of an insitu value,
75 which is almost always the case, it is necessary to fetch the descrip‐
76 tor for the metric and interpret the type field, as described in detail
77 in pmLookupDesc(3). When the pmResult is received from a PCP1.x pmcd,
78 insitu values may also be 32 bit floating point values (of type
79 PM_TYPE_FLOAT). In all cases, it is good practice to use
80 pmLookupDesc(3) to fetch the descriptor for the metric and interpret
81 the type field therein. Note also that the PMAPI(3) will automatically
82 translate from the PCP2.0 format to the PCP1.x format when a PCP1.x
83 client requests 32 bit floating point values from a PCP2.0 pmcd, but
84 the reverse translation does not occur (because the PCP2.0 pmcd cannot
85 automatically distinguish between arbitrary 32 bit floating point val‐
86 ues and 32 bit integers).
87
88 If one value (i.e. associated with a particular instance) for a
89 requested metric is `unavailable' (at the requested time), then there
90 is no associated pmValue structure in the result. If there are no
91 available values for a metric, then numval will be zero and the associ‐
92 ated pmValue[] instance will be empty (valfmt is undefined in these
93 circumstances, however pmid will be correctly set to the PMID of the
94 metric with no values).
95
96 As an extension of this protocol, if the Performance Metrics Collection
97 System (PMCS) is able to provide a reason why no values are available
98 for a particular metric, this is encoded as a standard error code in
99 the corresponding numval. Since the error codes are all negative, val‐
100 ues for a requested metric are `unavailable' if numval is less than, or
101 equal to, zero. A performance metric's value may be `unavailable' for
102 any of the following reasons;
103
104 + The metric is not supported in this version of the software for the
105 associated Performance Metric Domain
106
107 + Collection is not currently activated in the software for the asso‐
108 ciated Performance Metric Domain
109
110 + The associated PMID is not known
111
112 + The current system configuration does not include the associated
113 hardware component and/or the associated software module, e.g. a
114 disk is not installed, or off-line, or Oracle is not installed
115
116 + The metric is one for which an instance profile is required, and
117 none was provided (there are a small number of metrics in this cate‐
118 gory, typically ones with very large, and/or very dynamic instance
119 domains, and/or expensive metric instantiation methods).
120
121 In general, we may not be able to differentiate between the various
122 cases, and if differentiation is not possible, numval will simply be
123 zero.
124
125 The argument definition and the result specifications have been con‐
126 structed to ensure that for each PMID in the requested pmidlist there
127 is exactly one pmValueSet in the result, and further the PMIDs appear
128 in exactly the same sequence in both pmidlist and result. This makes
129 the number and order of entries in result completely deterministic, and
130 greatly simplifies the application programming logic after the call to
131 pmFetch.
132
133 The result structure returned by pmFetch is dynamically allocated using
134 a combination of malloc(3) calls and specialized allocation strategies,
135 and should be released when no longer required by calling pmFreeRe‐
136 sult(3) - under no circumstances should free(3) be called directly to
137 release this space.
138
139 As common error conditions are encoded in the result data structure,
140 we'd expect only cataclysmic events to cause an error value to be
141 returned. One example would be if the metrics source context was a
142 remote host, and that host or the PMCS on that host became unreachable.
143 Otherwise the value returned by the pmFetch function will be non-nega‐
144 tive.
145
146 If the current context involves fetching metrics from a Performance
147 Metrics Collector Daemon (PMCD), then the return value may be used to
148 encode out-of-band changes in the state of the PMCD and the associated
149 Performance Metrics Daemon Agents (PMDAs), as a bit-wise ``or'' of the
150 following values:
151
152 PMCD_RESTART_AGENT An attempt has been made to restart at least one
153 failed PMDA.
154
155 PMCD_ADD_AGENT At least one PMDA has been started.
156
157 PMCD_DROP_AGENT PMCD has noticed the termination of at least one
158 PMDA.
159
160 The default is to return zero to indicate no change in state, however
161 the pmResult returned by pmFetch has the same interpretation indepen‐
162 dent of the return value being zero or greater than zero.
163
165 pmcd(1), pmAddProfile(3), PMAPI(3), pmDelProfile(3), pmDupContext(3),
166 pmExtractValue(3), pmFetchArchive(3), pmFreeResult(3), pmGetInDom(3),
167 pmLookupDesc(3), pmLookupName(3), pmNewContext(3), pmSetMode(3),
168 pmUseContext(3) and pmWhichContext(3).
169
170 Note that pmFetch is the most primitive method of fetching metric val‐
171 ues from the PMCS. More user friendly interfaces to the PMCS are
172 available or currently under development - these higher level fetch
173 methods insulate the user from the intricacies of context creation,
174 setting up instance profiles, pmResult traversal, and splitting fetches
175 into batches to minimize PDU traffic or according to other optimization
176 criteria.
177
179 As mentioned above, pmFetch returns error codes insitu in the argument
180 result. If no result is returned, e.g. due to IPC failure using the
181 current PMAPI context, or end of file on an archive log, then pmFetch
182 will return a negative error code which may be examined using
183 pmErrStr(3).
184
185 PM_ERR_EOL
186 When fetching records from an archive log, pmFetch returns this
187 error code to indicate the end of the log has been passed (or
188 the start of the log has been passed, if the direction of tra‐
189 versal is backwards in time). If the ``mode'' for the current
190 PMAPI context (see pmSetMode(3)) is PM_MODE_INTERP then the time
191 origin is advanced, even when this error code is returned. In
192 this way applications that position the time outside the range
193 defined by the records in the archive, and then commence to
194 pmFetch will eventually see valid results once the time origin
195 moves inside the temporal span of the archive.
196
198 Many of the performance metrics exported from PCP agents have the
199 semantics of counter meaning they are expected to be monotonically
200 increasing. Under some circumstances, one value of these metrics may
201 be smaller than the previously fetched value. This can happen when a
202 counter of finite precision overflows, or when the PCP agent has been
203 reset or restarted, or when the PCP agent is exporting values from some
204 underlying instrumentation that is subject to some asynchronous discon‐
205 tinuity.
206 The environment variable PCP_COUNTER_WRAP may be set to indicate that
207 all such cases of a decreasing ``counter'' should be treated as a
208 counter overflow, and hence the values are assumed to have wrapped once
209 in the interval between consecutive samples. This ``wrapping'' behav‐
210 ior was the default in earlier PCP versions, but by default has been
211 disabled in PCP version 1.3 and later.
212
213
214
215Performance Co-Pilot PCP PMFETCH(3)