pmFetch
Functionint pmFetch(int numpmid, pmID pmidlist[], pmResult **result)
Python:
pmResult* pmresult = pmFetch(c_uint pmid[])
pmFetch
, specifying a list of PMIDs (for example, as constructed by pmLookupName
) through pmidlist and numpmid. The call to pmFetch
is executed in the context of a source of metrics, instance profile, and collection time, previously established by calls to the functions described in Section 3.8.4, “PMAPI Context Services”.
pmFetch
is returned as a tree structured result, described in the Section 3.5, “Performance Metrics Values”.
pmValue
structure in the result. If there are no available values for a metric, then numval is zero and the associated pmValue
[] instance is empty; valfmt is undefined in these circumstances, but pmid is correctly set to the PMID of the metric with no values.
pmerr(1)
and pmErrStr(3)
man pages. Since all error codes are negative, values for a requested metric are unavailable if numval is less than or equal to zero.
pmValueSet
in the result, and that the PMIDs appear in exactly the same sequence in both pmidlist and result. This makes the number and order of entries in result completely deterministic, and greatly simplifies the application programming logic after the call to pmFetch
.
pmFetch
is dynamically allocated using one or more calls to malloc
and specialized allocation strategies, and should be released when no longer required by calling pmFreeResult
. Under no circumstances should free
be called directly to release this space.
malloc
failure, and so on) would cause an error value to be returned by pmFetch
. Otherwise, the value returned by the pmFetch
function is zero.
pmValue
structure) of selected performance metrics once every 10 seconds:
Example 3.15. PMAPI Metrics Services
int i, j, sts; pmID pmidlist[10]; pmResult *result; time_t now; /* set up PMAPI context, numpmid and pmidlist[] ... */ while ((sts = pmFetch(10, pmidlist, &result)) >= 0) { now = (time_t)result->timestamp.tv_sec; printf("\n@ %s", ctime(&now)); for (i = 0; i < result->numpmid; i++) { printf("PMID: %s", pmIDStr(result->vset[i]->pmid)); for (j = 0; j < result->vset[i]->numval; j++) { printf(" 0x%x", result->vset[i]->vlist[j].value.lval); putchar('\n'); } } pmFreeResult(result); sleep(10); }
Note
pmFetch
times out and returns PM_ERR_TIMEOUT
. This is most likely to occur when the PMAPI client and PMCD are communicating over a slow network connection, but may also occur when one of the hosts is extremely busy. The time out period may be modified using the PMCD_REQUEST_TIMEOUT
environment variable; see the PCPIntro(1)
man page.
pmLookupName
. The returned pmresult is passed to pmExtractValue
.