---
name: "pmiAddMetric"
section: "3"
platform: "linux"
package: "pcp"
version: "7.2.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/pmiAddMetric"
---

# pmiAddMetric(3)

add a new metric definition to a LOGIMPORT context

## NAME

**pmiAddMetric** - add a new metric definition to a LOGIMPORT context

## C SYNOPSIS

**#include \<pcp/pmapi.h\>**\
 **#include \<pcp/import.h\>**

**int pmiAddMetric(const char \****name***,** **pmID** *pmid***,** **int** *type***,** **pmInDom** *indom***,** **int** *sem***,** **pmUnits** *units***);**

**cc ... -lpcp\_import -lpcp**

## Perl SYNOPSIS

**use PCP::LogImport;**

**pmiAddMetric($***name***,** **$***pmid***,** **$***type***,** **$***indom***,** **$***sem***,** **$***units***);**

## Python SYNOPSIS

**from pcp import pmi**

**log.pmiAddMetric(***name***,** *pmid***,** *type***,** *indom***,** *sem***,** *units***)**

## DESCRIPTION

As part of the Performance Co-Pilot Log Import API (see [**LOGIMPORT**(3)](/LOGIMPORT/3.md)), **pmiAddMetric** is used to define a new metric.  The metric's *name* must follow the naming conventions described in [**PCPIntro**(1)](/PCPIntro/1.md) and should be unique for each LOGIMPORT context.

The other arguments are in effect the fields of a **pmDesc** structure. Refer to [**pmLookupDesc**(3)](/pmLookupDesc/3.md) for a complete description of the values and semantics of the components of this structure, and hence the valid argument values for **pmiAddMetric**.

The internal identifier for the metric may be given using the *pmid* argument and must be unique for each LOGIMPORT context. The value for *pmid* which would typically be constructed using the **pmID\_build** macro, e.g. pmID\_build(PMI\_DOMAIN, 0, 3) for the fourth metric in first \`\`cluster'' of metrics in the Performance Metrics Domain PMI\_DOMAIN (which is the default for all meta data created by the LOGIMPORT library). Alternatively, *pmid* may be **PM\_IN\_NULL** and **pmiAddMetric** will assign a unique *pmid* (although this means the *pmid* remains opaque and the application must use [**pmiPutValue**(3)](/pmiPutValue/3.md) or [**pmiPutValueHandle**(3)](/pmiPutValueHandle/3.md) and cannot use [**pmiPutResult**(3)](/pmiPutResult/3.md) to add data values to the PCP archive).

*type* defines the data type of the metric and must be one of the **PM\_TYPE\_...** values defined in **\<pcp/import.h\>**.

The instance domain for the metric is defined by *indom* and may be **PM\_INDOM\_NULL** for a metric with a singular value, else the value for *indom* would normally be constructed using the **pmInDom\_build** macro, e.g. pmInDom\_build(LOGIMPORT,0) for the first instance domain in the Performance Metrics Domain LOGIMPORT (which is the default for all meta data created by the LOGIMPORT library). Multiple metrics can share the same instance domain if they have values for a similar (or more usually, identical) set of instances.

The semantics of the metric (counter, instantaneous value, etc.) is specified by the *sem* argument which would normally be the result of a call to the convenience constructor methods [**pmiUnits**(3)](/pmiUnits/3.md) or [**pmiExtraUnits**(3)](/pmiExtraUnits/3.md)

## DIAGNOSTICS

**pmiAddMetric** returns zero on success else a negative value that can be turned into an error message by calling [**pmiErrStr**(3)](/pmiErrStr/3.md).

## SEE ALSO

[**PCPIntro**(1)](/PCPIntro/1.md), [**LOGIMPORT**(3)](/LOGIMPORT/3.md), [**PMAPI**(3)](/PMAPI/3.md), [**pmLookupDesc**(3)](/pmLookupDesc/3.md), [**pmiErrStr**(3)](/pmiErrStr/3.md), [**pmiExtraUnits**(3)](/pmiExtraUnits/3.md), [**pmiPutLabel**(3)](/pmiPutLabel/3.md), [**pmiPutResult**(3)](/pmiPutResult/3.md), [**pmiPutText**(3)](/pmiPutText/3.md), [**pmiPutValue**(3)](/pmiPutValue/3.md), [**pmiPutValueHandle**(3)](/pmiPutValueHandle/3.md) and [**pmiUnits**(3)](/pmiUnits/3.md).
