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 a number of reasons; the following list is illustrative but not exhaus‐
103 tive: of the software for the associated Performance Metric Domain
104
105 + Collection is not currently activated in the software for the
106 associated Performance Metric Domain
107
108 + The associated PMID is not known
109
110 + The current system configuration does not include the associated
111 hardware component and/or the associated software module, e.g. a
112 disk is not installed, or off-line, or Oracle is not installed
113
114 + The metric is one for which an instance profile is required, and
115 none was provided (there are a small number of metrics in this
116 category, typically ones with very large, and/or very dynamic
117 instance domains, and/or expensive metric instantiation meth‐
118 ods).
119
120 + If the current context involves fetching metrics from an archive
121 log, values may be unavailable in the region around a <mark>
122 record (see pmlogextract(1)) that indicate a temporal disconti‐
123 nuity in the time-series of metric values.
124
125 In general, we may not be able to differentiate between the various
126 cases, and if differentiation is not possible, numval will simply be
127 zero.
128
129 The argument definition and the result specifications have been con‐
130 structed to ensure that for each PMID in the requested pmidlist there
131 is exactly one pmValueSet in the result, and further the PMIDs appear
132 in exactly the same sequence in both pmidlist and result. This makes
133 the number and order of entries in result completely deterministic, and
134 greatly simplifies the application programming logic after the call to
135 pmFetch.
136
137 The result structure returned by pmFetch is dynamically allocated using
138 a combination of malloc(3) calls and specialized allocation strategies,
139 and should be released when no longer required by calling pmFreeRe‐
140 sult(3) - under no circumstances should free(3) be called directly to
141 release this space.
142
143 As common error conditions are encoded in the result data structure,
144 we'd expect only cataclysmic events to cause an error value to be
145 returned. One example would be if the metrics source context was a
146 remote host, and that host or the PMCS on that host became unreachable.
147 Otherwise the value returned by the pmFetch function will be non-nega‐
148 tive.
149
150 If the current context involves fetching metrics from a Performance
151 Metrics Collector Daemon (PMCD), then the return value may be used to
152 encode out-of-band changes in the state of the PMCD and the associated
153 Performance Metrics Daemon Agents (PMDAs), as a bit-wise ``or'' of the
154 following values:
155
156 PMCD_RESTART_AGENT An attempt has been made to restart at least one
157 failed PMDA.
158
159 PMCD_ADD_AGENT At least one PMDA has been started.
160
161 PMCD_DROP_AGENT PMCD has noticed the termination of at least one
162 PMDA.
163
164 PMCD_AGENT_CHANGE A convenience macro for any of the three PMDA
165 changes.
166
167 PMCD_LABEL_CHANGE PMCD has been informed of changes to global (con‐
168 text) labels, or new metrics have appeared which
169 have associated labels.
170
171 PMCD_NAMES_CHANGE PMCD has been informed that the namespace has been
172 modified, such that new metrics have appeared or
173 existing metrics have been removed.
174
175 The default is to return zero to indicate no change in state, however
176 the pmResult returned by pmFetch has the same interpretation indepen‐
177 dent of the return value being zero or greater than zero.
178
180 pmcd(1), pmAddProfile(3), PMAPI(3), pmDelProfile(3), pmDupContext(3),
181 pmExtractValue(3), pmFetchArchive(3), pmFreeResult(3), pmGetInDom(3),
182 pmLookupDesc(3), pmLookupLabels(3), pmLookupName(3), pmNewContext(3),
183 pmSetMode(3), pmUseContext(3) and pmWhichContext(3).
184
185 Note that pmFetch is the most primitive method of fetching metric val‐
186 ues from the PMCS. See the pmFetchGroup(3) API for a higher level
187 method that insulates the user from the intricacies of looking up met‐
188 ric names and metadata, setting up instance profiles, pmResult traver‐
189 sal, conversions, and scaling.
190
192 As mentioned above, pmFetch returns error codes insitu in the argument
193 result. If no result is returned, e.g. due to IPC failure using the
194 current PMAPI context, or end of file on an archive log, then pmFetch
195 will return a negative error code which may be examined using
196 pmErrStr(3).
197
198 PM_ERR_EOL
199 When fetching records from an archive log, pmFetch returns this
200 error code to indicate the end of the log has been passed (or
201 the start of the log has been passed, if the direction of tra‐
202 versal is backwards in time). If the ``mode'' for the current
203 PMAPI context (see pmSetMode(3)) is PM_MODE_INTERP then the time
204 origin is advanced, even when this error code is returned. In
205 this way applications that position the time outside the range
206 defined by the records in the archive, and then commence to
207 pmFetch will eventually see valid results once the time origin
208 moves inside the temporal span of the archive.
209
211 Many of the performance metrics exported from PCP agents have the
212 semantics of counter meaning they are expected to be monotonically
213 increasing. Under some circumstances, one value of these metrics may
214 be smaller than the previously fetched value. This can happen when a
215 counter of finite precision overflows, or when the PCP agent has been
216 reset or restarted, or when the PCP agent is exporting values from some
217 underlying instrumentation that is subject to some asynchronous discon‐
218 tinuity.
219 The environment variable PCP_COUNTER_WRAP may be set to indicate that
220 all such cases of a decreasing ``counter'' should be treated as a
221 counter overflow, and hence the values are assumed to have wrapped once
222 in the interval between consecutive samples. This ``wrapping'' behav‐
223 ior was the default in earlier PCP versions, but by default has been
224 disabled in PCP version 1.3 and later.
225
226
227
228Performance Co-Pilot PCP PMFETCH(3)