Do you think IIT Guwahati certified course can help you in your career?
No
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.
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.
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.
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:
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:
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.
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.
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.
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:
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: