swagger.json 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. {
  2. "openapi": "3.0.1",
  3. "info": {
  4. "title": "OpenCost API",
  5. "description": "The OpenCost API provides real-time and historical reporting of Kubernetes cloud costs.",
  6. "license": {
  7. "name": "Apache 2.0",
  8. "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
  9. },
  10. "version": "0.1"
  11. },
  12. "servers": [
  13. {
  14. "url": "http://localhost:9003",
  15. "description": "kubectl port-forward --namespace opencost service/opencost 9003"
  16. }
  17. ],
  18. "paths": {
  19. "/allocation/compute": {
  20. "get": {
  21. "summary": "query for costs and resources allocated to Kubernetes workloads",
  22. "description": "The standard OpenCost API query for costs and resources allocated to Kubernetes workloads. You may specify the `window` date range, the Kubernetes primitive to `aggregate` on, the `step` for the duration of returned sets, and the `resolution` for the duration to use for Prometheus queries.",
  23. "parameters": [
  24. {
  25. "name": "window",
  26. "in": "query",
  27. "description": "Duration of time over which to query. Accepts: words like `today`, `week`, `month`, `yesterday`, `lastweek`, `lastmonth`; durations like `30m`, `12h`, `7d`; [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) date pairs like `2021-01-02T15:04:05Z,2021-02-02T15:04:05Z`; Unix timestamps like `1578002645,1580681045`.",
  28. "required": true,
  29. "style": "form",
  30. "explode": true,
  31. "schema": {
  32. "type": "string"
  33. },
  34. "examples": {
  35. "today": {
  36. "summary": "The current day",
  37. "value": "today"
  38. },
  39. "month": {
  40. "summary": "The month-to-date",
  41. "value": "month"
  42. },
  43. "lastweek": {
  44. "summary": "The previous week",
  45. "value": "lastweek"
  46. },
  47. "30m": {
  48. "summary": "The last 30 minutes",
  49. "value": "30m"
  50. },
  51. "12h": {
  52. "summary": "The last 12 hours",
  53. "value": "12h"
  54. },
  55. "7d": {
  56. "summary": "The previous 7 days",
  57. "value": "7d"
  58. },
  59. "range": {
  60. "summary": "A custom RFC3339 date range",
  61. "value": "2023-01-18T10:30:00Z,2023-01-19T10:30:00Z"
  62. },
  63. "unix": {
  64. "summary": "A custom Unix timestamp range",
  65. "value": "1674073869,1674193869"
  66. }
  67. }
  68. },
  69. {
  70. "name": "aggregate",
  71. "in": "query",
  72. "description": "Field by which to aggregate the results. Accepts: `cluster`, `node`, `namespace`, `controllerKind`, `controller`, `service`, `pod`, `container`, `label:<name>`, and `annotation:<name>`. Also accepts comma-separated lists for multi-aggregation, like `namespace,label:app`.",
  73. "required": false,
  74. "style": "form",
  75. "explode": true,
  76. "schema": {
  77. "type": "string"
  78. },
  79. "examples": {
  80. "cluster": {
  81. "summary": "Aggregates by the cluster.",
  82. "value": "cluster"
  83. },
  84. "node": {
  85. "summary": "Aggregates by the compute nodes in the cluster.",
  86. "value": "node"
  87. },
  88. "namespace": {
  89. "summary": "Aggregates by the namespaces in the cluster.",
  90. "value": "namespace"
  91. },
  92. "controllerKind": {
  93. "summary": "Aggregates by the kinds of controllers present in the cluster.",
  94. "value": "controllerKind"
  95. },
  96. "controller": {
  97. "summary": "Aggregates by the individual controllers within the cluster.",
  98. "value": "controller"
  99. },
  100. "service": {
  101. "summary": "Aggregates by the services within the cluster.",
  102. "value": "service"
  103. },
  104. "pod": {
  105. "summary": "Aggregates by the individual pods within the cluster",
  106. "value": "pod"
  107. },
  108. "container": {
  109. "summary": "Aggregates by the containers present in the cluster",
  110. "value": "container"
  111. }
  112. }
  113. },
  114. {
  115. "name": "step",
  116. "in": "query",
  117. "description": "Duration of a single allocation set. If unspecified, this defaults to the window, so that you receive exactly one set for the entire window. If specified, it works chronologically backward, querying in durations of step until the full window is covered. Default is `window`",
  118. "required": false,
  119. "style": "form",
  120. "explode": true,
  121. "schema": {
  122. "type": "string"
  123. },
  124. "examples": {
  125. "30m": {
  126. "summary": "30 minute steps over the duration of the window.",
  127. "value": "30m"
  128. },
  129. "2h": {
  130. "summary": "2 hour steps over the duration of the window",
  131. "value": "2h"
  132. },
  133. "1d": {
  134. "summary": "Daily steps over the duration of the window (ie. `lastweek` or `month`",
  135. "value": "1d"
  136. }
  137. }
  138. },
  139. {
  140. "name": "resolution",
  141. "in": "query",
  142. "description": "Duration to use as resolution in Prometheus queries. Smaller values (i.e. higher resolutions) will provide better accuracy, but worse performance (i.e. slower query time, higher memory use). Larger values (i.e. lower resolutions) will perform better, but at the expense of lower accuracy for short-running workloads. Default is `1m`",
  143. "required": false,
  144. "style": "form",
  145. "explode": true,
  146. "schema": {
  147. "type": "string"
  148. },
  149. "examples": {
  150. "1m": {
  151. "summary": "Highly accurate, slower query.",
  152. "value": "1m"
  153. },
  154. "30m": {
  155. "summary": "Less accurate, faster query. Not recommended for short-lived workloads.",
  156. "value": "30m"
  157. }
  158. }
  159. }
  160. ],
  161. "responses": {
  162. "200": {
  163. "description": "Success with `window` of `2d` and `aggregate` by `namespace`",
  164. "content": {
  165. "application/json": {
  166. "schema": {
  167. "$ref": "#/components/schemas/inline_response_200"
  168. },
  169. "examples": {
  170. "0": {
  171. "value": "{\"code\":200,\"status\":\"success\",\"data\":[{\"kube-system\":{\"name\":\"kube-system\",\"properties\":{\"cluster\":\"cluster-one\",\"namespace\":\"kube-system\"},\"window\":{\"start\":\"2023-01-18T11:38:45Z\",\"end\":\"2023-01-20T11:38:45Z\"},\"start\":\"2023-01-18T11:38:45Z\",\"end\":\"2023-01-20T11:38:00Z\",\"minutes\":2879.235705,\"cpuCores\":0.449881,\"cpuCoreRequestAverage\":0.449881,\"cpuCoreUsageAverage\":0.009417,\"cpuCoreHours\":21.588536,\"cpuCost\":0.408822,\"cpuCostAdjustment\":0.000000,\"cpuEfficiency\":0.020932,\"gpuCount\":0.000000,\"gpuHours\":0.000000,\"gpuCost\":0.000000,\"gpuCostAdjustment\":0.000000,\"networkTransferBytes\":0.000000,\"networkReceiveBytes\":0.000000,\"networkCost\":0.000000,\"networkCostAdjustment\":0.000000,\"loadBalancerCost\":0.000000,\"loadBalancerCostAdjustment\":0.000000,\"pvBytes\":0.000000,\"pvByteHours\":0.000000,\"pvCost\":0.000000,\"pvs\":null,\"pvCostAdjustment\":0.000000,\"ramBytes\":146761671.651553,\"ramByteRequestAverage\":146761671.651553,\"ramByteUsageAverage\":125495250.508328,\"ramByteHours\":7042690751.326794,\"ramCost\":0.016647,\"ramCostAdjustment\":0.000000,\"ramEfficiency\":0.855096,\"sharedCost\":0.000000,\"externalCost\":0.000000,\"totalCost\":0.425469,\"totalEfficiency\":0.053569,\"rawAllocationOnly\":null},\"opencost\":{\"name\":\"opencost\",\"properties\":{\"cluster\":\"cluster-one\",\"node\":\"ip-192-168-20-42.ap-southeast-2.compute.internal\",\"controller\":\"opencost\",\"controllerKind\":\"deployment\",\"namespace\":\"opencost\",\"pod\":\"opencost-75dc7dcc49-xdx5t\",\"providerID\":\"i-064548f89b9d35c11\"},\"window\":{\"start\":\"2023-01-18T11:38:45Z\",\"end\":\"2023-01-20T11:38:45Z\"},\"start\":\"2023-01-18T11:38:45Z\",\"end\":\"2023-01-20T11:38:00Z\",\"minutes\":2879.235705,\"cpuCores\":0.019995,\"cpuCoreRequestAverage\":0.019995,\"cpuCoreUsageAverage\":0.001821,\"cpuCoreHours\":0.959490,\"cpuCost\":0.018170,\"cpuCostAdjustment\":0.000000,\"cpuEfficiency\":0.091055,\"gpuCount\":0.000000,\"gpuHours\":0.000000,\"gpuCost\":0.000000,\"gpuCostAdjustment\":0.000000,\"networkTransferBytes\":0.000000,\"networkReceiveBytes\":0.000000,\"networkCost\":0.000000,\"networkCostAdjustment\":0.000000,\"loadBalancerCost\":0.000000,\"loadBalancerCostAdjustment\":0.000000,\"pvBytes\":0.000000,\"pvByteHours\":0.000000,\"pvCost\":0.000000,\"pvs\":null,\"pvCostAdjustment\":0.000000,\"ramBytes\":109970800.411162,\"ramByteRequestAverage\":109970800.411162,\"ramByteUsageAverage\":35525920.971352,\"ramByteHours\":5277197583.375299,\"ramCost\":0.012474,\"ramCostAdjustment\":0.000000,\"ramEfficiency\":0.323049,\"sharedCost\":0.000000,\"externalCost\":0.000000,\"totalCost\":0.030644,\"totalEfficiency\":0.185490,\"rawAllocationOnly\":null},\"prometheus\":{\"name\":\"prometheus\",\"properties\":{\"cluster\":\"cluster-one\",\"namespace\":\"prometheus\"},\"window\":{\"start\":\"2023-01-18T11:38:45Z\",\"end\":\"2023-01-20T11:38:45Z\"},\"start\":\"2023-01-18T11:38:45Z\",\"end\":\"2023-01-20T11:38:00Z\",\"minutes\":2879.235705,\"cpuCores\":0.000000,\"cpuCoreRequestAverage\":0.000000,\"cpuCoreUsageAverage\":0.007793,\"cpuCoreHours\":0.000000,\"cpuCost\":0.000000,\"cpuCostAdjustment\":0.000000,\"cpuEfficiency\":0.000000,\"gpuCount\":0.000000,\"gpuHours\":0.000000,\"gpuCost\":0.000000,\"gpuCostAdjustment\":0.000000,\"networkTransferBytes\":0.000000,\"networkReceiveBytes\":0.000000,\"networkCost\":0.000000,\"networkCostAdjustment\":0.000000,\"loadBalancerCost\":0.000000,\"loadBalancerCostAdjustment\":0.000000,\"pvBytes\":0.000000,\"pvByteHours\":0.000000,\"pvCost\":0.000000,\"pvs\":null,\"pvCostAdjustment\":0.000000,\"ramBytes\":0.000000,\"ramByteRequestAverage\":0.000000,\"ramByteUsageAverage\":287770105.329488,\"ramByteHours\":0.000000,\"ramCost\":0.000000,\"ramCostAdjustment\":0.000000,\"ramEfficiency\":0.000000,\"sharedCost\":0.000000,\"externalCost\":0.000000,\"totalCost\":0.000000,\"totalEfficiency\":0.000000,\"rawAllocationOnly\":null}}]}"
  172. }
  173. }
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. },
  181. "components": {
  182. "schemas": {
  183. "inline_response_200": {
  184. "type": "object",
  185. "properties": {
  186. "code": {
  187. "type": "integer"
  188. },
  189. "data": {
  190. "type": "array",
  191. "items": {
  192. "type": "object",
  193. "properties": {
  194. "opencost": {
  195. "type": "object",
  196. "properties": {
  197. "cpuCoreHours": {
  198. "type": "number"
  199. },
  200. "gpuCostAdjustment": {
  201. "type": "number"
  202. },
  203. "ramEfficiency": {
  204. "type": "number"
  205. },
  206. "loadBalancerCost": {
  207. "type": "number"
  208. },
  209. "gpuCost": {
  210. "type": "number"
  211. },
  212. "networkTransferBytes": {
  213. "type": "number"
  214. },
  215. "sharedCost": {
  216. "type": "number"
  217. },
  218. "pvCost": {
  219. "type": "number"
  220. },
  221. "totalEfficiency": {
  222. "type": "number"
  223. },
  224. "ramCostAdjustment": {
  225. "type": "number"
  226. },
  227. "pvByteHours": {
  228. "type": "number"
  229. },
  230. "networkCost": {
  231. "type": "number"
  232. },
  233. "ramByteUsageAverage": {
  234. "type": "number"
  235. },
  236. "end": {
  237. "type": "string"
  238. },
  239. "ramByteHours": {
  240. "type": "number"
  241. },
  242. "cpuCoreUsageAverage": {
  243. "type": "number"
  244. },
  245. "gpuCount": {
  246. "type": "number"
  247. },
  248. "cpuCostAdjustment": {
  249. "type": "number"
  250. },
  251. "externalCost": {
  252. "type": "number"
  253. },
  254. "minutes": {
  255. "type": "number"
  256. },
  257. "gpuHours": {
  258. "type": "number"
  259. },
  260. "loadBalancerCostAdjustment": {
  261. "type": "number"
  262. },
  263. "pvCostAdjustment": {
  264. "type": "number"
  265. },
  266. "ramCost": {
  267. "type": "number"
  268. },
  269. "start": {
  270. "type": "string"
  271. },
  272. "pvs": {},
  273. "cpuCost": {
  274. "type": "number"
  275. },
  276. "ramBytes": {
  277. "type": "number"
  278. },
  279. "networkCostAdjustment": {
  280. "type": "number"
  281. },
  282. "cpuCores": {
  283. "type": "number"
  284. },
  285. "pvBytes": {
  286. "type": "number"
  287. },
  288. "cpuEfficiency": {
  289. "type": "number"
  290. },
  291. "rawAllocationOnly": {},
  292. "name": {
  293. "type": "string"
  294. },
  295. "cpuCoreRequestAverage": {
  296. "type": "number"
  297. },
  298. "networkReceiveBytes": {
  299. "type": "number"
  300. },
  301. "window": {
  302. "type": "object",
  303. "properties": {
  304. "start": {
  305. "type": "string"
  306. },
  307. "end": {
  308. "type": "string"
  309. }
  310. }
  311. },
  312. "properties": {
  313. "type": "object",
  314. "properties": {
  315. "cluster": {
  316. "type": "string"
  317. },
  318. "node": {
  319. "type": "string"
  320. },
  321. "controller": {
  322. "type": "string"
  323. },
  324. "pod": {
  325. "type": "string"
  326. },
  327. "providerID": {
  328. "type": "string"
  329. },
  330. "namespace": {
  331. "type": "string"
  332. },
  333. "controllerKind": {
  334. "type": "string"
  335. }
  336. }
  337. },
  338. "totalCost": {
  339. "type": "number"
  340. },
  341. "ramByteRequestAverage": {
  342. "type": "number"
  343. }
  344. }
  345. },
  346. "kube-system": {
  347. "type": "object",
  348. "properties": {
  349. "cpuCoreHours": {
  350. "type": "number"
  351. },
  352. "gpuCostAdjustment": {
  353. "type": "number"
  354. },
  355. "ramEfficiency": {
  356. "type": "number"
  357. },
  358. "loadBalancerCost": {
  359. "type": "number"
  360. },
  361. "gpuCost": {
  362. "type": "number"
  363. },
  364. "networkTransferBytes": {
  365. "type": "number"
  366. },
  367. "sharedCost": {
  368. "type": "number"
  369. },
  370. "pvCost": {
  371. "type": "number"
  372. },
  373. "totalEfficiency": {
  374. "type": "number"
  375. },
  376. "ramCostAdjustment": {
  377. "type": "number"
  378. },
  379. "pvByteHours": {
  380. "type": "number"
  381. },
  382. "networkCost": {
  383. "type": "number"
  384. },
  385. "ramByteUsageAverage": {
  386. "type": "number"
  387. },
  388. "end": {
  389. "type": "string"
  390. },
  391. "ramByteHours": {
  392. "type": "number"
  393. },
  394. "cpuCoreUsageAverage": {
  395. "type": "number"
  396. },
  397. "gpuCount": {
  398. "type": "number"
  399. },
  400. "cpuCostAdjustment": {
  401. "type": "number"
  402. },
  403. "externalCost": {
  404. "type": "number"
  405. },
  406. "minutes": {
  407. "type": "number"
  408. },
  409. "gpuHours": {
  410. "type": "number"
  411. },
  412. "loadBalancerCostAdjustment": {
  413. "type": "number"
  414. },
  415. "pvCostAdjustment": {
  416. "type": "number"
  417. },
  418. "ramCost": {
  419. "type": "number"
  420. },
  421. "start": {
  422. "type": "string"
  423. },
  424. "pvs": {},
  425. "cpuCost": {
  426. "type": "number"
  427. },
  428. "ramBytes": {
  429. "type": "number"
  430. },
  431. "networkCostAdjustment": {
  432. "type": "number"
  433. },
  434. "cpuCores": {
  435. "type": "number"
  436. },
  437. "pvBytes": {
  438. "type": "number"
  439. },
  440. "cpuEfficiency": {
  441. "type": "number"
  442. },
  443. "rawAllocationOnly": {},
  444. "name": {
  445. "type": "string"
  446. },
  447. "cpuCoreRequestAverage": {
  448. "type": "number"
  449. },
  450. "networkReceiveBytes": {
  451. "type": "number"
  452. },
  453. "window": {
  454. "type": "object",
  455. "properties": {
  456. "start": {
  457. "type": "string"
  458. },
  459. "end": {
  460. "type": "string"
  461. }
  462. }
  463. },
  464. "properties": {
  465. "type": "object",
  466. "properties": {
  467. "cluster": {
  468. "type": "string"
  469. },
  470. "namespace": {
  471. "type": "string"
  472. }
  473. }
  474. },
  475. "totalCost": {
  476. "type": "number"
  477. },
  478. "ramByteRequestAverage": {
  479. "type": "number"
  480. }
  481. }
  482. },
  483. "prometheus": {
  484. "type": "object",
  485. "properties": {
  486. "cpuCoreHours": {
  487. "type": "number"
  488. },
  489. "gpuCostAdjustment": {
  490. "type": "number"
  491. },
  492. "ramEfficiency": {
  493. "type": "number"
  494. },
  495. "loadBalancerCost": {
  496. "type": "number"
  497. },
  498. "gpuCost": {
  499. "type": "number"
  500. },
  501. "networkTransferBytes": {
  502. "type": "number"
  503. },
  504. "sharedCost": {
  505. "type": "number"
  506. },
  507. "pvCost": {
  508. "type": "number"
  509. },
  510. "totalEfficiency": {
  511. "type": "number"
  512. },
  513. "ramCostAdjustment": {
  514. "type": "number"
  515. },
  516. "pvByteHours": {
  517. "type": "number"
  518. },
  519. "networkCost": {
  520. "type": "number"
  521. },
  522. "ramByteUsageAverage": {
  523. "type": "number"
  524. },
  525. "end": {
  526. "type": "string"
  527. },
  528. "ramByteHours": {
  529. "type": "number"
  530. },
  531. "cpuCoreUsageAverage": {
  532. "type": "number"
  533. },
  534. "gpuCount": {
  535. "type": "number"
  536. },
  537. "cpuCostAdjustment": {
  538. "type": "number"
  539. },
  540. "externalCost": {
  541. "type": "number"
  542. },
  543. "minutes": {
  544. "type": "number"
  545. },
  546. "gpuHours": {
  547. "type": "number"
  548. },
  549. "loadBalancerCostAdjustment": {
  550. "type": "number"
  551. },
  552. "pvCostAdjustment": {
  553. "type": "number"
  554. },
  555. "ramCost": {
  556. "type": "number"
  557. },
  558. "start": {
  559. "type": "string"
  560. },
  561. "pvs": {},
  562. "cpuCost": {
  563. "type": "number"
  564. },
  565. "ramBytes": {
  566. "type": "number"
  567. },
  568. "networkCostAdjustment": {
  569. "type": "number"
  570. },
  571. "cpuCores": {
  572. "type": "number"
  573. },
  574. "pvBytes": {
  575. "type": "number"
  576. },
  577. "cpuEfficiency": {
  578. "type": "number"
  579. },
  580. "rawAllocationOnly": {},
  581. "name": {
  582. "type": "string"
  583. },
  584. "cpuCoreRequestAverage": {
  585. "type": "number"
  586. },
  587. "networkReceiveBytes": {
  588. "type": "number"
  589. },
  590. "window": {
  591. "type": "object",
  592. "properties": {
  593. "start": {
  594. "type": "string"
  595. },
  596. "end": {
  597. "type": "string"
  598. }
  599. }
  600. },
  601. "properties": {
  602. "type": "object",
  603. "properties": {
  604. "cluster": {
  605. "type": "string"
  606. },
  607. "namespace": {
  608. "type": "string"
  609. }
  610. }
  611. },
  612. "totalCost": {
  613. "type": "number"
  614. },
  615. "ramByteRequestAverage": {
  616. "type": "number"
  617. }
  618. }
  619. }
  620. }
  621. }
  622. },
  623. "status": {
  624. "type": "string"
  625. }
  626. }
  627. }
  628. }
  629. }
  630. }