Metrics API v2
The /metrics/v2/ endpoints use the Jolokia library
for Java Management Extension (JMX) metrics to query Orchestrator service
metrics.
Jolokia is an extensive, open-source metrics library. We've described how to use the metrics according to the default Puppet Enterprise (PE) configuration; however, you can find more features described in the Jolokia documentation.
For security reasons, by default, we only enable the read-access Jolokia interface, which
includes the read, list,
version, and search
operations. You can Configure Jolokia if you want to change
the security access policy.
Configure Jolokia
You can customize your Jolokia security access policy and metrics.conf settings. You can also use these steps to disable the /metrics/v2/ endpoints.
Forming metrics API requests
The metrics API accepts well-formed HTTPS requests.
URI path
following the
pattern:https://<DNS>:<PORT>/metrics/v2/<OPERATION>
-
DNS: Your PE console host's DNS name. You can uselocalhost, manually enter the DNS name, or use apuppetcommand (as explained in Using example commands). -
PORT: The PuppetDB service port. -
OPERATION: One or more sections specifying the operation for the request, such aslistorread. Some operations require, or allow, additional modifiers such as queries, attributes, and MBean names.
list operation:https://$(puppet config print server):8081/metrics/v2/list
https://puppet.example.dns:8081/metrics/v2/list
To form a complete curl command, you need to provide appropriate curl arguments, and authorization (in the form of a Puppet certificate), the content type, and/or additional parameters specific to the endpoint you are calling.
For general information about forming curl commands, authentication in commands, and Windows modifications, go to Using example commands.
Metrics API wildcards and filtering
The /metrics/v2/ endpoints support globbing (wildcard
selection) and response filtering. You can also combine these features in the same
request.
curl "http://puppet.example.dns:8081/metrics/v2/read/java.lang:name=*,type=GarbageCollector/CollectionCount,CollectionTime"
{
"request": {
"mbean": "java.lang:name=*,type=GarbageCollector",
"attribute": [
"CollectionCount",
"CollectionTime"
],
"type": "read"
},
"value": {
"java.lang:name=PS Scavenge,type=GarbageCollector": {
"CollectionTime": 1314,
"CollectionCount": 27
},
"java.lang:name=PS MarkSweep,type=GarbageCollector": {
"CollectionTime": 580,
"CollectionCount": 5
}
},
"timestamp": 1497977710,
"status": 200
}
Refer to the Jolokia protocol documentation for more information.
GET /metrics/v2/<OPERATION>
Retrieve orchestrator service metrics data or metadata.
Request format
GET /metrics/v2/<OPERATION>/<QUERY>
list operation to get a
list of all valid
MBeans:GET /metrics/v2/list
list operation,
you can form more complex and targeted queries. For example, this request uses the
read operation to query registered logger
names:GET /metrics/v2/read/java.until.logging:type=Logging/LoggerNames
GET /metrics/v2/read/<MBEAN_NAMES>/<ATTRIBUTES>/<INNER_PATH_FILTER>
MBean names are created by joining the first two keys in the list response's value object with a
colon (which are the domain and prop list, in Jolokia terms), such as java.until.logging:type=Logging.
Attributes are derived from the attr object, which is
within the value object in the list response.
If you specify multiple MBean names or attributes, use comma separation, such as:
/java.lang:name=*,type=GarbageCollector/
The inner path filter is optional and depends on the MBeans and attributes you are querying.
You must use the read operation to query MBeans.
For more complex queries, or queries containing special characters, use POST /metrics/v2/<OPERATION>.
Response format
A successful request returns a JSON object containing a series of objects, arrays, and/or key-value pairs describing metrics data or metadata, based on the content of the request.
GET /metrics/v2/list
contains metadata about MBeans you can use to create targeted queries, such
as:{
"request": {
"type": "list"
},
"value": {
"java.util.logging": {
"type=Logging": {
"op": {
"getLoggerLevel": {
...
},
...
},
"attr": {
"LoggerNames": {
"rw": false,
"type": "[Ljava.lang.String;",
"desc": "LoggerNames"
},
"ObjectName": {
"rw": false,
"type": "javax.management.ObjectName",
"desc": "ObjectName"
}
},
"desc": "Information on the management interface of the MBean"
}
},
...
}
}
/metrics/v2/read/java.until.logging:type=Logging/LoggerNames, contains
more specific data. For example:{
"request": {
"mbean": "java.util.logging:type=Logging",
"attribute": "LoggerNames",
"type": "read"
},
"value": [
"javax.management.snmp",
"global",
"javax.management.notification",
"javax.management.modelmbean",
"javax.management.timer",
"javax.management",
"javax.management.mlet",
"javax.management.mbeanserver",
"javax.management.snmp.daemon",
"javax.management.relation",
"javax.management.monitor",
"javax.management.misc",
""
],
"timestamp": 1497977258,
"status": 200
}
POST /metrics/v2/<OPERATION>
Use more complicated queries to retrieve orchestrator service metrics data or metadata.
POST /metrics/v2/ is functionally the same as GET /metrics/v2/<OPERATION>, except that your query is appended in
JSON format. This is useful when your query is complex or includes special
characters.
When forming your request, the content type is application/json and the body must be a JSON object.