pmjsonInit man page

pmjsonInit, pmjsonInitIndom — JSON performance metrics extraction

C Synopsis

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

int pmjsonInitIndom(int fd, json_metric_desc *json_metrics, int num_metrics, pmInDom indom);

int pmjsonInit(int fd, json_metric_desc *json_metrics, int num_metrics);

cc ... -lpcp_web


pmjsonInitIndom creates and initializes JSON metric extraction functionality for PCP metrics with instance domains. Metrics and instances are defined by the json_metrics parameter. The result of parsing is the extraction of values for the requested metrics (as defined in the json_pointer field) in the values field.

pmjsonInit specifies a call to the JSON parsing and metric value extraction functionality where there are no instance domains, or the PMDA wishes to perform instance domain operations itself.

fd is an open file descriptor from which the JSON document will be read.

json_metrics is the array of json_metric_desc struct which contains the json pointer to the metric data, possible flags to check the data against, number of values (in the case of an array), pmAtomValue where the data is stored, as well as the instance domain in the even the PMDA in question has multiple domains. pmjsonInitIndom will endeavour to make use of the pmdaCacheAdd(3) function where possible. In the event that no indom is needed, PM_INDOM_NULL should be passed, or pmjsonInit used instead.

num_metrics is the number of elements in in the array of json_metrics.

indom is the instance domain to be passed to pmdaCacheAdd.

typedef struct json_metrics_desc {
    char          *json_pointer;  /* json pointer to metric */
    int           flags;          /* flags to check if set */
    int           num_values;     /* number of values */
    pmAtomValue   values;         /* metric value */
    char          *dom;           /* instance domain */
} json_metric_desc;

The JSON Pointer syntax current follows RFC6901 in specifying a metrics location within the JSON document.


For the sample JSON document:
    "Name": "/clever_almeida",
    "State": {
        "Dead": false,
        "Error": "",
        "ExitCode": 0,
        "FinishedAt": "2016-07-18T21:21:20.332488706Z",
        "OOMKilled": false,
        "Paused": false,
        "Pid": 0,
        "Restarting": false,
        "Running": false,
        "StartedAt": "2016-07-18T14:10:58.52487316Z"

A possible corresponding json_metric array would be as follows for the
Pid, Name, and metrics to indicate whether the container is Running,
Paused, or Restarting.

static json_metric_desc json_metrics[] = {
    { "State/Pid", 0, 1, {0}, ""},
    { "Name", 0, 1, {0}, ""},
    { "State/Running", CONTAINER_FLAG_RUNNING, 1, {0}, ""},
    { "State/Paused", CONTAINER_FLAG_PAUSED, 1, {0}, ""},
    { "State/Restarting", CONTAINER_FLAG_RESTARTING, 1, {0}, ""},

Return Code

The function returns zero on success, otherwise an error code suitable for passing to pmErrStr_r(3) is returned.

See Also

pmErrStr_r(3), pmdaCacheAdd(3),,,,

Referenced By


pmjsoninit(3) is an alias of pmjsonInit(3).

PCP Performance Co-Pilot