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

DESCRIPTION

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

EXAMPLE

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

DIAGNOSTICS

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

CAVEAT

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

SEE ALSO

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