On 04/05/16 05:18, Hanafi, Mahmoud (ARC-TN)[Computer Sciences
Corporation] wrote:
How to program pmda with more than 1 level of inst like this.
lustre.jobstats.ost.open
instA
jobid1
jobid2
instB
jobid1
jobid2
Mahmoud,
This question arises from time to time, so let me respond as fully as
I'm able, in the hope that some combination of mail indexer and
documentation updater(s) will snarf the text and save it in a place
where others can find it.
Multi-dimensional Instance Domains
The underlying PCP data model supports only linear instance domains, so
for each instance there is a matching unique integer (internal) instance
identifier selected by the PMDA implementor. These internal instance
identifiers are in the range 0 to 2^31-1 (probably safest to avoid
negative values).
This scheme works well for sets of metrics where the members of the set
naturally occur in a list, a one-dimensional array or a set.
For sets of metrics with higher-order natural indexing, e.g. tables or
arrays or meshes or grids, it is necessary to map the multiple indexes
onto a single set of integers.
For example the metric "my.counter" naturally occurs in the following table:
Thing ...
foo (0) bar (2) oops (3) ...
Optype
add (0) y y y
fetch (1) y y y
update (2) y y y
delete (3) y y y
Optype is one of 4 fixed values, but Thing may be dynamic and depend on
what's running or installed.
First it will be necessary to decide how to construct a unique external
name for the each instance. The simplest approach will usually be string
concatenation of the component index names with some separator, e.g. for
the example above, "add:foo" or "foo/update" ... the order and separator
is a matter of choice, but avoid any embedded spaces in the resulting
string, because the external name must be unique up to the first space
(if any) ... see pmLookupInDom(3).
Then there are 3 approaches that can be used to generate the internal
instance identifier from the naturally occurring indices for the
multi-dimensional data.
1. Algorithmic Mapping
If the maximum value of N-1 of the N indexes is known, then the N index
values can be mapped to 1-dimensional index, e.g. in the example above
there are 4 Optypes, but a variable number of Things, so
index = (Optype)*4 + Thing
will work.
2. Mapping via the pmdaCache services
The libpcp_pmda library contains a number of instance domain cache
services, see pmdaCache(3).
These may be used to map the external names of the multi-dimensional
indices onto a unique set of internal instance identifiers.
First construct the external instance name, e.g. "add:foo", then call
pmdaCacheStore(3) ... this will return a unique internal instance
identifier. Other members of the pmdaCache family of routines allow the
cache to be persisted to the filesystem so the mapping persists across
multiple invocations of the PMDA (a good thing) and searching of the
cache based on either the internal or the external instance identifier.
3. Move one dimension into the PMNS
This is less obvious, but sometimes a natural fit, especially for 2
dimensional data.
In the example above, instead of my.counter, the PMDA would support
my.counter.add, my.counter.fetch, my.counter.update and my.counter.delete.
Then the instance mapping is reduced to a linear mapping of the
remaining dimension, i.e. "Thing" in the example above.
Hope this helps.
|