PMDAINSTANCE(3)

πŸ“¦
version 7.2.2 Β· 4 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

πŸ’– PMDAINSTANCE πŸ’–

okay bestie, welcome to pmdaInstance(3) β€” it lives in the Library Functions Manual section of the PCP docs, and it's literally the function that hands you back instance descriptions for a PMDA. sit down, hydrate, let's go 🫢


✨ NAME ✨

pmdaInstance β€” return instance descriptions for a PMDA


🌸 C SYNOPSIS 🌸

#include <pcp/pmapi.h>
#include <pcp/pmda.h>

int pmdaInstance(pmInDom indom, int inst, char *name,
                 pmInResult **result, pmdaExt *pmda);

cc ... -lpcp_pmda -lpcp

πŸ¦‹ DESCRIPTION πŸ¦‹

so pmdaInstance uses the standard PMDA(3) data structures to hand you info about the instance domain indom. no cap.

The result structure is built by pmdaInstance itself, and it'll contain one or more instance names and/or identifiers, depending on what you passed in inst and name. it's giving "choose your own adventure" but for instance domains πŸ’…

Here's the vibe breakdown:

  • If inst has the value PM_IN_NULL and name is a null string, then result will contain all the instance names and identifiers in the instance domain. the whole buffet. ✨
  • If inst is PM_IN_NULL but name is the name of an instance in the instance domain indom, then result will contain the instance identifier for instance name.
⚠️ note bestie: if name contains no spaces, partial matching up to the first space in the instance name is performed β€” i.e. "1" will match instance name "1 minute". But if name contains an embedded space, then no partial matching happens and name should match one of the instance names exactly. exact match only, no vibes-based guessing.
  • If name is a null string but inst is an instance identifier in the instance domain indom, then result will contain the name for instance inst. πŸ”₯

The result structure is allocated with malloc(3) and should be released by the caller with free(3). yes you have to clean up after yourself, the function is not your mom 😭


🌈 MULTI-DIMENSIONAL INSTANCE NAMING 🌈

further to the above description of name, the set of rules describing external instance names is provided in the pmdaCacheStore(3) manual page. go read it, it's the lore.

Instance domains add another dimension (a set of values) to metrics. But sometimes that's just not enough to describe complex multi-dimensional instance domain situations. for those girlies, the approach a bunch of PMDAs use is to structure the external instance names using a delimiter ("/" or "::" are most commonly used) so you can separate out the other dimensions. When that happens, instance domain labels should be used to define names for each instance name component. This lets PMAPI(3) client tools identify and refine value fetches to specific dimensions of interest. iconic behavior, honestly πŸ‘‘

For example, some of the Linux kernel cgroup (control group) metric instance domains are multi-dimensional. The instance domain represents individual values across both control groups and CPUs, which makes it a two-dimensional instance domain. The instance names associated with this cgroup metrics indom have been structured using the "::" delimiter to separate the two dimensions. And the instance domain itself has been labeled accordingly, like this:

$ pminfo --desc --fetch --labels cgroup.cpuacct.usage_percpu
cgroup.cpuacct.usage_percpu
     Data Type: 64-bit unsigned int  InDom: 3.22 0xc00016
     Semantics: counter  Units: nanosec
     inst [0 or "/::cpu0"] value 713787
     inst [1 or "/::cpu1"] value 353969
     inst [2 or "/app::cpu0"] value 407816
     inst [3 or "/app::cpu1"] value 202747
     inst [0 or "/::cpu0"] labels {"device_type":"cpu","cgroup":"/","cpu":0}
     inst [1 or "/::cpu1"] labels {"device_type":"cpu","cgroup":"/","cpu":1}
     inst [2 or "/app::cpu0"] labels {"device_type":"cpu","cgroup":"/app","cpu":0}
     inst [3 or "/app::cpu1"] labels {"device_type":"cpu","cgroup":"/app","cpu":1}

$ pminfo --labels 3.22
InDom: 3.22 0xc00016
     labels {"device_type":"cpu"}

As shown above, the individual instances inherit the labels from the instance domain, and the PMDA also applies additional per-instance labels describing individual cgroup and CPU names. When this model has been used by the PMDA, PMAPI clients are able to restrict their queries to the cgroup metric instances β€” in the example, restricting to processor "cpu0" using the "cpu" label, perhaps, or to just the "/app" cgroup metrics using the "cgroup" label. pick your filter, live your truth πŸŽ€

Furthermore, using this labeling scheme, client tools can also correlate related instances across different instance domains. cross-domain slay.

$ pminfo --desc --fetch --labels kernel.percpu.cpu.irq.soft
kernel.percpu.cpu.irq.soft
     Data Type: 64-bit unsigned int  InDom: 60.0 0xf000000
     Semantics: counter  Units: millisec
     inst [0 or "cpu0"] value 6770
     inst [1 or "cpu1"] value 100
     inst [0 or "cpu0"] labels {"device_type":"cpu"}
     inst [1 or "cpu1"] labels {"device_type":"cpu"}

$ pminfo --labels 60.0
InDom: 60.0 0xf000000
     labels {"device_type":"cpu"}

Although these two metrics have different instance domains (60.0 and 3.22 respectively) and are sourced from different PMDAs, the "device_type" label identifies the common device to which these values relate. the way that a label can just connect two whole metrics... obsessed πŸ’œ


πŸ’€ CAVEAT πŸ’€

The PMDA must be using PMDA_INTERFACE_2 or later, as specified in the call to pmdaDSO(3) or pmdaDaemon(3). If labeling of multi-dimensional instance names is performed, the PMDA must use PMDA_INTERFACE_7 or later.

Because of optional partial matching up to the first space in the instance name, the PMDA developer should ensure that if instance names are allowed to have spaces, the names are unique up to the first space. fr fr, don't skip this one πŸ™ˆ


πŸ”₯ DIAGNOSTICS πŸ”₯

If any errors occur during the execution of pmdaInstance, the result structure is deallocated. (it cleans up after itself in that case, at least πŸ’…)

  • If the instance domain indom is not supported by the PMDA, pmdaInstance will return PM_ERR_INDOM.
  • If the inst or name does not correspond to any instances in the indom domain, pmdaInstance will return PM_ERR_INST.

πŸ‘‘ SEE ALSO πŸ‘‘

malloc(3), PMAPI(3), PMDA(3), pmdaCacheStore(3), pmdaLabel(3) and pmGetInDom(3).


and that's the whole page bestie, you ate it up ⭐ go forth and query your instance domains responsibly 🌸

Performance Co-Pilot Β· PCP Β· PMDAINSTANCE(3) πŸ’– πŸ¦‹ πŸŽ€

πŸ“¦ where this page comes from