1PMDAFETCH(3)               Library Functions Manual               PMDAFETCH(3)
2
3
4

NAME

6       pmdaFetch,  pmdaSetFetchCallBack  -  fill a pmResult structure with the
7       requested metric values
8

C SYNOPSIS

10       #include <pcp/pmapi.h>
11       #include <pcp/pmda.h>
12
13       int pmdaFetch(int numpmid, pmID *pmidlist, pmResult **resp,
14               pmdaExt *pmda);
15       void pmdaSetFetchCallBack(pmdaInterface *dispatch,
16               pmdaFetchCallBack callback);
17
18       cc ... -lpcp_pmda -lpcp
19

DESCRIPTION

21       pmdaFetch is a generic callback used by a PMDA(3) to  process  a  fetch
22       request  from  pmcd(1).  The request from pmcd is initiated by a client
23       calling pmFetch(3).
24
25       This is one of the few generic callbacks in libpcp_pmda  (see  PMDA(3))
26       that is incomplete, requiring a further pmdaFetchCallBack method of its
27       own.  The additional callback should be registered using  pmdaSetFetch‐
28       CallBack and the pmdaFetchCallBack method has the following prototype:
29       int func(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *avp)
30
31       pmdaFetch  will allocate and resize the resp result structure, to store
32       values for the numpmid metrics listed in pmidlist.
33
34       For each instance listed in the profile (see  pmdaProfile(3))  of  each
35       metric  listed  in  pmidlist, the pmdaFetchCallBack method is called to
36       fill the pmAtomValue structure identified by avp with  a  value  for  a
37       specific metric-instance pair identified by the metric descriptor mdesc
38       and the instance inst.  This value is then  copied  into  the  pmResult
39       structure.
40
41       The  pmdaFetchCallBack  method should return a value less than zero for
42       an error, and the most likely cases would be PM_ERR_PMID if the  metric
43       identified  by  mdesc is not known to the method, or PM_ERR_INST if the
44       method believes the instance inst is not known for the  metric  identi‐
45       fied by mdesc.
46
47       The success error codes depend on the version of PMDA_INTERFACE the PM‐
48       DA is using.
49
50       If the PMDA is using PMDA_INTERFACE_2 then on  success  the  pmdaFetch‐
51       CallBack method should return 0.
52
53       If  the PMDA is using PMDA_INTERFACE_3 or PMDA_INTERFACE_4 then on suc‐
54       cess the pmdaFetchCallBack method should return 1 if  a  value  is  re‐
55       turned via avp, else 0 if no values are currently available for the re‐
56       quested metric-instance pair although mdesc and inst both seem  reason‐
57       able.
58
59       If  the  PMDA  is  using  PMDA_INTERFACE_5 or later then on success the
60       pmdaFetchCallBack method should return  PMDA_FETCH_STATIC  (1)  if  the
61       value  returned  via  avp  can be ignored by pmdaFetch once it has been
62       copied into the pmResult structure, else PMDA_FETCH_DYNAMIC (2) if  the
63       value  returned  via  avp  uses  the  either the vp or cp fields of the
64       pmAtomValue and the associated value (buffer) was allocated  using  one
65       of  malloc(3),  calloc(3),  realloc(3),  strdup  (3) etc. and pmdaFetch
66       should release the memory by calling free(3) once a new buffer has been
67       allocated and the value copied, else PMDA_FETCH_NOVALUES (0) if no val‐
68       ues are currently available for the requested metric-instance pair  al‐
69       though mdesc and inst both seem reasonable.
70
71       If  the  pmdaFetchCallBack  method returns a value for an instance of a
72       metric of type PM_TYPE_STRING or PM_TYPE_AGGREGATE some special care is
73       needed  –  the method should either use a static buffer, set avp->cp or
74       avp->vp to the address of the buffer and return  PMDA_FETCH_STATIC,  or
75       use a dynamically allocated buffer, keep a static reference to the buf‐
76       fer's address, return PMDA_FETCH_STATIC and free (3) or realloc (3)  or
77       reuse  the buffer the next time the pmdaFetchCallBack method is called,
78       else use a dynamically allocated buffer and return PMDA_FETCH_DYNAMIC.
79

EXAMPLE

81       The following code fragments are for a hypothetical PMDA has with  met‐
82       rics  (A, B, C and D) and an instance domain (X) with two instances (X1
83       and X2).  The instance domain and metrics description tables  (see  pm‐
84       daInit(3)) could be defined as:
85
86            static pmdaInstid _X[] = {
87                { 0, "X1" }, { 1, "X2" }
88            };
89            static pmdaIndom indomtab[] = {
90            #define X_INDOM 0
91                { 0, 2, _X },
92            };
93            static pmdaMetric metrictab[] = {
94            /* A */
95                { (void *)0,
96                  { PMDA_PMID(0,0), PM_TYPE_32, PM_INDOM_NULL,
97                    PM_SEM_INSTANT, {0,0,0,0,0,0} }, },
98            /* B */
99                { (void *)0,
100                  { PMDA_PMID(0,1), PM_TYPE_DOUBLE, X_INDOM,
101                    PM_SEM_INSTANT, {0,1,0,0,PM_TIME_SEC,0} }, },
102            /* C */
103                { (void *)0,
104                  { PMDA_PMID(0,2), PM_TYPE_STRING, PM_INDOM_NULL,
105                    PM_SEM_INSTANT, {0,0,0,0,0,0} }, },
106            /* D */
107                { (void *)0,
108                  { PMDA_PMID(0,3), PM_TYPE_STRING, PM_INDOM_NULL,
109                    PM_SEM_INSTANT, {0,0,0,0,0,0} }, },
110            };
111
112       A pmdaFetchCallBack method to be called from pmdaFetch could be defined
113       as:
114
115            int
116            myFetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *avp)
117            {
118              static char sbuf[20]; // reuse this buffer
119              char        *dbuf;    // malloc'd
120              switch (pmID_item(mdesc->m_desc.pmid)) {
121                case 0:
122                  /* assign some value for metric A */;
123                  avp->l = ...
124                  break;
125                case 1:
126                  switch (inst) {
127                      case 0:
128                       /* assign a value for metric B, instance X1 */;
129                          avp->d = ...
130                          break;
131                      case 1:
132                       /* assign a value for metric B, instance X2 */;
133                          avp->d = ...
134                          break;
135                      default:
136                          return PM_ERR_INST;
137                  }
138                case 2:
139                  /* place value for metric C in dbuf[] */
140                  memcpy(dbuf, ...);
141                  avp->cp = dbuf;
142                  break;
143                case 3:
144                  avp->cp = (char *)malloc(somesize);
145                  /* place value in avp->cp */
146                  pmsprintf(avp->cp, somesize, ...);
147                  return PMDA_FETCH_DYNAMIC;
148                default:
149                  return PM_ERR_PMID;
150              }
151              return PMDA_FETCH_STATIC;
152            }
153

DIAGNOSTICS

155       The following error messages indicate that there is discrepancy between
156       the  namespace,  pmdaMetric and pmdaIndom tables passed to pmdaInit(3),
157       and the registered fetch callback:
158
159       pmdaFetch: Requested metric metric is not defined
160                      A requested metric metric is not listed in the  pmdaMet‐
161                      ric  table.   The namespace for this PMDA(3) may contain
162                      additional metrics.
163
164       pmdaFetch: PMID pmid not handled by fetch callback
165                      The pmdaFetchCallBack method has  returned  PM_ERR_PMID.
166                      This  indicates that a metric may be listed in the pmda‐
167                      Metric table, but  is  not  supported  by  the  callback
168                      method.
169
170       pmdaFetch: Instance inst of PMID pmid not handled by fetch callback
171                      The  pmdaFetchCallBack  method has returned PM_ERR_INST.
172                      This indicates that an instance of metric is  listed  in
173                      the  pmdaIndom  table, but is not supported by the call‐
174                      back method.
175
176       pmdaFetch: Fetch callback error:
177                      The pmdaFetchCallBack method  returned  a  result  other
178                      than    PMDA_FETCH_NOVALUES,    PMDA_FETCH_STATIC,   PM‐
179                      DA_FETCH_DYNAMIC, PM_ERR_PMID or PM_ERR_INST.
180
181       pmdaFetch: Descriptor type (type) for metric pmid is bad
182                      The data type type specified for the metric pmid in  the
183                      pmdaMetric table is illegal.
184
185       pmdaFetch  will return -errno if an error occurred while allocating the
186       pmResult structure or copying the value from the pmAtomValue.
187

CAVEAT

189       The PMDA must be using PMDA_INTERFACE_2 or later, as specified  in  the
190       call to pmdaDSO(3) or pmdaDaemon(3).
191

SEE ALSO

193       pmcd(1),  PMAPI(3), PMDA(3), pmdaDaemon(3), pmdaDSO(3), pmdaInit(3) and
194       pmFetch(3).
195
196
197
198Performance Co-Pilot                  PCP                         PMDAFETCH(3)
Impressum