Main Content

GET Metrics

Retrieve server metrics

Description

Use the GET method to retrieve metrics for a server instance in the Prometheus® metrics format. The metrics service returns information about requests that client applications send to the server, and the time and memory that the server takes to execute the requests. You can use the metrics service to monitor server metrics in a Kubernetes® environment. All server metrics reset on a server restart.

In addition to the server metrics, the metrics service also returns custom metrics that you can create in the MATLAB® function that you deploy to the server. For a detailed example, see Create Custom Prometheus Metrics. Custom metrics reset depending on the value of the worker-restart-interval property.

To use the metrics service, you must enable the metrics service on the server. Do this by uncommenting the option --enable-metrics in the main_config server configuration file.

Request

HTTP Method

GET

URI

http(s)://host:port/api/metrics

Response

Success

HTTP Status Code

200 OK

Body
NameDescription
matlabprodserver_up_time_secondsTime in fractional seconds since server startup.
matlabprodserver_queue_time_secondsSum of wait times in fractional seconds for currently queued synchronous and asynchronous requests.
matlabprodserver_cpu_time_seconds

Total CPU time in fractional seconds that the server spent in request execution after startup.

matlabprodserver_memory_working_set_bytesSum of memory utilization in bytes by all MATLAB Production Server™ processes at a given time.
matlabprodserver_requests_accepted_total

Total number of valid requests that the server received after startup.

Total requests accepted at a given time is the sum of requests that are canceled, in queue, processing, and requests that have failed and successfully completed after server startup.

matlabprodserver_requests_in_queueNumber of requests currently waiting to be processed by the server.
matlabprodserver_requests_processingNumber of requests that the server is currently processing.
matlabprodserver_requests_succeeded_totalTotal number of requests that completed successfully.
matlabprodserver_requests_failed_totalTotal number of requests that failed. Requests can fail if they contain an incorrect name of the deployed MATLAB function.
matlabprodserver_requests_canceled_totalTotal number of asynchronous requests that clients canceled.

Error

403 Metrics Disabled

Sample Call

HTTP

Request:

GET /api/metrics HTTP/1.1
Host: localhost:9910

Response:

# TYPE matlabprodserver_up_time_seconds counter
matlabprodserver_up_time_seconds 68140.5
# TYPE matlabprodserver_queue_time_seconds gauge
matlabprodserver_queue_time_seconds 0
# TYPE matlabprodserver_cpu_time_seconds counter
matlabprodserver_cpu_time_seconds 18.2188
# TYPE matlabprodserver_memory_working_set_bytes gauge
matlabprodserver_memory_working_set_bytes 1.57426e+08
# TYPE matlabprodserver_requests_accepted_total counter
matlabprodserver_requests_accepted_total 0
# TYPE matlabprodserver_requests_in_queue gauge
matlabprodserver_requests_in_queue 0
# TYPE matlabprodserver_requests_processing gauge
matlabprodserver_requests_processing 0
# TYPE matlabprodserver_requests_succeeded_total counter
matlabprodserver_requests_succeeded_total 0
# TYPE matlabprodserver_requests_failed_total counter
matlabprodserver_requests_failed_total 0
# TYPE matlabprodserver_requests_canceled_total counter
matlabprodserver_requests_canceled_total 0

JavaScript

var data = null;
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "http://localhost:9910/api/metrics");
xhr.send(data);

Version History

Introduced in R2021a

See Also

| (MATLAB Compiler SDK) | (MATLAB Compiler SDK)

External Websites