> For the complete documentation index, see [llms.txt](https://spaceone-dev.gitbook.io/spaceone-apis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://spaceone-dev.gitbook.io/spaceone-apis/statistics/v1/resource.md).

# Resource

> **Package : spaceone.api.statistics.v1**

## Resource

{% hint style="info" %}
**Resource Methods:**
{% endhint %}

| Method            | Request                                     | Response                                                                                                           |
| ----------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| [**stat**](#stat) | [ResourceStatRequest](#resourcestatrequest) | [google.protobuf.Struct](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/struct.proto) |

### stat

> **POST** /statistics/v1/resources/stat

> Enables data preprocessing of different services. Although limited, it is possible to create not only basic queries but also data suitable for users' needs, such as joins between two tables created by the query, handling missing values, and sorting.

| Type     | Message                                                                                                            |
| -------- | ------------------------------------------------------------------------------------------------------------------ |
| Request  | [ResourceStatRequest](#resourcestatrequest)                                                                        |
| Response | [google.protobuf.Struct](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/struct.proto) |

{% tabs %}
{% tab title="Request Example" %}

```
{
    "aggregate": [
        {
            "query": {
                "resource_type": "inventory.CloudServiceType",
                "query": {
                    "filter": [
                        {
                            "k": "labels",
                            "v": [
                                "Server"
                            ],
                            "o": "in"
                        },
                        {
                            "k": "is_primary",
                            "v": true,
                            "o": "eq"
                        }
                    ],
                    "aggregate": [
                        {
                            "group": {
                                "keys": [
                                    {
                                        "key": "cloud_service_type_id",
                                        "name": "cloud_service_type_id"
                                    },
                                    {
                                        "key": "name",
                                        "name": "cloud_service_type"
                                    },
                                    {
                                        "key": "group",
                                        "name": "cloud_service_group"
                                    },
                                    {
                                        "key": "provider",
                                        "name": "provider"
                                    },
                                    {
                                        "key": "cloud_service_type_id",
                                        "name": "cloud_service_type_id"
                                    }
                                ],
                                "fields": [
                                    {
                                        "key": "tags",
                                        "name": "tags",
                                        "operator": "first"
                                    },
                                    {
                                        "key": "labels",
                                        "name": "labels",
                                        "operator": "first"
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        },
        {
            "join": {
                "resource_type": "inventory.CloudService",
                "query": {
                    "filter": [
                        {
                            "k": "ref_cloud_service_type.cloud_service_type_id",
                            "v": [
                                "cloud-svc-type-58c926b19aca",
                                "cloud-svc-type-c7e5bc38d911",
                                "cloud-svc-type-8dd4d7a13b95",
                                "cloud-svc-type-719e705cb529",
                                "cloud-svc-type-50bd62cf6e0e"
                            ],
                            "o": "in"
                        }
                    ],
                    "aggregate": [
                        {
                            "group": {
                                "keys": [
                                    {
                                        "key": "cloud_service_type",
                                        "name": "cloud_service_type"
                                    },
                                    {
                                        "key": "cloud_service_group",
                                        "name": "cloud_service_group"
                                    },
                                    {
                                        "key": "provider",
                                        "name": "provider"
                                    }
                                ],
                                "fields": [
                                    {
                                        "name": "count",
                                        "operator": "count"
                                    }
                                ]
                            }
                        }
                    ]
                },
                "keys": [
                    "cloud_service_type",
                    "cloud_service_group",
                    "provider"
                ]
            }
        },
        {
            "fill_na": {
                "data": {
                    "count": 0.0
                }
            }
        },
        {
            "formula": {
                "query": "count > 0"
            }
        },
        {
            "sort": {
                "key": "count",
                "desc": true
            }
        }
    ],
    "domain_id": "domain-58010aa2e451"
}
```

{% endtab %}

{% tab title="Response Example" %}

```
{
    "total_count": 5.0,
    "results": [
        {
            "labels": [
                "Compute",
                "Server"
            ],
            "cloud_service_type_id": "cloud-svc-type-58c926b19aca",
            "cloud_service_type": "Instance",
            "count": 44.0,
            "tags": [
                {
                    "key": "spaceone:icon",
                    "value": "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/aws-ec2.svg"
                }
            ],
            "provider": "aws",
            "cloud_service_group": "EC2"
        },
        {
            "tags": [
                {
                    "key": "spaceone:icon",
                    "value": "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/openstack/openstack_compute.svg"
                },
                {
                    "key": "spaceone:display_name",
                    "value": "Instance"
                }
            ],
            "cloud_service_group": "Compute",
            "cloud_service_type": "Instance",
            "provider": "openstack",
            "count": 12.0,
            "labels": [
                "Compute",
                "Server"
            ],
            "cloud_service_type_id": "cloud-svc-type-50bd62cf6e0e"
        },
        {
            "cloud_service_type": "Node",
            "count": 8.0,
            "provider": "kubernetes",
            "cloud_service_type_id": "cloud-svc-type-719e705cb529",
            "cloud_service_group": "Cluster",
            "tags": [
                {
                    "value": "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/kubernetes/node.svg",
                    "key": "spaceone:icon"
                }
            ],
            "labels": [
                "Compute",
                "Server",
                "Container"
            ]
        },
        {
            "cloud_service_type_id": "cloud-svc-type-8dd4d7a13b95",
            "cloud_service_type": "Instance",
            "cloud_service_group": "ComputeEngine",
            "labels": [
                "Compute",
                "Server"
            ],
            "tags": [
                {
                    "key": "spaceone:icon",
                    "value": "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/cloud-services/google_cloud/Compute_Engine.svg"
                }
            ],
            "count": 5.0,
            "provider": "google_cloud"
        },
        {
            "tags": [
                {
                    "value": "https://spaceone-custom-assets.s3.ap-northeast-2.amazonaws.com/console-assets/icons/azure-vm.svg",
                    "key": "spaceone:icon"
                }
            ],
            "cloud_service_type": "VirtualMachine",
            "cloud_service_group": "Compute",
            "count": 2.0,
            "provider": "azure",
            "cloud_service_type_id": "cloud-svc-type-c7e5bc38d911",
            "labels": [
                "Compute",
                "Server"
            ]
        }
    ]
}
```

{% endtab %}
{% endtabs %}

##

## Message

### ResourceStatRequest

| Field      | Type                                    | Required | Description |
| ---------- | --------------------------------------- | :------: | ----------- |
| aggregate  | [list of StatAggregate](#stataggregate) |     ✔    |             |
| page       | [StatPage](#statpage)                   |     ✘    |             |
| domain\_id | string                                  |     ✔    |             |

### SortKey

| Field | Type   | Description |
| ----- | ------ | ----------- |
| key   | string |             |
| desc  | bool   |             |

### StatAggregate

| Field    | Type                                          | Description |
| -------- | --------------------------------------------- | ----------- |
| query    | [StatAggregateQuery](#stataggregatequery)     |             |
| join     | [StatAggregateJoin](#stataggregatejoin)       |             |
| concat   | [StatAggregateConcat](#stataggregateconcat)   |             |
| sort     | [StatAggregateSort](#stataggregatesort)       |             |
| formula  | [StatAggregateFormula](#stataggregateformula) |             |
| fill\_na | [StatAggregateFillNA](#stataggregatefillna)   |             |

### StatAggregateConcat

| Field          | Type                                                                                                               | Required | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------ | :------: | ----------- |
| resource\_type | string                                                                                                             |     ✔    |             |
| query          | [spaceone.api.core.v1.StatisticsQuery](https://spaceone-dev.gitbook.io/api-reference/common-v1/statistics-query)   |     ✔    |             |
| extend\_data   | [google.protobuf.Struct](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/struct.proto) |     ✘    |             |

### StatAggregateFillNA

| Field | Type                                                                                                               | Required | Description |
| ----- | ------------------------------------------------------------------------------------------------------------------ | :------: | ----------- |
| data  | [google.protobuf.Struct](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/struct.proto) |     ✔    |             |

### StatAggregateFormula

| Field | Type   | Description |
| ----- | ------ | ----------- |
| eval  | string |             |
| query | string |             |

### StatAggregateJoin

| Field          | Type                                                                                                               | Required | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------ | -------- | ----------- |
| resource\_type | string                                                                                                             | ✔        |             |
| query          | [spaceone.api.core.v1.StatisticsQuery](https://spaceone-dev.gitbook.io/api-reference/common-v1/statistics-query)   | ✔        |             |
| extend\_data   | [google.protobuf.Struct](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/struct.proto) | ✘        |             |
| type           | <ul><li>LEFT</li><li>RIGHT</li><li>OUTER</li><li>INNER</li></ul>                                                   | ✘        |             |
| keys           | list of string                                                                                                     | ✘        |             |

### StatAggregateQuery

| Field          | Type                                                                                                               | Required | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------ | :------: | ----------- |
| resource\_type | string                                                                                                             |     ✔    |             |
| query          | [spaceone.api.core.v1.StatisticsQuery](https://spaceone-dev.gitbook.io/api-reference/common-v1/statistics-query)   |     ✔    |             |
| extend\_data   | [google.protobuf.Struct](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/struct.proto) |     ✘    |             |

### StatAggregateSort

| Field | Type                        | Required | Description |
| ----- | --------------------------- | :------: | ----------- |
| key   | string                      |     ✘    |             |
| desc  | bool                        |     ✘    |             |
| keys  | [list of SortKey](#sortkey) |     ✘    |             |

### StatPage

| Field | Type                                                                                             | Required | Description |
| ----- | ------------------------------------------------------------------------------------------------ | :------: | ----------- |
| start | [uint32](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/type.proto) |     ✘    |             |
| limit | [uint32](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/type.proto) |     ✔    |             |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://spaceone-dev.gitbook.io/spaceone-apis/statistics/v1/resource.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
