Table of contents
1.
Introduction
2.
Status API in Puppet
3.
Status API in Puppet: services endpoint
3.1.
GET/status/v1/services
3.1.1.
Request Format
3.1.2.
Response Format
3.2.
GET/status/v1/services/<service_name>
3.2.1.
Request Format
3.2.2.
Response Format
4.
Status API in Puppet: services plaintext endpoint
4.1.
GET/status/v1/simple
4.1.1.
Request Format
4.1.2.
Response Format
4.2.
GET/status/v1/simple/<service_name>
4.2.1.
Request Format
4.2.2.
Response Format
5.
Status API: metrics endpoint
5.1.
GET /status/v1/services/pe-jruby-metrics
5.1.1.
Request Format
5.1.2.
Response Format
5.2.
GET/status/v1/services/pe-master
5.2.1.
Request Format
5.2.2.
Response Format
5.3.
GET/status/v1/services/pe-puppet-profiler
5.3.1.
Request Format
5.3.2.
Response Format
6.
Table for different response codes:
7.
Frequently Asked Questions
7.1.
What are the values for the level parameter?
7.2.
What is the default value of the timeout parameter?
7.3.
What value do we use for the level parameter in the metrics endpoint?
7.4.
Do we need to change the port number in the request if we change the service's port number?
8.
Conclusion
Last Updated: Mar 27, 2024

Advanced Concept of Status API in Puppet

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey Ninja, welcome to yet another article. Have you ever heard of Puppet?? No 🤔?? Let's quickly discuss about Puppet. It is an automation tool. It helps in generating reports and automation and configurations. To know more about Puppet, have a look at this article. In this article, we will discuss the advanced concept of status API in Puppet. Let us start with understanding the status API in Puppet. 

advanced concepts of status api

Status API in Puppet

We have many tools that help us check the status of the puppet code and view reports. One such service is status API in Puppet. We use status API in Puppet to monitor how the PE ( Puppet Enterprise) components and services perform. 

status api

There are several ports to which status API in Puppet endpoints listen. Endpoints inform us about the health of the services and other information, such as connectivity to the server, etc. We will see three endpoints in this article. Let us now move on to the endpoints of the status API in Puppet.

Status API in Puppet: services endpoint

/service is an endpoint. This endpoint returns information about the running services. We use this information in integrating and scripting with other services. The information it returns is understood by machines. 

services endpoint

We have two variations for this endpoint. Let us see its usage, request, and response format.

GET/status/v1/services

This returns the status of all the PE services on a particular port.

Request Format

For this endpoint, we need to specify the port for the PE service we want to query. Below is a table that has the ports and the service linked to it:

Port

Services

8081

Puppet DB

8140

Puppet Server

Code Manager

File Sync Client 

File Sync Storage

8143

Orchestrator

PCP broker

PCP broker v2

4433

RBAC

Activity Service

Classifier

We need to add the following:

level: It tells how rigorous the check should run. 

timeout: It sets the limit for the check and is specified in seconds.

For example: Below is a request that returns the info status of a PE:

cert="$(puppet config print hostcert)"
cacert="$(puppet config print localcacert)"
key="$(puppet config print hostprivkey)"

curl --cert "$cert" --cacert "$cacert" --key "$key" \
--header "Content-Type: application/json" \
--request GET "https://puppet.status.example:4433/status/v1/services?level=info&timeout=50"

Response Format

For queries to this endpoint, we get a JSON object. The object contains a list of details about the PE. The server responds using either code- 200, 503, or 400. The meaning of these codes are in the table at the article's end. The following table represents the key and their meaning.

Key 

Description

service_version

It has the package version of the JAR file. 

service_status_version

It has the version of the API we used to get the status of the PE.

state

It has the value for the state of the PE.

status 

It's an object that has the details of the status of the PE.

detail_level

It returns the value which we specify in the limit parameter while requesting.

active_alerts

If we have replication enabled, it contains an array object that has a message and severity. If we do not have a relocation, it is an empty array.

GET/status/v1/services/<service_name>

This returns the status of the PE services whose name is specified.

Request Format

We need to specify the service name and their respective port number for this endpoint. Below is a table that has the ports and the service linked to it:

Port

Service

4433

classifier-service/ activity-service/ rbac-service

8140

code-manager-service/ server

8081

puppetdb-service

The content type and parameter for this are the same as the get/status/v1/services

For example: Below is a request that returns the info status of a classifier service:

 

cert="$(puppet config print hostcert)"
cacert="$(puppet config print localcacert)"
key="$(puppet config print hostprivkey)"

 

curl --cert "$cert" --cacert "$cacert" --key "$key" \
--header "Content-Type: application/json" \
--request GET "https://puppet.example.com:4433/status/v1/services/classifier-service?level=info&timeout=50"

Response Format

We get a JSON object for queries to this endpoint, just like for GET/status/v1/services. The server responds using either code- 200, 503, 404, or 400

Status API in Puppet: services plaintext endpoint

service plaintext endpoints are helpful in cases where JSON parsing or parameter setting is impossible. It returns a string containing the service state and a status code.

plaintext endpoint

GET/status/v1/simple

The above endpoint provides a status for all the services the status service has an idea about.

Request Format

For this endpoint, we need to specify the port for the PE service we want to query. It uses text/plain; charset=utf-8 as its content type. Also, no parameters are accepted in this endpoint. 

Response Format

200 and 503 are the response code that the server uses. The status of all the services the endpoint has an idea about is the response we get for the request. It can return 3 values: running - which means that all the services are running; error - which means that either one or more services report an error; and unknown - when no services report an error, but any one service is unknown.

GET/status/v1/simple/<service_name>

This returns the status for a specific service we specify in the place of <service_name>.

Request Format

It is the same as that for the GET/status/v1/simple endpoint. It just needs a specific service name to process the request. The service name can be activity-service,classifier-service, code-manager-service, orchestrator-service, puppetdb-service, rbac-service, or server.

Response Format

The server responds with 200, 503, or 400 response codes and their respective messages. 

Status API: metrics endpoint

We use metrics endpoint when we want additional information about Puppet Server. We use the debug value for the limit parameter to get this metric. 

metrics endpoint

Let us see the type of metrics endpoints:

GET /status/v1/services/pe-jruby-metrics

This endpoint returns information about the JRuby pools. It is in JSON format.

Request Format

The port number for this endpoint is 8140, and the value for the level parameter is debug.

uri="https://$(puppet config print server):8140/status/v1/services/pe-jruby-metrics?level=debug"
curl --insecure "$uri"

Response Format

The response code for the response for this endpoint is 200 and 503. It also returns information about PE services in JSON format.

There are two sections in the response(in the experimental section)- jruby-pool-lock-status and metrics.

The keys in jruby-pool-lock-status are in the table below:

Key 

Description

current-state

It can have either of the three values: not-in-use acquired or locked.

last-time-changed

It contains the date and time for the last time the current-state update was made.

The keys in metrics are in the table below:

Key 

Description

average-borrow-time

It contains the average time a JRuby instance takes to handle a request. 

average-wait-time

It is average time the puppet server takes to take a resource from the JRuby pool.

borrow-count

It is the number of JRuby instances in use plus the ones used.

average-requested-jrubies

It is the average number of requests for a JRuby instance.

borrow-timeout-count

It is the number of requests that were not fulfilled and timed out.

num-free-jrubies

It is the number of free JRuby instances that can be put into use.

num-jrubies

The number of JRuby instances present.

num-pool-locks

The number of locked JRuby instances. 

requested-count

The number of JRuby requested, borrowed, or timed out.

requested-instance

The number of requests which are yet to be served.

return-count

The number of instances used(already).

GET/status/v1/services/pe-master

This endpoint provides information about the routes that connect the server and the agent. The information is in JSON format.

Request Format

It is the same as that of the GET/status/v1/services endpoint. Example:

uri="https://$(puppet config print server):8140/status/v1/services/pe-master?level=debug"
curl --insecure "$uri"

Response Format

The response codes for this endpoint are 200 and 503. It also returns information about the PE services in JSON format. There’s a subsection in the experimental section of the response which has the following keys:

Key 

Description

aggregate

It contains the server's total time to execute requests on the route.

count

The total number of requests completed. 

mean

The average time the server takes to process one request for the route.

route-id

The route-id of the route.

GET/status/v1/services/pe-puppet-profiler

It provides us with statistics about catalog compilation. It is in JSON format. 

Request Format

Again the request format is the same as that of the GET/status/v1/services endpoint. We need to add pe-puppet-profiler at the end. Example:

uri="https://$(puppet config print server):8140/status/v1/services/pe-puppet-profiler?level=debug"
curl --insecure "$uri"

 

Response Format

The server responds with codes 200 or 503. The metrics have two subsections: 

function-metrics and resource-metrics. They both contain the following keys:

Key 

Description

function or resource

It is the function name or the resource name.

count

The number of times the function is called or the resource is instantiated during catalog compilation.

aggregate

Total time spent in handling the function or resource.

mean

It contains the value after dividing the aggregate by count.

Table for different response codes:

Here are some examples of Response Code and their description:

Response Code

Description

200

It is the response code when all the services report a running status.

400

The response code is when the level parameter is set to an invalid value.

404

It is the response code when the specified service does not match any service.

503

It is the response code when we are unaware of the status of the service.

Frequently Asked Questions

What are the values for the level parameter?

There are three values for the level parameter: info, debug, and critical.

What is the default value of the timeout parameter?

The default value for the timeout parameter is 30 (seconds).

What value do we use for the level parameter in the metrics endpoint?

We use debug value for the level parameter in the metrics endpoint.

Do we need to change the port number in the request if we change the service's port number?

Yes, we need to specify the port number in the request.

Conclusion

In this article, we learned about advanced concept of status API in Puppet. We saw status API in Puppet’s service endpoints, metrics endpoints, and plaintext endpoints. We saw the request and response format for every endpoint, along with the examples. Check out the Coding Ninjas Studio library to learn more about Puppet. See: 

 

 Don't stop yourself here. Also, practice data structures and algorithmsinterview questionsDBMScomputer networks, and operating systems to crack the interviews of big tech giants. Explore other fields like machine learningdeep learningcomputer vision, and big data. Also, check out Interview Experiences for different companies.

Happy learning!

Live masterclass