PMNEWCONTEXT(3)
π PMNEWCONTEXT(3) β the manual page bestie π
okay so this is pmNewContext from the Performance Co-Pilot library functions manual, and we're gonna get you fluent in it, no cap. β¨
πΈ NAME πΈ
pmNewContext β establish a new PMAPI context (it's giving "new era, new me" but for performance metrics) π¦
β¨ C SYNOPSIS β¨
#include <pcp/pmapi.h>
int pmNewContext(int type, const char *name);
cc ... -lpcp
π DESCRIPTION π
So basically, an app using the Performance Metrics Application Programming Interface (PMAPI) can juggle several concurrent contexts at once, and each one is tied to a source of performance metrics β like pmcd(1) on some host, or a set of archives of performance metrics as created by pmlogger(1), or a stand-alone connection on the local host that does not involve pmcd(1). multiple contexts? she contains multitudes. π
pmNewContext is the one you call to establish a new context. The source of the metrics is identified by name, and it can be either a host name (when type is PM_CONTEXT_HOST), or a comma-separated list of names referring to a set of archives (when type is PM_CONTEXT_ARCHIVE). Each element of that list can either be the base name common to all of the physical files of an archive, or the name of a directory containing archives. ποΈ
π when type is PM_CONTEXT_HOST π
For a type of PM_CONTEXT_HOST, besides identifying a host, the name can also encode extra optional info: a pmcd(1) port number, a pmproxy(1) hostname, and a proxy port number. For example, the name "app23:14321,4321@firewall.example.com:11111" specifies a connection on port 14321 (or port 4321 if 14321 is unavailable) to pmcd(1) on the host app23 via port 11111 to pmproxy(1) on the host firewall.example.com. iconic networking moment fr fr. π
Alternatively, for a type of PM_CONTEXT_HOST, name may be unix: for an authenticated Unix domain socket connection to pmcd(1) on the localhost, or local: for an authenticated connection to pmcd(1) on the localhost via a Unix domain socket if available, else via an internet socket connection to localhost. local: is the default choice for most applications when calling pmNewContext to establish a context for pmcd(1) on the local host. the default! remember it! π«Ά
π when type is PM_CONTEXT_ARCHIVE π
For a type of PM_CONTEXT_ARCHIVE, each element of the list of names in name may also be the name of any of the physical files of an archive, e.g. myarchive.meta (the metadata file) or myarchive.index (the temporal index) or myarchive.0 (the first data volume of the archive) or myarchive.0.bz2 or myarchive.0.bz (the first data volume compressed with bzip2(1)) or myarchive.0.gz or myarchive.0.Z or myarchive.0.z (the first data volume compressed with gzip(1)), myarchive.1 or myarchive.3.bz2 or myarchive.42.gz etc. so many file extensions bestie, it's a whole alphabet. π₯
β οΈ the archive-set restrictions β οΈ
If more than one archive is specified for a type of PM_CONTEXT_ARCHIVE, there are some restrictions on the archives within the set β and these are not optional, they're the vibe check the archives must pass:
- The archives must all have been generated on the same host.
- The archives must not overlap in time.
- The archives must all have been created using the same time zone.
- The PMID of each metric should be the same in all of the archives. Multiple PMIDs are currently tolerated by using the first PMID defined for each metric and ignoring subsequent PMIDs.
- The type of each metric must be the same in all of the archives.
- The semantics of each metric must be the same in all of the archives.
- The units of each metric must be the same in all of the archives.
- The instance domain of each metric must be the same in all of the archives.
like, they all gotta match, it's giving synchronized swimming. πββοΈ
π when type is PM_CONTEXT_LOCAL π
In the case where type is PM_CONTEXT_LOCAL, name is ignored, and the context uses a stand-alone connection to the PMDA methods used by pmcd(1). The mechanism in the library uses the same ``plugin'' architecture that operates between pmcd(1) and DSO PMDAs, so operations involve function calls rather than IPC message passing β for PM_CONTEXT_LOCAL contexts this may mean lower latency for operations like pmFetch(3), but at the cost of longer initialization time and possible access control differences compared to pmcd(1). tradeoffs, we love to see them. π
When this type of context is used, the range of accessible performance metrics is constrained to those from the DSO PMDAs defined in the pmcd(1) configuration file /etc/pcp/pmcd/pmcd.conf, so those reported by the command
$ awk '$3 == "dso" {print}' /etc/pcp/pmcd/pmcd.conf
or alternatively reported by the command
$ pminfo -f pmcd.agent.type | grep 'value 0'
This usually means the PMDA exporting metrics from the operating system and the pmcd'', pmproxy'' and may includes some others like ``mmv''. Alternate DSO PMDAs can be used, refer to pmSpecLocalPMDA(3). π«
π the PM_CONTEXT_HOST extra flags π
In the case where type is PM_CONTEXT_HOST, additional flags can be added to the type to indicate if the connection to pmcd(1) should be encrypted (PM_CTXFLAG_SECURE), should be encrypted if possible (PM_CTXFLAG_RELAXED), is deferred (PM_CTXFLAG_SHALLOW), should use authentication (PM_CTXFLAG_AUTH), should be a connection to a container (PM_CTXFLAG_CONTAINER), or if the file descriptor used to communicate with pmcd(1) should not be shared across contexts (PM_CTXFLAG_EXCLUSIVE). Both the PM_CTXFLAG_SHALLOW and PM_CTXFLAG_EXCLUSIVE flags are now deprecated and ignored. π (the way they got phased outβ¦ periodt.)
π¦ the PM_CONTEXT_ARCHIVE extra flags π¦
When type is PM_CONTEXT_ARCHIVE, additional flags can be added to the type for restricted handling of the archive suited to applications that are aware of the structure of PCP archives, namely PM_CTXFLAG_NO_FEATURE_CHECK (do not check feature compatibility for archive label records), PM_CTXFLAG_METADATA_ONLY (open only the metadata, not the data volume(s) nor the index) and PM_CTXFLAG_LAST_VOLUME (open the archive at the start of the last data volume, instead of the default start of the first data volume). ποΈ
Multiple flags can be specified by bit-wise ``or-ing'' of the PM_CTXFLAG macros, but not all combinations make sense, e.g. if PM_CTXFLAG_METADATA_ONLY and PM_CTXFLAG_LAST_VOLUME are specified, PM_CTXFLAG_METADATA_ONLY takes precedence. precedence! she said it first, she wins!
π¦ what you get when it's set up π¦
The initial instance profile is set up to select all instances in all instance domains. In the case of a set of archives, the initial collection time is also set to zero, so that an initial pmFetch(3) will result in the earliest set of metrics being returned from the set of archives. π°οΈ
Once established, the association between a context and a source of metrics is fixed for the life of the context, however routines are provided to independently manipulate both the instance profile (see pmAddProfile(3) and pmDelProfile(3)) and the collection time for archives (see pmSetMode(3)).
pmNewContext returns a handle that may be used with subsequent calls to pmUseContext(3). π«
The new context remains the current PMAPI context for all subsequent calls across the PMAPI, until another call to pmNewContext(3) is made, or the context is explicitly changed with a call to pmDupContext(3) or pmUseContext(3), or destroyed using pmDestroyContext(3). main character energy: the context stays until something else steals the spotlight. β¨
β³ the timeout tea β³
When attempting to connect to a remote pmcd(1) on a machine that is booting, pmNewContext could potentially block for a long time until the remote machine finishes its initialization. pmNewContext will abort and return an error if the connection has not been established after some specified interval has elapsed. The default interval is 5 seconds. This may be modified by setting PMCD_CONNECT_TIMEOUT in the environment to a real number of seconds for the desired timeout. This is most useful in cases where the remote host is at the end of a slow network, requiring longer latencies to establish the connection correctly. π’
π¨ CAVEATS π¨
When using a type of PM_CONTEXT_LOCAL, the operating system PMDA may export data structures directly from the kernel, which means that the pmNewContext caller should be an executable program compiled for the same object code format as the booted kernel. same object code format or it's a whole situation. π
In addition, applications using a PM_CONTEXT_LOCAL context must be single-threaded because the various DSO PMDAs may not be thread-safe. This restriction is enforced at the PMAPI(3), where routines may return the error code PM_ERR_THREAD if the library detects calls from more than one thread. no multitasking bestie, pick a lane. π
Applications that use gethostbyname(3) should exercise caution because the static fields in struct hostent may not be preserved across some PMAPI(3) calls. In particular, pmNewContext(3) and pmReconnectContext(3) both may call gethostbyname(3) internally. β οΈ
π DIAGNOSTICS π
PM_ERR_PERMISSIONβ No permission to perform requested operationPM_ERR_CONNLIMITβ PMCD connection limit for this host exceededPM_ERR_NOCONTEXTβ Requested context type was notPM_CONTEXT_LOCAL,PM_CONTEXT_HOSTorPM_CONTEXT_ARCHIVE.PM_ERR_LOGOVERLAPβ Archives overlap in timePM_ERR_LOGHOSTβ Archives differ by hostPM_ERR_LOGCHANGETYPEβ The type of a metric differs among archivesPM_ERR_LOGCHANGESEMβ The semantics of a metric differs among archivesPM_ERR_LOGCHANGEINDOMβ The instance domain of a metric differs among archivesPM_ERR_LOGCHANGEUNITSβ The units of a metric differs among archives
these are the error codes and they are NOT playing around. π
πΏ ENVIRONMENT πΏ
PMCD_CONNECT_TIMEOUTβ Timeout period (in seconds) forpmcd(1)connection attempts.PMCD_PORTβ TCP/IP port(s) for connecting topmcd(1), historically was4321and more recently the officially registered port44321; in the current release, pmcd listens on both these ports as a transitional arrangement. If used, should be set to a comma-separated list of numerical port numbers.
π SEE ALSO π
pmcd(1), pminfo(1), pmproxy(1), PMAPI(3), pmAddProfile(3), pmDelProfile(3), pmDestroyContext(3), pmDupContext(3), pmFetch(3), pmGetConfig(3), pmReconnectContext(3), pmSetMode(3), pmSpecLocalPMDA(3), pmUseContext(3), pmWhichContext(3), pcp.conf(5) and pcp.env(5).
and that's the whole page bestie!! this was Performance Co-Pilot, PCP, PMNEWCONTEXT(3), and you ate that. go establish some contexts, stay single-threaded, and remember: local: is the default. mwah! πππ¦β¨
π¦ 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.0.1-1.fc43 Β· 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 Red Hat
- Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms