void pmdaInit(pmdaInterface *dispatch, pmdaIndom *indoms, int nindoms, pmdaMetric *metrics, int nmetrics)
Much of the pmdaInterface structure can be automatically initialized with pmdaDaemon(3), pmdaGetOpt(3) and pmdaDSO(3). pmdaInit completes the PMDA initialization phase with three operations. The first operation adds the domain and instance numbers to the instance and metric tables. Singular metrics (metrics without an instance domain) should have the instance domain PM_INDOM_NULL set in the indom field of the pmDesc structure (see pmLookupDesc(3)). Metrics with an instance domain should set this field to be the serial number of the instance domain in the indoms table.
The instance domain table may be made empty by setting indoms to NULL and nindoms to 0. This allows the caller to provide custom Fetch and Instance callback functions. The metric table may be made empty by setting metrics to NULL and nmetrics to 0. This allows the caller to provide custom Fetch and Descriptor callback functions.
static pmdaInstid _X[] = {
{ 0, "X1" }, { 1, "X2" }
};
static pmdaInstid _Y[] = {
{ 0, "Y1" }, { 1, "Y2" }
};
static pmdaIndom indomtab[] = {
#define X_INDOM 0
{ X_INDOM, 2, _X },
#define Y_INDOM 3
{ Y_INDOM, 2, _Y }
};
static pmdaMetric metrictab[] = {
/* A */
{ (void *)0,
{ PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
{ 0,0,0,0,0,0} }, },
/* B */
{ (void *)0,
{ PMDA_PMID(0,1), PM_TYPE_U32, X_INDOM, PM_SEM_INSTANT,
{ 0,0,0,0,0,0} }, },
/* C */
{ (void *)0,
{ PMDA_PMID(0,2), PM_TYPE_DOUBLE, Y_INDOM, PM_SEM_INSTANT,
{ 0,1,0,0,PM_TIME_SEC,0} }, }
};
The metric description table defines metric A with no instance domain, metric B with instance domain X and metric C with instance domain Y. Metric C has units of seconds, while the other metrics have no units (simple counters). pmdaInit will take these structures and assign the PMDA(3) domain number to the it_indom field of each instance domain. This identifier also replaces the indom field of all metrics which have that instance domain, so that they are correctly associated.
The second stage opens the help text file, if one was specified with the -h command line option (see pmdaGetOpt(3)) or as a helptext argument to pmdaDSO(3) or pmdaDaemon(3).
The final stage determines if the metrics can be directly mapped to the metric table using their unique identifiers. If all of the metric PMID item numbers correspond to the position in the metrics table, then direct mapping is used. This can greatly improve the efficiency of the callback functions.
pmdaInit may issue any of these messages: