swagger.json 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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: `all`, `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`. Defaults to `cluster,node,namespace,pod,container`.",
  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. "all": {
  113. "summary": "Aggregates into a single allocation",
  114. "value": "all"
  115. }
  116. }
  117. },
  118. {
  119. "name": "step",
  120. "in": "query",
  121. "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`",
  122. "required": false,
  123. "style": "form",
  124. "explode": true,
  125. "schema": {
  126. "type": "string"
  127. },
  128. "examples": {
  129. "30m": {
  130. "summary": "30 minute steps over the duration of the window.",
  131. "value": "30m"
  132. },
  133. "2h": {
  134. "summary": "2 hour steps over the duration of the window",
  135. "value": "2h"
  136. },
  137. "1d": {
  138. "summary": "Daily steps over the duration of the window (ie. `lastweek` or `month`",
  139. "value": "1d"
  140. }
  141. }
  142. },
  143. {
  144. "name": "resolution",
  145. "in": "query",
  146. "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`",
  147. "required": false,
  148. "style": "form",
  149. "explode": true,
  150. "schema": {
  151. "type": "string"
  152. },
  153. "examples": {
  154. "1m": {
  155. "summary": "Highly accurate, slower query.",
  156. "value": "1m"
  157. },
  158. "30m": {
  159. "summary": "Less accurate, faster query. Not recommended for short-lived workloads.",
  160. "value": "30m"
  161. }
  162. }
  163. }
  164. ],
  165. "responses": {
  166. "200": {
  167. "description": "Success with `window` of `2d` and `aggregate` by `namespace`",
  168. "content": {
  169. "application/json": {
  170. "schema": {
  171. "$ref": "#/components/schemas/inline_response_200"
  172. },
  173. "examples": {
  174. "0": {
  175. "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}}]}"
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. },
  185. "components": {
  186. "schemas": {
  187. "inline_response_200": {
  188. "type": "object",
  189. "properties": {
  190. "code": {
  191. "type": "integer"
  192. },
  193. "data": {
  194. "type": "array",
  195. "items": {
  196. "type": "object",
  197. "properties": {
  198. "opencost": {
  199. "type": "object",
  200. "properties": {
  201. "cpuCoreHours": {
  202. "type": "number"
  203. },
  204. "gpuCostAdjustment": {
  205. "type": "number"
  206. },
  207. "ramEfficiency": {
  208. "type": "number"
  209. },
  210. "loadBalancerCost": {
  211. "type": "number"
  212. },
  213. "gpuCost": {
  214. "type": "number"
  215. },
  216. "networkTransferBytes": {
  217. "type": "number"
  218. },
  219. "sharedCost": {
  220. "type": "number"
  221. },
  222. "pvCost": {
  223. "type": "number"
  224. },
  225. "totalEfficiency": {
  226. "type": "number"
  227. },
  228. "ramCostAdjustment": {
  229. "type": "number"
  230. },
  231. "pvByteHours": {
  232. "type": "number"
  233. },
  234. "networkCost": {
  235. "type": "number"
  236. },
  237. "ramByteUsageAverage": {
  238. "type": "number"
  239. },
  240. "end": {
  241. "type": "string"
  242. },
  243. "ramByteHours": {
  244. "type": "number"
  245. },
  246. "cpuCoreUsageAverage": {
  247. "type": "number"
  248. },
  249. "gpuCount": {
  250. "type": "number"
  251. },
  252. "cpuCostAdjustment": {
  253. "type": "number"
  254. },
  255. "externalCost": {
  256. "type": "number"
  257. },
  258. "minutes": {
  259. "type": "number"
  260. },
  261. "gpuHours": {
  262. "type": "number"
  263. },
  264. "loadBalancerCostAdjustment": {
  265. "type": "number"
  266. },
  267. "pvCostAdjustment": {
  268. "type": "number"
  269. },
  270. "ramCost": {
  271. "type": "number"
  272. },
  273. "start": {
  274. "type": "string"
  275. },
  276. "pvs": {},
  277. "cpuCost": {
  278. "type": "number"
  279. },
  280. "ramBytes": {
  281. "type": "number"
  282. },
  283. "networkCostAdjustment": {
  284. "type": "number"
  285. },
  286. "cpuCores": {
  287. "type": "number"
  288. },
  289. "pvBytes": {
  290. "type": "number"
  291. },
  292. "cpuEfficiency": {
  293. "type": "number"
  294. },
  295. "rawAllocationOnly": {},
  296. "name": {
  297. "type": "string"
  298. },
  299. "cpuCoreRequestAverage": {
  300. "type": "number"
  301. },
  302. "networkReceiveBytes": {
  303. "type": "number"
  304. },
  305. "window": {
  306. "type": "object",
  307. "properties": {
  308. "start": {
  309. "type": "string"
  310. },
  311. "end": {
  312. "type": "string"
  313. }
  314. }
  315. },
  316. "properties": {
  317. "type": "object",
  318. "properties": {
  319. "cluster": {
  320. "type": "string"
  321. },
  322. "node": {
  323. "type": "string"
  324. },
  325. "controller": {
  326. "type": "string"
  327. },
  328. "pod": {
  329. "type": "string"
  330. },
  331. "providerID": {
  332. "type": "string"
  333. },
  334. "namespace": {
  335. "type": "string"
  336. },
  337. "controllerKind": {
  338. "type": "string"
  339. }
  340. }
  341. },
  342. "totalCost": {
  343. "type": "number"
  344. },
  345. "ramByteRequestAverage": {
  346. "type": "number"
  347. }
  348. }
  349. },
  350. "kube-system": {
  351. "type": "object",
  352. "properties": {
  353. "cpuCoreHours": {
  354. "type": "number"
  355. },
  356. "gpuCostAdjustment": {
  357. "type": "number"
  358. },
  359. "ramEfficiency": {
  360. "type": "number"
  361. },
  362. "loadBalancerCost": {
  363. "type": "number"
  364. },
  365. "gpuCost": {
  366. "type": "number"
  367. },
  368. "networkTransferBytes": {
  369. "type": "number"
  370. },
  371. "sharedCost": {
  372. "type": "number"
  373. },
  374. "pvCost": {
  375. "type": "number"
  376. },
  377. "totalEfficiency": {
  378. "type": "number"
  379. },
  380. "ramCostAdjustment": {
  381. "type": "number"
  382. },
  383. "pvByteHours": {
  384. "type": "number"
  385. },
  386. "networkCost": {
  387. "type": "number"
  388. },
  389. "ramByteUsageAverage": {
  390. "type": "number"
  391. },
  392. "end": {
  393. "type": "string"
  394. },
  395. "ramByteHours": {
  396. "type": "number"
  397. },
  398. "cpuCoreUsageAverage": {
  399. "type": "number"
  400. },
  401. "gpuCount": {
  402. "type": "number"
  403. },
  404. "cpuCostAdjustment": {
  405. "type": "number"
  406. },
  407. "externalCost": {
  408. "type": "number"
  409. },
  410. "minutes": {
  411. "type": "number"
  412. },
  413. "gpuHours": {
  414. "type": "number"
  415. },
  416. "loadBalancerCostAdjustment": {
  417. "type": "number"
  418. },
  419. "pvCostAdjustment": {
  420. "type": "number"
  421. },
  422. "ramCost": {
  423. "type": "number"
  424. },
  425. "start": {
  426. "type": "string"
  427. },
  428. "pvs": {},
  429. "cpuCost": {
  430. "type": "number"
  431. },
  432. "ramBytes": {
  433. "type": "number"
  434. },
  435. "networkCostAdjustment": {
  436. "type": "number"
  437. },
  438. "cpuCores": {
  439. "type": "number"
  440. },
  441. "pvBytes": {
  442. "type": "number"
  443. },
  444. "cpuEfficiency": {
  445. "type": "number"
  446. },
  447. "rawAllocationOnly": {},
  448. "name": {
  449. "type": "string"
  450. },
  451. "cpuCoreRequestAverage": {
  452. "type": "number"
  453. },
  454. "networkReceiveBytes": {
  455. "type": "number"
  456. },
  457. "window": {
  458. "type": "object",
  459. "properties": {
  460. "start": {
  461. "type": "string"
  462. },
  463. "end": {
  464. "type": "string"
  465. }
  466. }
  467. },
  468. "properties": {
  469. "type": "object",
  470. "properties": {
  471. "cluster": {
  472. "type": "string"
  473. },
  474. "namespace": {
  475. "type": "string"
  476. }
  477. }
  478. },
  479. "totalCost": {
  480. "type": "number"
  481. },
  482. "ramByteRequestAverage": {
  483. "type": "number"
  484. }
  485. }
  486. },
  487. "prometheus": {
  488. "type": "object",
  489. "properties": {
  490. "cpuCoreHours": {
  491. "type": "number"
  492. },
  493. "gpuCostAdjustment": {
  494. "type": "number"
  495. },
  496. "ramEfficiency": {
  497. "type": "number"
  498. },
  499. "loadBalancerCost": {
  500. "type": "number"
  501. },
  502. "gpuCost": {
  503. "type": "number"
  504. },
  505. "networkTransferBytes": {
  506. "type": "number"
  507. },
  508. "sharedCost": {
  509. "type": "number"
  510. },
  511. "pvCost": {
  512. "type": "number"
  513. },
  514. "totalEfficiency": {
  515. "type": "number"
  516. },
  517. "ramCostAdjustment": {
  518. "type": "number"
  519. },
  520. "pvByteHours": {
  521. "type": "number"
  522. },
  523. "networkCost": {
  524. "type": "number"
  525. },
  526. "ramByteUsageAverage": {
  527. "type": "number"
  528. },
  529. "end": {
  530. "type": "string"
  531. },
  532. "ramByteHours": {
  533. "type": "number"
  534. },
  535. "cpuCoreUsageAverage": {
  536. "type": "number"
  537. },
  538. "gpuCount": {
  539. "type": "number"
  540. },
  541. "cpuCostAdjustment": {
  542. "type": "number"
  543. },
  544. "externalCost": {
  545. "type": "number"
  546. },
  547. "minutes": {
  548. "type": "number"
  549. },
  550. "gpuHours": {
  551. "type": "number"
  552. },
  553. "loadBalancerCostAdjustment": {
  554. "type": "number"
  555. },
  556. "pvCostAdjustment": {
  557. "type": "number"
  558. },
  559. "ramCost": {
  560. "type": "number"
  561. },
  562. "start": {
  563. "type": "string"
  564. },
  565. "pvs": {},
  566. "cpuCost": {
  567. "type": "number"
  568. },
  569. "ramBytes": {
  570. "type": "number"
  571. },
  572. "networkCostAdjustment": {
  573. "type": "number"
  574. },
  575. "cpuCores": {
  576. "type": "number"
  577. },
  578. "pvBytes": {
  579. "type": "number"
  580. },
  581. "cpuEfficiency": {
  582. "type": "number"
  583. },
  584. "rawAllocationOnly": {},
  585. "name": {
  586. "type": "string"
  587. },
  588. "cpuCoreRequestAverage": {
  589. "type": "number"
  590. },
  591. "networkReceiveBytes": {
  592. "type": "number"
  593. },
  594. "window": {
  595. "type": "object",
  596. "properties": {
  597. "start": {
  598. "type": "string"
  599. },
  600. "end": {
  601. "type": "string"
  602. }
  603. }
  604. },
  605. "properties": {
  606. "type": "object",
  607. "properties": {
  608. "cluster": {
  609. "type": "string"
  610. },
  611. "namespace": {
  612. "type": "string"
  613. }
  614. }
  615. },
  616. "totalCost": {
  617. "type": "number"
  618. },
  619. "ramByteRequestAverage": {
  620. "type": "number"
  621. }
  622. }
  623. }
  624. }
  625. }
  626. },
  627. "status": {
  628. "type": "string"
  629. }
  630. }
  631. }
  632. }
  633. }
  634. }