Selectel Cloud Management API
Consumption Statistics
Follow these steps to view the Cloud platform resource consumption:
-
Obtain a token (API key) to work with the Selectel API.
-
Obtain a token for your account (it must be reissued at least once a day) by running:
curl -X POST -H 'X-Token: <token_value>' -H 'Content-type: application/json' -d '{"token":{"account_name":"<account_id>"}}' -H 'Content-type: application/json' https://my.selectel.ru/api/vpc/resell/v2/tokens
Where:
<token_value>
is the Selectel token (API key);<account_id>
is the account number in the Control panel.
-
An OpenStack Token of the following form will be returned:
{"token": {"id": "<openstack_account_token>"}}
- The Gnocchi REST API is used when working with consumption statistics. Authorization is performed using
<openstack_account_token>
obtained earlier.
Data Sources
Cloud services consumption data is stored in a structure distributed across several regions.
Endpoint | Product services |
---|---|
https://api.ru-3.selvpc.ru/metric/v1/ | Cloud core: virtual machines, volumes, networks, and PaaS products (MKS, DBaaS, Serverless) |
https://api.ru-1.selvpc.ru/metric/v1/ | Cloud platform |
https://api.ru-2.selvpc.ru/metric/v1/ | CDN |
Working with Large Aggregated Data
- To get information about the consumption of the entire cloud account, obtain a permanent Selectel account ID:
curl -H 'Content-type: application/json' -H 'X-Auth-Token: <openstack_account_token>' https://api.ru-3.selvpc.ru/metric/v1/resource/sel_account
- The structure of the following form will be returned:
[
{
"creator": "---",
"started_at": "2020-08-30T10:16:17.244227+00:00",
"revision_start": "2020-08-30T10:16:17.404943+00:00",
"ended_at": null,
"user_id": null,
"project_id": "01be84552e6a452aa14995a73b12345a",
"original_resource_id": "01be84552e6a452aa14995a73b12345a",
"id": "01be8455-2e6a-452a-a149-95a73b12345a",
"type": "sel_account",
"name": "000000",
"revision_end": null,
"metrics": {
"vpc.account.full.cost": "01d9b2e1-7be1-46a8-9ced-000cdcf72cbd"
},
"created_by_user_id": "a0e0123e8c364232b1234dbb31ce1a5e",
"created_by_project_id": "5e200c6ffe184b9f8b69344d36123456"
}
]
Use the id
field from the API response. In further requests, this identifier must be substituted into the <openstack_account_id>
variable.
3. Request metric changes for the vpc.account.full.cost
account:
curl -H 'Content-type: application/json' -H 'X-Auth-Token: <openstack_account_token>' 'https://api.ru-3.selvpc.ru/metric/v1/resource/sel_account/<openstack_account_id>/metric/vpc.account.full.cost/measures?aggregation_methods=max&granularity=86400&start=2021-01-31T21:00:00&stop=2021-04-16T21:00:00'
- Sample response:
[["2021-01-31T00:00:00+00:00", 86400.0, 86.33333333333333],
["2021-02-01T00:00:00+00:00", 86400.0, 205.83333333333334],
...
["2021-02-02T00:00:00+00:00", 86400.0, 242.75]]
Each list element in the response contains three fields: the period start date, the period duration in seconds, and the account consumption value in kopecks.
Working with Consumption Information for Individual Projects
- To obtain information about a single cloud project, request a list of projects:
curl -H 'Content-type: application/json' -H 'X-Auth-Token: <openstack_account_token>' https://api.ru-3.selvpc.ru/metric/v1/resource/sel_project
- The structure of the following form will be returned:
[
{
"creator": "---",
"started_at": "2021-04-27T09:00:00+00:00",
"revision_start": "2021-04-27T10:42:02.957886+00:00",
"ended_at": null,
"user_id": null,
"project_id": "01be84552e6a452aa14995a73b12345a",
"original_resource_id": "a10c12341eb247d1b1c225a4902018e3",
"id": "a10c1234-1eb2-47d1-b1c2-25a4902018e3",
"type": "sel_project",
"parent_id": "01be8455-2e6a-452a-a149-95a73b12345a",
"name": "Test",
"revision_end": null,
"metrics": {
"vpc.compute_cores.ru-7a.cost": "7fe07d04-1f2b-4f3a-a376-fcc00eb6be95",
"vpc.compute_cores.ru-7a.quantity": "c0007aca-0a0a-4a2a-a053-da123dc15a55",
"vpc.compute_ram.ru-7a.cost": "d2ac0509-f6b3-40ae-03e2-125db025fc0a",
"vpc.compute_ram.ru-7a.quantity": "2ad22fad-d01f-4d44-8fb6-123b2cb7fc09",
...
"vpc.project.ru-3.cost": "fba81bd8-bb9d-4f95-9018-e05f912410e3",
"vpc.project.ru-7.cost": "9fc7beaa-d94c-46d1-a56a-b05c8a79ba23",
},
"created_by_user_id": "ec05e123a2b64596bf1e12c4b80139c1",
"created_by_project_id": "5e204c6ffe123b9f8b69344d36178355"
},
...
]
Use the id
field from the API response. In further requests, this identifier must be substituted into the <project_id>
variable.
- Request changes for a specific (
<metric_name>
) metric provided in the API response above:
curl -H 'Content-type: application/json' -H 'X-Auth-Token: <openstack_account_token>' 'https://api.ru-3.selvpc.ru/metric/v1/resource/sel_project/<project_id>/metric/<metric_name>/measures?aggregation_methods=max&granularity=86400&start=2021-01-31T21:00:00&stop=2021-04-16T21:00:00'
- Sample response:
[["2021-03-12T00:00:00+00:00", 86400.0, 10.0]]
Each list element in the response contains three fields: the period start date, the period duration in seconds, and the account consumption value in kopecks.