---
type: api
title: Get machine learning memory usage info
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-ml-get-memory-stats
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v9/operation/operation-ml-get-memory-stats
products:
  - Elasticsearch
---

# Get machine learning memory usage info


Availability: Generally available since 8.2

## Paths

- `GET` `/_ml/memory/{node_id}/_stats`
- `GET` `/_ml/memory/_stats`

#### Path parameters

- `node_id` (string) — optional, leave it out to use `/_ml/memory/_stats`
  The names of particular nodes in the cluster to target. For example, `nodeId1,nodeId2` or
`ml:true`

## Description

Get information about how machine learning jobs and trained models are using memory,
on each node, both within the JVM heap, and natively, outside of the JVM.

## Required authorization

- Cluster privileges: `monitor_ml`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## Query string parameters

- `master_timeout` (string · default: 30s) — optional
  Period to wait for a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error.
- `timeout` (string · default: 30s) — optional
  Period to wait for a response. If no response is received before the timeout expires, the request
fails and returns an error.

## Response

`application/json`

- `_nodes` (object)
  - `failures` (object[])
    - `type` (string)
      The type of error
    - `reason` (union string) — nullable
      A human-readable explanation of the error, in English.
      One of: `string`
    - `stack_trace` (string)
      The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
    - `caused_by` (object) — recursive
      Same fields as `failures` in `_nodes`
    - `root_cause` (object[]) — recursive
      Same fields as `failures` in `_nodes`
    - `suppressed` (object[]) — recursive
      Same fields as `failures` in `_nodes`
  - `total` (number)
    Total number of nodes selected by the request.
  - `successful` (number)
    Number of nodes that responded successfully to the request.
  - `failed` (number)
    Number of nodes that rejected the request or failed to respond. If this value is not 0, a reason for the rejection or failure is included in the response.
- `cluster_name` (string)
- `nodes` (map string to object)
  Map values (object)
  - `attributes` (map string to string)
  - `jvm` (object)
    Contains Java Virtual Machine (JVM) statistics for the node.
    - `heap_max` (number | string)
      Maximum amount of memory available for use by the heap.
    - `heap_max_in_bytes` (number)
      Maximum amount of memory, in bytes, available for use by the heap.
    - `java_inference` (number | string)
      Amount of Java heap currently being used for caching inference models.
    - `java_inference_in_bytes` (number)
      Amount of Java heap, in bytes, currently being used for caching inference models.
    - `java_inference_max` (number | string)
      Maximum amount of Java heap to be used for caching inference models.
    - `java_inference_max_in_bytes` (number)
      Maximum amount of Java heap, in bytes, to be used for caching inference models.
  - `mem` (object)
    Contains statistics about memory usage for the node.
    - `adjusted_total` (number | string)
      If the amount of physical memory has been overridden using the es.total_memory_bytes system property
then this reports the overridden value. Otherwise it reports the same value as total.
    - `adjusted_total_in_bytes` (number)
      If the amount of physical memory has been overridden using the `es.total_memory_bytes` system property
then this reports the overridden value in bytes. Otherwise it reports the same value as `total_in_bytes`.
    - `total` (number | string)
      Total amount of physical memory.
    - `total_in_bytes` (number)
      Total amount of physical memory in bytes.
    - `ml` (object)
      Contains statistics about machine learning use of native memory on the node.
      - `anomaly_detectors` (number | string)
        Amount of native memory set aside for anomaly detection jobs.
      - `anomaly_detectors_in_bytes` (number)
        Amount of native memory, in bytes, set aside for anomaly detection jobs.
      - `data_frame_analytics` (number | string)
        Amount of native memory set aside for data frame analytics jobs.
      - `data_frame_analytics_in_bytes` (number)
        Amount of native memory, in bytes, set aside for data frame analytics jobs.
      - `max` (number | string)
        Maximum amount of native memory (separate to the JVM heap) that may be used by machine learning native processes.
      - `max_in_bytes` (number)
        Maximum amount of native memory (separate to the JVM heap), in bytes, that may be used by machine learning native processes.
      - `native_code_overhead` (number | string)
        Amount of native memory set aside for loading machine learning native code shared libraries.
      - `native_code_overhead_in_bytes` (number)
        Amount of native memory, in bytes, set aside for loading machine learning native code shared libraries.
      - `native_inference` (number | string)
        Amount of native memory set aside for trained models that have a PyTorch model_type.
      - `native_inference_in_bytes` (number)
        Amount of native memory, in bytes, set aside for trained models that have a PyTorch model_type.
  - `name` (string)
    Human-readable identifier for the node. Based on the Node name setting setting.
  - `roles` (string[])
    Roles assigned to the node.
  - `transport_address` (string)
    The host and port where transport HTTP connections are accepted.
  - `ephemeral_id` (string)
## Code examples

#### Console

```console
GET _ml/memory/_stats?human
```

#### JavaScript

```javascript
const response = await client.ml.getMemoryStats({
  human: "true",
});
```

#### Python

```python
resp = client.ml.get_memory_stats(
    human=True,
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_ml/memory/_stats?human" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.ml().getMemoryStats(g -> g);
```

#### C#

```c#
var response = await client.MachineLearning.GetMemoryStatsAsync();
```

#### PHP

```php
$resp = $client->ml()->getMemoryStats([
    "human" => "true",
]);
```

#### Ruby

```ruby
response = client.ml.get_memory_stats(
  human: "true"
)
```

