PMLOADDERIVEDCONFIG(3)
π PMLOADDERIVEDCONFIG(3) π
okay so bestie, we're in the Library Functions Manual section today, and this one is literally the glow-up your metrics have been waiting for. it's pmLoadDerivedConfig and she is iconic. π
β¨ NAME β¨
pmLoadDerivedConfig β load derived metric definitions from files πΈ
π¦ C SYNOPSIS π¦
#include <pcp/pmapi.h>
int pmLoadDerivedConfig(char *path);
cc ... -lpcp
π DESCRIPTION π
okay so picture this: derived metrics are how you take the metrics you already have and invent new ones on top of them, using cute little arithmetic expressions. and the definitions of those metrics? they can be persisted to disk and loaded back programmatically by monitor tools, which is exactly what pmLoadDerivedConfig does. no cap. β¨
The path parameter is a colon separated list of files and/or directories β yes, the syntax is the same as for the $PATH variable for sh(1) β and that's where the derived metric specifications get sourced from. π
so how does a path turn into actual files? here's the vibe check:
- if a component is a file, that file is added to the list π
- else if a component is a directory, then recursive descent is used to enumerate all files below that directory, and those get added to the list ποΈ
Each file in the resulting list is parsed in order, following the derived metrics syntax described below. no skipping, no shortcuts, periodt.
π what's inside the files π
every line in the file(s) identified by path is one of three things:
- a control line beginning with
#controlβ seepmSetDerivedControl(3)for the deets - a comment line β otherwise, with a
`#`in the first position of the line - the declaration of a derived performance metric, which is specified as:
- the name of the derived metric, using the same
`dot notation`syntax that's used for PCP performance metrics β seePCPIntro(1)andPMNS(5)π - an equals sign (
`=`) - a valid expression for a derived metric, as described in
pmRegisterDerived(3)
for every line containing a derived metric definition, pmRegisterDerived(3) gets called to register the new derived metric. that's the whole assignment bestie, and she ate. π
π«Ά giving your metric extra attributes π«Ά
once a derived metric has been declared, it may be assigned additional attributes with a line of the form:
- the name of the derived metric
- a left parenthesis, an attribute type, and a right parenthesis
- an equals sign (
`=`) - an attribute value
Currently, attribute type may be either oneline or helptext, to designate the `one line` or expanded help text to be associated with the derived metric β see pmLookupText(3). π§
The attribute value may be either:
- arbitrary text following the
`=`and ending at the end of the line, or - a string enclosed in either single quotes (
') or double quotes (")
in that second case, the attribute value may span multiple lines, and a simple escape mechanism is supported, namely: for any character `x`, `\x` is replaced by `x` β which is how you escape quotes inside a string, for example. π and there's a special case when the `\` comes at the end of the line, in which case the following newline is not included in the attribute value. sneaky but slay.
outside of attribute values, white space is ignored in the lines, and blank lines are ignored altogether. π
π the return value situation π
Because pmLoadDerivedConfig may process many files, each of which may contain many derived metric specifications, it is not possible to provide a specific error status on return. so instead: the result from pmLoadDerivedConfig will be the number of derived metrics successfully loaded from files on the given path. π
Catastrophic errors β like not being able to open one of the files on the given path β will cause an immediate return with a negative return value that can be passed to pmErrStr(3) to obtain the associated error message. so like, if it's negative, something went very wrong, bestie. π¨
When errors are encountered in the derived metric specifications, diagnostic messages are generated by pmRegisterDerived(3) and displayed via pmprintf(3). π’
Also fyi: pmUnregisterDerived(3) may be used to undefine a derived metric by name, which removes all instances of the derived metric in all contexts, irrespective of how the derived metric was defined. she's thorough like that. π
π₯ EXAMPLE π₯
# sample derived metric definitions
bad_in_pkts = network.interface.in.errors + network.interface.in.drops
# note the following would need to be on a single line ...
disk.dev.read_pct = 100 * delta(disk.dev.read) /
(delta(disk.dev.read) + delta(disk.dev.write))
disk.dev.read_pct(oneline) = percentage of disk reads
disk.dev.read_pct(helptext) = '\
Percentage of disk reads compared to the total number of
disk reads and disk writes.'
# the operand metric (some.metric.bar) may not be defined
#control novalue=1
foo = some.metric.bar * hinv.ncpu
β SEE ALSO β
PCPIntro(1), sh(1), PMAPI(3), pmLookupText(3), pmRegisterDerived(3), pmSetDerivedControl(3), pmUnregisterDerived(3), pmprintf(3) and PMNS(5).
and that's the whole page bestie, you're officially a derived-metrics girlie now πβ¨
this lil masterpiece comes to you courtesy of Performance Co-Pilot, and yeah, it's PMLOADDERIVEDCONFIG(3) β go forth and derive, ily ππ¦π
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2009 Ken McDonell. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms