PMMERGELABELS(3)
π pmMergeLabels β bestie edition π
okay so this is the manual for pmMergeLabels and pmMergeLabelSets, which live in the Library Functions Manual (section 3, if u were wondering π). they merge sets of performance metric labels. that's the whole vibe. let's get into it β¨
πΈ NAME πΈ
pmMergeLabels, pmMergeLabelSets β merge sets of performance metric labels π·οΈβ¨
π C SYNOPSIS π
#include <pcp/pmapi.h>
int pmMergeLabels(char **sets, int nsets, char *buffer, int length);
int pmMergeLabelSets(pmLabelSet **sets, int nsets, char *buffer,
int length, int (*filter)
(const pmLabel *, const char *, void *),
void *arg);
cc ... -lpcp
π PYTHON SYNOPSIS π
from pcp import pmapi
buffer = pmapi.pmContext().pmMergeLabels(sets)
buffer = pmapi.pmContext().pmMergeLabelSets(sets, filter)
β¨ DESCRIPTION β¨
so pmMergeLabels takes multiple label sets (there are nsets of them, bestie) and merges them all into one single result buffer that's length bytes long. both the input sets AND the result buffer are name:value pairs in the "JSONB" format that's described over on pmLookupLabels(3). π
the pmMergeLabelSets interface does the exact same thing, but it lets u merge indexed sets of labels. the format of the pmLabelSet data structure is described in detail in pmLookupLabels(3). go read that one, i'll wait π«Ά
okay so here's the thing β names can repeat across the label sets u hand in, but duplicate names are NOT allowed in the final buffer. periodt. so any label name that shows up in more than one input set gets reduced down to one, using the rules in the "PRECEDENCE" section of pmLookupLabels. and listen: the position of each element in the sets array matters for those precedence rules β earlier positions are taken to be of lower precedence than later positions. so like, order is the moment, fr fr π
values have to be primitive JSON entities (numbers, strings, that kind of thing), one-dimensional arrays, or maps (aka simple associative arrays). no fancy business π
and here's the extra lil bonus: besides using indexed label sets, the pmMergeLabelSets interface also gives u an optional filter callback function. if it's non-NULL, this function gets called for every label that would be added to the output buffer, which gives u finer-grained control over the final merged set. u can use this to filter individual labels based on their name, value, and/or flags. if the filter function returns zero (false), then that label gets filtered out of the resulting set. any non-zero return value means the label should be included in the buffer. simple as π
π PYTHON EXAMPLE π
import sys
import json
from pcp import pmapi
import cpmapi as c_api
def merge_callback(label, jsondata, data=None):
d = json.loads(jsondata)
labelsD.update(d)
return 0
ctx = pmapi.pmContext()
for metric in sys.argv[1:]:
pmid = ctx.pmLookupName(metric)[0]
lset = ctx.pmLookupLabels(pmid)
labelsD = {}
ctx.pmMergeLabelSets(lset, merge_callback)
print("== %s ===" % metric)
for n,v in labelsD.items():
print(" %s = %s" % (n,v))
ctx.pmFreeLabelSets(lset)
π DIAGNOSTICS π
on success, both pmMergeLabels and pmMergeLabelSets return the number of bytes written into the supplied buffer. slay π
but if it fails to parse the input strings, fails to allocate memory, or finds any internal inconsistencies, ur getting a negative return code. so like, check that return value bestie, don't just vibe past it π
π₯ SEE ALSO π₯
pminfo(1), PMAPI(3) and pmLookupLabels(3).
and that's the whole page!! this one came to u from Performance Co-Pilot (that's the PCP girlies πΈ), and it's the PMMERGELABELS(3) page β no cap, go merge some labels, u got this ππ
π¦ 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.1.0-6.fc44 Β· 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) 2016-2017 Red Hat. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms