collector.go 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467
  1. package collector
  2. import (
  3. "github.com/opencost/opencost/core/pkg/source"
  4. "github.com/opencost/opencost/modules/collector-source/pkg/metric"
  5. "github.com/opencost/opencost/modules/collector-source/pkg/metric/aggregator"
  6. )
  7. // NewOpenCostMetricStore creates a new MetricStore which has registered all MetricCollector instances required
  8. // for OpenCost
  9. func NewOpenCostMetricStore() metric.MetricStore {
  10. memStore := metric.NewInMemoryMetricStore()
  11. // Register all the metrics
  12. memStore.Register(NewPVPricePerGiBHourMetricCollector())
  13. memStore.Register(NewPVUsedAverageMetricCollector())
  14. memStore.Register(NewPVUsedMaxMetricCollector())
  15. memStore.Register(NewPVCInfoMetricCollector())
  16. memStore.Register(NewPVActiveMinutesMetricCollector())
  17. memStore.Register(NewLocalStorageUsedActiveMinutesMetricCollector())
  18. memStore.Register(NewLocalStorageUsedAverageMetricCollector())
  19. memStore.Register(NewLocalStorageUsedMaxMetricCollector())
  20. memStore.Register(NewLocalStorageBytesMetricCollector())
  21. memStore.Register(NewLocalStorageActiveMinutesMetricCollector())
  22. memStore.Register(NewNodeCPUCoresCapacityMetricCollector())
  23. memStore.Register(NewNodeCPUCoresAllocatableMetricCollector())
  24. memStore.Register(NewNodeRAMBytesCapacityMetricCollector())
  25. memStore.Register(NewNodeRAMBytesAllocatableMetricCollector())
  26. memStore.Register(NewNodeGPUCountMetricCollector())
  27. memStore.Register(NewNodeLabelsMetricCollector())
  28. memStore.Register(NewNodeActiveMinutesMetricCollector())
  29. memStore.Register(NewNodeCPUModeTotalMetricCollector())
  30. memStore.Register(NewNodeRAMSystemUsageAverageMetricCollector())
  31. memStore.Register(NewNodeRAMUserUsageAverageMetricCollector())
  32. memStore.Register(NewLBPricePerHourMetricCollector())
  33. memStore.Register(NewLBActiveMinutesMetricCollector())
  34. memStore.Register(NewClusterUptimeMetricCollector())
  35. memStore.Register(NewClusterManagementDurationMetricCollector())
  36. memStore.Register(NewClusterManagementPricePerHourMetricCollector())
  37. memStore.Register(NewPodActiveMinutesMetricCollector())
  38. memStore.Register(NewRAMBytesAllocatedMetricCollector())
  39. memStore.Register(NewRAMRequestsMetricCollector())
  40. memStore.Register(NewRAMLimitsMetricCollector())
  41. memStore.Register(NewRAMUsageAverageMetricCollector())
  42. memStore.Register(NewRAMUsageMaxMetricCollector())
  43. memStore.Register(NewCPUCoresAllocatedMetricCollector())
  44. memStore.Register(NewCPURequestsMetricCollector())
  45. memStore.Register(NewCPULimitsMetricCollector())
  46. memStore.Register(NewCPUUsageAverageMetricCollector())
  47. memStore.Register(NewCPUUsageMaxMetricCollector())
  48. memStore.Register(NewGPUsRequestedMetricCollector())
  49. memStore.Register(NewGPUsUsageAverageMetricCollector())
  50. memStore.Register(NewGPUsUsageMaxMetricCollector())
  51. memStore.Register(NewGPUsAllocatedMetricCollector())
  52. memStore.Register(NewIsGPUSharedMetricCollector())
  53. memStore.Register(NewGPUInfoMetricCollector())
  54. memStore.Register(NewNodeCPUPricePerHourMetricCollector())
  55. memStore.Register(NewNodeRAMPricePerGiBHourMetricCollector())
  56. memStore.Register(NewNodeGPUPricePerHourMetricCollector())
  57. memStore.Register(NewNodeIsSpotMetricCollector())
  58. memStore.Register(NewPodPVCAllocationMetricCollector())
  59. memStore.Register(NewPVCBytesRequestedMetricCollector())
  60. memStore.Register(NewPVBytesMetricCollector())
  61. memStore.Register(NewPVInfoMetricCollector())
  62. memStore.Register(NewNetZoneGiBMetricCollector())
  63. memStore.Register(NewNetZonePricePerGiBMetricCollector())
  64. memStore.Register(NewNetRegionGiBMetricCollector())
  65. memStore.Register(NewNetRegionPricePerGiBMetricCollector())
  66. memStore.Register(NewNetInternetGiBMetricCollector())
  67. memStore.Register(NewNetInternetPricePerGiBMetricCollector())
  68. memStore.Register(NewNetInternetServiceGiBMetricCollector())
  69. memStore.Register(NewNetNatGatewayGiBMetricCollector())
  70. memStore.Register(NewNetNatGatewayPricePerGiBMetricCollector())
  71. memStore.Register(NewNetReceiveBytesMetricCollector())
  72. memStore.Register(NewNetZoneIngressGiBMetricCollector())
  73. memStore.Register(NewNetRegionIngressGiBMetricCollector())
  74. memStore.Register(NewNetInternetIngressGiBMetricCollector())
  75. memStore.Register(NewNetInternetServiceIngressGiBMetricCollector())
  76. memStore.Register(NewNetNatGatewayIngressPricePerGiBMetricCollector())
  77. memStore.Register(NewNetNatGatewayIngressGiBMetricCollector())
  78. memStore.Register(NewNetTransferBytesMetricCollector())
  79. memStore.Register(NewNamespaceUptimeMetricCollector())
  80. memStore.Register(NewNamespaceLabelsMetricCollector())
  81. memStore.Register(NewNamespaceAnnotationsMetricCollector())
  82. memStore.Register(NewPodLabelsMetricCollector())
  83. memStore.Register(NewPodAnnotationsMetricCollector())
  84. memStore.Register(NewServiceLabelsMetricCollector())
  85. memStore.Register(NewDeploymentLabelsMetricCollector())
  86. memStore.Register(NewStatefulSetLabelsMetricCollector())
  87. memStore.Register(NewDaemonSetLabelsMetricCollector())
  88. memStore.Register(NewJobLabelsMetricCollector())
  89. memStore.Register(NewPodsWithReplicaSetOwnerMetricCollector())
  90. memStore.Register(NewReplicaSetsWithoutOwnersMetricCollector())
  91. memStore.Register(NewReplicaSetsWithRolloutMetricCollector())
  92. memStore.Register(NewResourceQuotaUptimeMetricCollector())
  93. memStore.Register(NewResourceQuotaSpecCPURequestAverageMetricCollector())
  94. memStore.Register(NewResourceQuotaSpecCPURequestMaxMetricCollector())
  95. memStore.Register(NewResourceQuotaSpecRAMRequestAverageMetricCollector())
  96. memStore.Register(NewResourceQuotaSpecRAMRequestMaxMetricCollector())
  97. memStore.Register(NewResourceQuotaSpecCPULimitAverageMetricCollector())
  98. memStore.Register(NewResourceQuotaSpecCPULimitMaxMetricCollector())
  99. memStore.Register(NewResourceQuotaSpecRAMLimitAverageMetricCollector())
  100. memStore.Register(NewResourceQuotaSpecRAMLimitMaxMetricCollector())
  101. memStore.Register(NewResourceQuotaStatusUsedCPURequestAverageMetricCollector())
  102. memStore.Register(NewResourceQuotaStatusUsedCPURequestMaxMetricCollector())
  103. memStore.Register(NewResourceQuotaStatusUsedRAMRequestAverageMetricCollector())
  104. memStore.Register(NewResourceQuotaStatusUsedRAMRequestMaxMetricCollector())
  105. memStore.Register(NewResourceQuotaStatusUsedCPULimitAverageMetricCollector())
  106. memStore.Register(NewResourceQuotaStatusUsedCPULimitMaxMetricCollector())
  107. memStore.Register(NewResourceQuotaStatusUsedRAMLimitAverageMetricCollector())
  108. memStore.Register(NewResourceQuotaStatusUsedRAMLimitMaxMetricCollector())
  109. return memStore
  110. }
  111. // avg(
  112. // avg_over_time(
  113. // pv_hourly_cost{
  114. // <some_custom_filter>
  115. // }[1h]
  116. // )
  117. // ) by (cluster_id, persistentvolume, volumename, provider_id)
  118. func NewPVPricePerGiBHourMetricCollector() *metric.MetricCollector {
  119. return metric.NewMetricCollector(
  120. metric.PVPricePerGiBHourID,
  121. metric.PVHourlyCost,
  122. []string{
  123. source.VolumeNameLabel,
  124. source.PVLabel,
  125. source.ProviderIDLabel,
  126. source.UIDLabel,
  127. },
  128. aggregator.AverageOverTime,
  129. nil,
  130. )
  131. }
  132. // avg(
  133. // avg_over_time(
  134. // kubelet_volume_stats_used_bytes{
  135. // <some_custom_filter>
  136. // }[1h]
  137. // )
  138. // ) by (cluster_id, persistentvolumeclaim, namespace)
  139. func NewPVUsedAverageMetricCollector() *metric.MetricCollector {
  140. return metric.NewMetricCollector(
  141. metric.PVUsedAverageID,
  142. metric.KubeletVolumeStatsUsedBytes,
  143. []string{
  144. source.NamespaceLabel,
  145. source.PVCLabel,
  146. source.UIDLabel,
  147. },
  148. aggregator.AverageOverTime,
  149. nil,
  150. )
  151. }
  152. // max(
  153. // max_over_time(
  154. // kubelet_volume_stats_used_bytes{
  155. // <some_custom_filter>
  156. // }[1h]
  157. // )
  158. // ) by (cluster_id, persistentvolumeclaim, namespace)
  159. func NewPVUsedMaxMetricCollector() *metric.MetricCollector {
  160. return metric.NewMetricCollector(
  161. metric.PVUsedMaxID,
  162. metric.KubeletVolumeStatsUsedBytes,
  163. []string{
  164. source.NamespaceLabel,
  165. source.PVCLabel,
  166. source.UIDLabel,
  167. },
  168. aggregator.MaxOverTime,
  169. nil,
  170. )
  171. }
  172. // avg(
  173. // kube_persistentvolumeclaim_info{
  174. // volumename != "",
  175. // <some_custom_filter>
  176. // }
  177. // ) by (persistentvolumeclaim, storageclass, volumename, namespace, cluster_id)[0:10m]
  178. func NewPVCInfoMetricCollector() *metric.MetricCollector {
  179. return metric.NewMetricCollector(
  180. metric.PVCInfoID,
  181. metric.KubePersistentVolumeClaimInfo,
  182. []string{
  183. source.NamespaceLabel,
  184. source.VolumeNameLabel,
  185. source.PVCLabel,
  186. source.StorageClassLabel,
  187. source.UIDLabel,
  188. },
  189. aggregator.Uptime,
  190. func(labels map[string]string) bool {
  191. return labels[source.VolumeNameLabel] != ""
  192. },
  193. )
  194. }
  195. // avg(
  196. // kube_persistentvolume_capacity_bytes{
  197. // <some_custom_filter>
  198. // }
  199. // ) by (cluster_id, persistentvolume)[0:10m]
  200. func NewPVActiveMinutesMetricCollector() *metric.MetricCollector {
  201. return metric.NewMetricCollector(
  202. metric.PVActiveMinutesID,
  203. metric.KubePersistentVolumeCapacityBytes,
  204. []string{
  205. source.PVLabel,
  206. source.UIDLabel,
  207. },
  208. aggregator.Uptime,
  209. nil,
  210. )
  211. }
  212. // sum_over_time(
  213. //
  214. // sum(
  215. // container_fs_usage_bytes{
  216. // device=~"/dev/(nvme|sda).*",
  217. // id="/",
  218. // <some_custom_filter>
  219. // }
  220. // ) by (instance, device, cluster_id)[%s:%dm]
  221. //
  222. // ) / 1024 / 1024 / 1024 * %f * %f`
  223. // NewLocalStorageUsedActiveMinutesMetricCollector does not have an associated query end point but is used in the results
  224. // of QueryLocalStorageUsedCost
  225. func NewLocalStorageUsedActiveMinutesMetricCollector() *metric.MetricCollector {
  226. return metric.NewMetricCollector(
  227. metric.LocalStorageUsedActiveMinutesID,
  228. metric.ContainerFSUsageBytes,
  229. []string{
  230. source.InstanceLabel,
  231. source.DeviceLabel,
  232. source.UIDLabel,
  233. },
  234. aggregator.Uptime,
  235. nil, // filter not required here because only container root file system is being scraped
  236. )
  237. }
  238. // avg(
  239. // sum(
  240. // avg_over_time(
  241. // container_fs_usage_bytes{
  242. // device=~"/dev/(nvme|sda).*",
  243. // id="/",
  244. // <some_custom_filter>
  245. // }[1h]
  246. // )
  247. // ) by (instance, device, cluster_id, job)
  248. // ) by (instance, device, cluster_id)
  249. func NewLocalStorageUsedAverageMetricCollector() *metric.MetricCollector {
  250. return metric.NewMetricCollector(
  251. metric.LocalStorageUsedAverageID,
  252. metric.ContainerFSUsageBytes,
  253. []string{
  254. source.InstanceLabel,
  255. source.DeviceLabel,
  256. source.UIDLabel,
  257. },
  258. aggregator.AverageOverTime,
  259. nil, // filter not required here because only container root file system is being scraped
  260. )
  261. }
  262. // max(
  263. //
  264. // sum(
  265. // max_over_time(
  266. // container_fs_usage_bytes{
  267. // device=~"/dev/(nvme|sda).*",
  268. // id="/",
  269. // <some_custom_filter>
  270. // }[1h]
  271. // )
  272. // ) by (instance, device, cluster_id, job)
  273. //
  274. // ) by (instance, device, cluster_id)
  275. func NewLocalStorageUsedMaxMetricCollector() *metric.MetricCollector {
  276. return metric.NewMetricCollector(
  277. metric.LocalStorageUsedMaxID,
  278. metric.ContainerFSUsageBytes,
  279. []string{
  280. source.InstanceLabel,
  281. source.DeviceLabel,
  282. source.UIDLabel,
  283. },
  284. aggregator.MaxOverTime,
  285. nil, // filter not required here because only container root file system is being scraped
  286. )
  287. }
  288. // avg_over_time(
  289. //
  290. // sum(
  291. // container_fs_limit_bytes{
  292. // device=~"/dev/(nvme|sda).*",
  293. // id="/",
  294. // <some_custom_filter>
  295. // }
  296. // ) by (instance, device, cluster_id)[%s:%dm]
  297. //
  298. // )
  299. func NewLocalStorageBytesMetricCollector() *metric.MetricCollector {
  300. return metric.NewMetricCollector(
  301. metric.LocalStorageBytesID,
  302. metric.NodeFSCapacityBytes,
  303. []string{
  304. source.InstanceLabel,
  305. source.DeviceLabel,
  306. source.UIDLabel,
  307. },
  308. aggregator.AverageOverTime,
  309. nil, // filter not required here because only node root file system is being scraped
  310. )
  311. }
  312. // count(
  313. //
  314. // kube_node_labels{
  315. // <some_custom_filter>
  316. // }
  317. //
  318. // ) by (cluster_id, node, instance, provider_id)[%s:%dm]
  319. func NewLocalStorageActiveMinutesMetricCollector() *metric.MetricCollector {
  320. return metric.NewMetricCollector(
  321. metric.LocalStorageActiveMinutesID,
  322. metric.KubeNodeLabels,
  323. []string{
  324. source.NodeLabel,
  325. source.ProviderIDLabel,
  326. source.UIDLabel,
  327. },
  328. aggregator.Uptime,
  329. nil,
  330. )
  331. }
  332. // avg(
  333. //
  334. // avg_over_time(
  335. // kube_node_status_capacity_cpu_cores{
  336. // <some_custom_filter>
  337. // }[1h]
  338. // )
  339. //
  340. // ) by (cluster_id, node)
  341. func NewNodeCPUCoresCapacityMetricCollector() *metric.MetricCollector {
  342. return metric.NewMetricCollector(
  343. metric.NodeCPUCoresCapacityID,
  344. metric.KubeNodeStatusCapacityCPUCores,
  345. []string{
  346. source.NodeLabel,
  347. source.UIDLabel,
  348. },
  349. aggregator.AverageOverTime,
  350. nil,
  351. )
  352. }
  353. // avg(
  354. // avg_over_time(
  355. // kube_node_status_allocatable_cpu_cores{
  356. // <some_custom_filter>
  357. // }[1h]
  358. // )
  359. // ) by (cluster_id, node)
  360. func NewNodeCPUCoresAllocatableMetricCollector() *metric.MetricCollector {
  361. return metric.NewMetricCollector(
  362. metric.NodeCPUCoresAllocatableID,
  363. metric.KubeNodeStatusAllocatableCPUCores,
  364. []string{
  365. source.NodeLabel,
  366. source.UIDLabel,
  367. },
  368. aggregator.AverageOverTime,
  369. nil,
  370. )
  371. }
  372. // avg(
  373. // avg_over_time(
  374. // kube_node_status_capacity_memory_bytes{
  375. // <some_custom_filter>
  376. // }[1h]
  377. // )
  378. // ) by (cluster_id, node)
  379. func NewNodeRAMBytesCapacityMetricCollector() *metric.MetricCollector {
  380. return metric.NewMetricCollector(
  381. metric.NodeRAMBytesCapacityID,
  382. metric.KubeNodeStatusCapacityMemoryBytes,
  383. []string{
  384. source.NodeLabel,
  385. source.UIDLabel,
  386. },
  387. aggregator.AverageOverTime,
  388. nil,
  389. )
  390. }
  391. // avg(
  392. // avg_over_time(
  393. // kube_node_status_allocatable_memory_bytes{
  394. // <some_custom_filter>
  395. // }[1h]
  396. // )
  397. // ) by (cluster_id, node)
  398. func NewNodeRAMBytesAllocatableMetricCollector() *metric.MetricCollector {
  399. return metric.NewMetricCollector(
  400. metric.NodeRAMBytesAllocatableID,
  401. metric.KubeNodeStatusAllocatableMemoryBytes,
  402. []string{
  403. source.NodeLabel,
  404. source.UIDLabel,
  405. },
  406. aggregator.AverageOverTime,
  407. nil,
  408. )
  409. }
  410. // avg(
  411. // avg_over_time(
  412. // node_gpu_count{
  413. // <some_custom_filter>
  414. // }[1h]
  415. // )
  416. // ) by (cluster_id, node, provider_id)
  417. func NewNodeGPUCountMetricCollector() *metric.MetricCollector {
  418. return metric.NewMetricCollector(
  419. metric.NodeGPUCountID,
  420. metric.NodeGPUCount,
  421. []string{
  422. source.NodeLabel,
  423. source.ProviderIDLabel,
  424. source.UIDLabel,
  425. },
  426. aggregator.AverageOverTime,
  427. nil,
  428. )
  429. }
  430. // avg_over_time(
  431. // kube_node_labels{
  432. // <some_custom_filter>
  433. // }[1h]
  434. // )
  435. func NewNodeLabelsMetricCollector() *metric.MetricCollector {
  436. return metric.NewMetricCollector(
  437. metric.NodeLabelsID,
  438. metric.KubeNodeLabels,
  439. []string{
  440. source.NodeLabel,
  441. source.UIDLabel,
  442. },
  443. aggregator.Info,
  444. nil,
  445. )
  446. }
  447. // avg(
  448. // kube_node_labels{
  449. // <some_custom_filter>
  450. // }
  451. // ) by (node, cluster_id, provider_id)[%s:%dm]
  452. func NewNodeActiveMinutesMetricCollector() *metric.MetricCollector {
  453. return metric.NewMetricCollector(
  454. metric.NodeActiveMinutesID,
  455. metric.KubeNodeLabels,
  456. []string{
  457. source.NodeLabel,
  458. source.ProviderIDLabel,
  459. source.UIDLabel,
  460. },
  461. aggregator.Uptime,
  462. nil,
  463. )
  464. }
  465. // sum(
  466. // rate(
  467. // node_cpu_seconds_total{
  468. // <some_custom_filter>
  469. // }[%s:%dm]
  470. // )
  471. // ) by (kubernetes_node, cluster_id, mode)
  472. func NewNodeCPUModeTotalMetricCollector() *metric.MetricCollector {
  473. return metric.NewMetricCollector(
  474. metric.NodeCPUModeTotalID,
  475. metric.NodeCPUSecondsTotal,
  476. []string{
  477. source.KubernetesNodeLabel,
  478. source.ModeLabel,
  479. source.UIDLabel,
  480. },
  481. aggregator.Rate,
  482. nil,
  483. )
  484. }
  485. // avg(
  486. // avg_over_time(
  487. // container_memory_working_set_bytes{
  488. // container_name!="POD",
  489. // container_name!="",
  490. // namespace="kube-system",
  491. // <some_custom_filter>
  492. // }[%s:%dm]
  493. // )
  494. // ) by (instance, cluster_id)
  495. func NewNodeRAMSystemUsageAverageMetricCollector() *metric.MetricCollector {
  496. return metric.NewMetricCollector(
  497. metric.NodeRAMSystemUsageAverageID,
  498. metric.ContainerMemoryWorkingSetBytes,
  499. []string{
  500. source.InstanceLabel,
  501. source.UIDLabel,
  502. },
  503. aggregator.AverageOverTime,
  504. func(labels map[string]string) bool {
  505. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NamespaceLabel] == "kube-system"
  506. },
  507. )
  508. }
  509. // avg(
  510. // avg_over_time(
  511. // container_memory_working_set_bytes{
  512. // container_name!="POD",
  513. // container_name!="",
  514. // namespace!="kube-system",
  515. // <some_custom_filter>
  516. // }[%s:%dm]
  517. // )
  518. // ) by (instance, cluster_id)
  519. func NewNodeRAMUserUsageAverageMetricCollector() *metric.MetricCollector {
  520. return metric.NewMetricCollector(
  521. metric.NodeRAMUserUsageAverageID,
  522. metric.ContainerMemoryWorkingSetBytes,
  523. []string{
  524. source.InstanceLabel,
  525. source.UIDLabel,
  526. },
  527. aggregator.AverageOverTime,
  528. func(labels map[string]string) bool {
  529. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NamespaceLabel] != "kube-system"
  530. },
  531. )
  532. }
  533. // avg(
  534. // avg_over_time(
  535. // kubecost_load_balancer_cost{
  536. // <some_custom_filter>
  537. // }[1h]
  538. // )
  539. // ) by (namespace, service_name, ingress_ip, cluster_id)
  540. func NewLBPricePerHourMetricCollector() *metric.MetricCollector {
  541. return metric.NewMetricCollector(
  542. metric.LBPricePerHourID,
  543. metric.KubecostLoadBalancerCost,
  544. []string{
  545. source.NamespaceLabel,
  546. source.ServiceNameLabel,
  547. source.IngressIPLabel,
  548. source.UIDLabel,
  549. },
  550. aggregator.AverageOverTime,
  551. nil,
  552. )
  553. }
  554. // avg(
  555. // kubecost_load_balancer_cost{
  556. // <some_custom_filter>
  557. // }
  558. // ) by (namespace, service_name, cluster_id, ingress_ip)[%s:%dm]
  559. func NewLBActiveMinutesMetricCollector() *metric.MetricCollector {
  560. return metric.NewMetricCollector(
  561. metric.LBActiveMinutesID,
  562. metric.KubecostLoadBalancerCost,
  563. []string{
  564. source.NamespaceLabel,
  565. source.ServiceNameLabel,
  566. source.IngressIPLabel,
  567. source.UIDLabel,
  568. },
  569. aggregator.Uptime,
  570. nil,
  571. )
  572. }
  573. // avg(
  574. // cluster_info{
  575. // <some_custom_filter>
  576. // }
  577. // ) by (uid)[%s:%dm]
  578. func NewClusterUptimeMetricCollector() *metric.MetricCollector {
  579. return metric.NewMetricCollector(
  580. metric.ClusterUptimeID,
  581. metric.ClusterInfo,
  582. []string{
  583. source.UIDLabel,
  584. },
  585. aggregator.Uptime,
  586. nil,
  587. )
  588. }
  589. // avg(
  590. // kubecost_cluster_management_cost{
  591. // <some_custom_filter>
  592. // }
  593. // ) by (cluster_id, provisioner_name)[%s:%dm]
  594. func NewClusterManagementDurationMetricCollector() *metric.MetricCollector {
  595. return metric.NewMetricCollector(
  596. metric.ClusterManagementDurationID,
  597. metric.KubecostClusterManagementCost,
  598. []string{
  599. source.ProvisionerNameLabel,
  600. source.UIDLabel,
  601. },
  602. aggregator.Uptime,
  603. nil,
  604. )
  605. }
  606. // avg(
  607. // avg_over_time(
  608. // kubecost_cluster_management_cost{
  609. // <some_custom_filter>
  610. // }[1h]
  611. // )
  612. // ) by (cluster_id, provisioner_name)
  613. func NewClusterManagementPricePerHourMetricCollector() *metric.MetricCollector {
  614. return metric.NewMetricCollector(
  615. metric.ClusterManagementPricePerHourID,
  616. metric.KubecostClusterManagementCost,
  617. []string{
  618. source.ProvisionerNameLabel,
  619. source.UIDLabel,
  620. },
  621. aggregator.AverageOverTime,
  622. nil,
  623. )
  624. }
  625. // avg(
  626. // kube_pod_container_status_running{
  627. // <some_custom_filter>
  628. // } != 0
  629. // ) by (pod, namespace, uid, cluster_id)[%s:%s]
  630. func NewPodActiveMinutesMetricCollector() *metric.MetricCollector {
  631. return metric.NewMetricCollector(
  632. metric.PodActiveMinutesID,
  633. metric.KubePodContainerStatusRunning,
  634. []string{
  635. source.UIDLabel,
  636. source.NamespaceLabel,
  637. source.PodLabel,
  638. },
  639. aggregator.Uptime,
  640. nil,
  641. )
  642. }
  643. // avg(
  644. // avg_over_time(
  645. // container_memory_allocation_bytes{
  646. // container!="",
  647. // container!="POD",
  648. // node!="",
  649. // <some_custom_filter>
  650. // }[1h]
  651. // )
  652. // ) by (container, pod, namespace, node, cluster_id, provider_id)
  653. func NewRAMBytesAllocatedMetricCollector() *metric.MetricCollector {
  654. return metric.NewMetricCollector(
  655. metric.RAMBytesAllocatedID,
  656. metric.ContainerMemoryAllocationBytes,
  657. []string{
  658. source.NodeLabel,
  659. source.InstanceLabel,
  660. source.NamespaceLabel,
  661. source.PodLabel,
  662. source.UIDLabel,
  663. source.ContainerLabel,
  664. },
  665. aggregator.AverageOverTime,
  666. func(labels map[string]string) bool {
  667. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  668. },
  669. )
  670. }
  671. // avg(
  672. // avg_over_time(
  673. // kube_pod_container_resource_requests{
  674. // resource="memory",
  675. // unit="byte",
  676. // container!="",
  677. // container!="POD",
  678. // node!="",
  679. // <some_custom_filter>
  680. // }[1h]
  681. // )
  682. //) by (container, pod, namespace, node, cluster_id)
  683. func NewRAMRequestsMetricCollector() *metric.MetricCollector {
  684. return metric.NewMetricCollector(
  685. metric.RAMRequestsID,
  686. metric.KubePodContainerResourceRequests,
  687. []string{
  688. source.NodeLabel,
  689. source.InstanceLabel,
  690. source.NamespaceLabel,
  691. source.PodLabel,
  692. source.UIDLabel,
  693. source.ContainerLabel,
  694. },
  695. aggregator.AverageOverTime,
  696. func(labels map[string]string) bool {
  697. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  698. },
  699. )
  700. }
  701. // avg(
  702. // avg_over_time(
  703. // kube_pod_container_resource_limits{
  704. // resource="memory",
  705. // unit="byte",
  706. // container!="",
  707. // container!="POD",
  708. // node!="",
  709. // <some_custom_filter>
  710. // }[1h]
  711. // )
  712. //) by (container, pod, namespace, node, cluster_id)
  713. func NewRAMLimitsMetricCollector() *metric.MetricCollector {
  714. return metric.NewMetricCollector(
  715. metric.RAMLimitsID,
  716. metric.KubePodContainerResourceLimits,
  717. []string{
  718. source.NodeLabel,
  719. source.InstanceLabel,
  720. source.NamespaceLabel,
  721. source.PodLabel,
  722. source.ContainerLabel,
  723. },
  724. aggregator.AverageOverTime,
  725. func(labels map[string]string) bool {
  726. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  727. },
  728. )
  729. }
  730. // avg(
  731. // avg_over_time(
  732. // container_memory_working_set_bytes{
  733. // container!="",
  734. // container!="POD",
  735. // <some_custom_filter>
  736. // }[1h]
  737. // )
  738. // ) by (container, pod, namespace, instance, cluster_id)
  739. func NewRAMUsageAverageMetricCollector() *metric.MetricCollector {
  740. return metric.NewMetricCollector(
  741. metric.RAMUsageAverageID,
  742. metric.ContainerMemoryWorkingSetBytes,
  743. []string{
  744. source.NodeLabel,
  745. source.InstanceLabel,
  746. source.NamespaceLabel,
  747. source.PodLabel,
  748. source.UIDLabel,
  749. source.ContainerLabel,
  750. },
  751. aggregator.AverageOverTime,
  752. func(labels map[string]string) bool {
  753. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != ""
  754. },
  755. )
  756. }
  757. // max(
  758. // max_over_time(
  759. // container_memory_working_set_bytes{
  760. // container!="",
  761. // container_name!="POD",
  762. // container!="POD",
  763. // <some_custom_filter>
  764. // }[%s]
  765. // )
  766. // ) by (container_name, container, pod_name, pod, namespace, node, instance, %s)
  767. func NewRAMUsageMaxMetricCollector() *metric.MetricCollector {
  768. return metric.NewMetricCollector(
  769. metric.RAMUsageMaxID,
  770. metric.ContainerMemoryWorkingSetBytes,
  771. []string{
  772. source.NodeLabel,
  773. source.InstanceLabel,
  774. source.NamespaceLabel,
  775. source.PodLabel,
  776. source.UIDLabel,
  777. source.ContainerLabel,
  778. },
  779. aggregator.MaxOverTime,
  780. func(labels map[string]string) bool {
  781. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD" && labels[source.NodeLabel] != ""
  782. },
  783. )
  784. }
  785. // avg(
  786. // avg_over_time(
  787. // container_cpu_allocation{
  788. // container!="",
  789. // container!="POD",
  790. // node!="",
  791. // <some_custom_filter>
  792. // }[1h]
  793. // )
  794. // ) by (container, pod, namespace, node, cluster_id)
  795. func NewCPUCoresAllocatedMetricCollector() *metric.MetricCollector {
  796. return metric.NewMetricCollector(
  797. metric.CPUCoresAllocatedID,
  798. metric.ContainerCPUAllocation,
  799. []string{
  800. source.NodeLabel,
  801. source.InstanceLabel,
  802. source.NamespaceLabel,
  803. source.PodLabel,
  804. source.UIDLabel,
  805. source.ContainerLabel,
  806. },
  807. aggregator.AverageOverTime,
  808. func(labels map[string]string) bool {
  809. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  810. },
  811. )
  812. }
  813. // avg(
  814. // avg_over_time(
  815. // kube_pod_container_resource_requests{
  816. // resource="cpu",
  817. // unit="core",
  818. // container!="",
  819. // container!="POD",
  820. // node!="",
  821. // <some_custom_filter>
  822. // }[1h]
  823. // )
  824. // ) by (container, pod, namespace, node, cluster_id)
  825. func NewCPURequestsMetricCollector() *metric.MetricCollector {
  826. return metric.NewMetricCollector(
  827. metric.CPURequestsID,
  828. metric.KubePodContainerResourceRequests,
  829. []string{
  830. source.NodeLabel,
  831. source.InstanceLabel,
  832. source.NamespaceLabel,
  833. source.PodLabel,
  834. source.UIDLabel,
  835. source.ContainerLabel,
  836. },
  837. aggregator.AverageOverTime,
  838. func(labels map[string]string) bool {
  839. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  840. },
  841. )
  842. }
  843. // avg(
  844. // avg_over_time(
  845. // kube_pod_container_resource_limits{
  846. // resource="cpu",
  847. // unit="core",
  848. // container!="",
  849. // container!="POD",
  850. // node!="",
  851. // <some_custom_filter>
  852. // }[1h]
  853. // )
  854. // ) by (container, pod, namespace, node, cluster_id)
  855. func NewCPULimitsMetricCollector() *metric.MetricCollector {
  856. return metric.NewMetricCollector(
  857. metric.CPULimitsID,
  858. metric.KubePodContainerResourceLimits,
  859. []string{
  860. source.NodeLabel,
  861. source.InstanceLabel,
  862. source.NamespaceLabel,
  863. source.PodLabel,
  864. source.ContainerLabel,
  865. },
  866. aggregator.AverageOverTime,
  867. func(labels map[string]string) bool {
  868. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  869. },
  870. )
  871. }
  872. // avg(
  873. // rate(
  874. // container_cpu_usage_seconds_total{
  875. // container!="",
  876. // container_name!="POD",
  877. // container!="POD",
  878. // <some_custom_filter>
  879. // }[1h]
  880. // )
  881. // ) by (container_name, container, pod_name, pod, namespace, node, instance, cluster_id)
  882. func NewCPUUsageAverageMetricCollector() *metric.MetricCollector {
  883. return metric.NewMetricCollector(
  884. metric.CPUUsageAverageID,
  885. metric.ContainerCPUUsageSecondsTotal,
  886. []string{
  887. source.NodeLabel,
  888. source.InstanceLabel,
  889. source.NamespaceLabel,
  890. source.PodLabel,
  891. source.UIDLabel,
  892. source.ContainerLabel,
  893. },
  894. aggregator.Rate,
  895. func(labels map[string]string) bool {
  896. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD"
  897. },
  898. )
  899. }
  900. // max(
  901. //
  902. // max_over_time(
  903. // irate(
  904. // container_cpu_usage_seconds_total{
  905. // container!="POD",
  906. // container!="",
  907. // <some_custom_filter>
  908. // }[1h]
  909. // )[%s:%s]
  910. // )
  911. //
  912. // ) by (container, pod_name, pod, namespace, node, instance, cluster_id)
  913. func NewCPUUsageMaxMetricCollector() *metric.MetricCollector {
  914. return metric.NewMetricCollector(
  915. metric.CPUUsageMaxID,
  916. metric.ContainerCPUUsageSecondsTotal,
  917. []string{
  918. source.NodeLabel,
  919. source.InstanceLabel,
  920. source.NamespaceLabel,
  921. source.PodLabel,
  922. source.UIDLabel,
  923. source.ContainerLabel,
  924. },
  925. aggregator.IRateMax,
  926. func(labels map[string]string) bool {
  927. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD"
  928. },
  929. )
  930. }
  931. // avg(
  932. // avg_over_time(
  933. // kube_pod_container_resource_requests{
  934. // resource="nvidia_com_gpu",
  935. // container!="",
  936. // container!="POD",
  937. // node!="",
  938. // <some_custom_filter>
  939. // }[1h]
  940. // )
  941. // ) by (container, pod, namespace, node, cluster_id)
  942. func NewGPUsRequestedMetricCollector() *metric.MetricCollector {
  943. return metric.NewMetricCollector(
  944. metric.GPUsRequestedID,
  945. metric.KubePodContainerResourceRequests,
  946. []string{
  947. source.NamespaceLabel,
  948. source.PodLabel,
  949. source.UIDLabel,
  950. source.ContainerLabel,
  951. },
  952. aggregator.AverageOverTime,
  953. func(labels map[string]string) bool {
  954. return labels[source.ResourceLabel] == "nvidia_com_gpu" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  955. },
  956. )
  957. }
  958. // avg(
  959. // avg_over_time(
  960. // DCGM_FI_PROF_GR_ENGINE_ACTIVE{
  961. // container!=""
  962. // }[1h]
  963. // )
  964. // ) by (container, pod, namespace, cluster_id)
  965. func NewGPUsUsageAverageMetricCollector() *metric.MetricCollector {
  966. return metric.NewMetricCollector(
  967. metric.GPUsUsageAverageID,
  968. metric.DCGMFIPROFGRENGINEACTIVE,
  969. []string{
  970. source.NamespaceLabel,
  971. source.PodLabel,
  972. source.UIDLabel,
  973. source.ContainerLabel,
  974. },
  975. aggregator.AverageOverTime,
  976. func(labels map[string]string) bool {
  977. return labels[source.ContainerLabel] != ""
  978. },
  979. )
  980. }
  981. // max(
  982. // max_over_time(
  983. // DCGM_FI_PROF_GR_ENGINE_ACTIVE{
  984. // container!=""
  985. // }[1h]
  986. // )
  987. // ) by (container, pod, namespace, cluster_id)
  988. func NewGPUsUsageMaxMetricCollector() *metric.MetricCollector {
  989. return metric.NewMetricCollector(
  990. metric.GPUsUsageMaxID,
  991. metric.DCGMFIPROFGRENGINEACTIVE,
  992. []string{
  993. source.NamespaceLabel,
  994. source.PodLabel,
  995. source.UIDLabel,
  996. source.ContainerLabel,
  997. },
  998. aggregator.MaxOverTime,
  999. func(labels map[string]string) bool {
  1000. return labels[source.ContainerLabel] != ""
  1001. },
  1002. )
  1003. }
  1004. // avg(
  1005. // avg_over_time(
  1006. // container_gpu_allocation{
  1007. // container!="",
  1008. // container!="POD",
  1009. // node!="",
  1010. // <some_custom_filter>
  1011. // }[1h]
  1012. // )
  1013. // ) by (container, pod, namespace, node, cluster_id)
  1014. func NewGPUsAllocatedMetricCollector() *metric.MetricCollector {
  1015. return metric.NewMetricCollector(
  1016. metric.GPUsAllocatedID,
  1017. metric.ContainerGPUAllocation,
  1018. []string{
  1019. source.NamespaceLabel,
  1020. source.PodLabel,
  1021. source.UIDLabel,
  1022. source.ContainerLabel,
  1023. },
  1024. aggregator.AverageOverTime,
  1025. func(labels map[string]string) bool {
  1026. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD" && labels[source.NodeLabel] != ""
  1027. },
  1028. )
  1029. }
  1030. // avg(
  1031. // avg_over_time(
  1032. // kube_pod_container_resource_requests{
  1033. // container!="",
  1034. // node != "",
  1035. // pod != "",
  1036. // container!= "",
  1037. // unit = "integer",
  1038. // <some_custom_filter>
  1039. // }[1h]
  1040. // )
  1041. // ) by (container, pod, namespace, node, resource, cluster_id)
  1042. func NewIsGPUSharedMetricCollector() *metric.MetricCollector {
  1043. return metric.NewMetricCollector(
  1044. metric.IsGPUSharedID,
  1045. metric.KubePodContainerResourceRequests,
  1046. []string{
  1047. source.NamespaceLabel,
  1048. source.PodLabel,
  1049. source.UIDLabel,
  1050. source.ContainerLabel,
  1051. source.ResourceLabel,
  1052. },
  1053. aggregator.AverageOverTime,
  1054. func(labels map[string]string) bool {
  1055. return labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != "" && labels[source.PodLabel] != "" && labels[source.UnitLabel] == "integer"
  1056. },
  1057. )
  1058. }
  1059. // avg(
  1060. // avg_over_time(
  1061. // DCGM_FI_DEV_DEC_UTIL{
  1062. // container!="",
  1063. // <some_custom_filter>
  1064. // }[1h]
  1065. // )
  1066. // ) by (container, pod, namespace, device, modelName, UUID, cluster_id)
  1067. func NewGPUInfoMetricCollector() *metric.MetricCollector {
  1068. return metric.NewMetricCollector(
  1069. metric.GPUInfoID,
  1070. metric.DCGMFIDEVDECUTIL,
  1071. []string{
  1072. source.NamespaceLabel,
  1073. source.PodLabel,
  1074. source.UIDLabel,
  1075. source.ContainerLabel,
  1076. source.DeviceLabel,
  1077. source.ModelNameLabel,
  1078. source.UUIDLabel,
  1079. },
  1080. aggregator.Info,
  1081. func(labels map[string]string) bool {
  1082. return labels[source.ContainerLabel] != ""
  1083. },
  1084. )
  1085. }
  1086. // avg(
  1087. // avg_over_time(
  1088. // node_cpu_hourly_cost{
  1089. // <some_custom_filter>
  1090. // }[1h]
  1091. // )
  1092. // ) by (node, cluster_id, instance_type, provider_id)
  1093. func NewNodeCPUPricePerHourMetricCollector() *metric.MetricCollector {
  1094. return metric.NewMetricCollector(
  1095. metric.NodeCPUPricePerHourID,
  1096. metric.NodeCPUHourlyCost,
  1097. []string{
  1098. source.NodeLabel,
  1099. source.InstanceTypeLabel,
  1100. source.ProviderIDLabel,
  1101. source.UIDLabel,
  1102. },
  1103. aggregator.AverageOverTime,
  1104. nil,
  1105. )
  1106. }
  1107. // avg(
  1108. // avg_over_time(
  1109. // node_ram_hourly_cost{
  1110. // <some_custom_filter>
  1111. // }[1h]
  1112. // )
  1113. // ) by (node, cluster_id, instance_type, provider_id)
  1114. func NewNodeRAMPricePerGiBHourMetricCollector() *metric.MetricCollector {
  1115. return metric.NewMetricCollector(
  1116. metric.NodeRAMPricePerGiBHourID,
  1117. metric.NodeRAMHourlyCost,
  1118. []string{
  1119. source.NodeLabel,
  1120. source.InstanceTypeLabel,
  1121. source.ProviderIDLabel,
  1122. source.UIDLabel,
  1123. },
  1124. aggregator.AverageOverTime,
  1125. nil,
  1126. )
  1127. }
  1128. // avg(
  1129. // avg_over_time(
  1130. // node_gpu_hourly_cost{
  1131. // <some_custom_filter>
  1132. // }[1h]
  1133. // )
  1134. // ) by (node, cluster_id, instance_type, provider_id)
  1135. func NewNodeGPUPricePerHourMetricCollector() *metric.MetricCollector {
  1136. return metric.NewMetricCollector(
  1137. metric.NodeGPUPricePerHourID,
  1138. metric.NodeGPUHourlyCost,
  1139. []string{
  1140. source.NodeLabel,
  1141. source.InstanceTypeLabel,
  1142. source.ProviderIDLabel,
  1143. source.UIDLabel,
  1144. },
  1145. aggregator.AverageOverTime,
  1146. nil,
  1147. )
  1148. }
  1149. // avg_over_time(
  1150. // kubecost_node_is_spot{
  1151. // <some_custom_filter>
  1152. // }[1h]
  1153. // )
  1154. func NewNodeIsSpotMetricCollector() *metric.MetricCollector {
  1155. return metric.NewMetricCollector(
  1156. metric.NodeIsSpotID,
  1157. metric.KubecostNodeIsSpot,
  1158. []string{
  1159. source.NodeLabel,
  1160. source.ProviderIDLabel,
  1161. source.UIDLabel,
  1162. },
  1163. aggregator.AverageOverTime,
  1164. nil,
  1165. )
  1166. }
  1167. // avg(
  1168. // avg_over_time(
  1169. // pod_pvc_allocation{
  1170. // <some_custom_filter>
  1171. // }[1h]
  1172. // )
  1173. // ) by (persistentvolume, persistentvolumeclaim, pod, namespace, cluster_id)
  1174. func NewPodPVCAllocationMetricCollector() *metric.MetricCollector {
  1175. return metric.NewMetricCollector(
  1176. metric.PodPVCAllocationID,
  1177. metric.PodPVCAllocation,
  1178. []string{
  1179. source.NamespaceLabel,
  1180. source.PodLabel,
  1181. source.UIDLabel,
  1182. source.PVLabel,
  1183. source.PVCLabel,
  1184. },
  1185. aggregator.AverageOverTime,
  1186. nil,
  1187. )
  1188. }
  1189. // avg(
  1190. // avg_over_time(
  1191. // kube_persistentvolumeclaim_resource_requests_storage_bytes{
  1192. // <some_custom_filter>
  1193. // }[1h]
  1194. // )
  1195. // ) by (persistentvolumeclaim, namespace, cluster_id)
  1196. func NewPVCBytesRequestedMetricCollector() *metric.MetricCollector {
  1197. return metric.NewMetricCollector(
  1198. metric.PVCBytesRequestedID,
  1199. metric.KubePersistentVolumeClaimResourceRequestsStorageBytes,
  1200. []string{
  1201. source.NamespaceLabel,
  1202. source.PVCLabel,
  1203. source.UIDLabel,
  1204. },
  1205. aggregator.AverageOverTime,
  1206. nil,
  1207. )
  1208. }
  1209. // avg(
  1210. // avg_over_time(
  1211. // kube_persistentvolume_capacity_bytes{
  1212. // <some_custom_filter>
  1213. // }[1h]
  1214. // )
  1215. // ) by (persistentvolume, cluster_id)
  1216. func NewPVBytesMetricCollector() *metric.MetricCollector {
  1217. return metric.NewMetricCollector(
  1218. metric.PVBytesID,
  1219. metric.KubePersistentVolumeCapacityBytes,
  1220. []string{
  1221. source.PVLabel,
  1222. source.UIDLabel,
  1223. },
  1224. aggregator.AverageOverTime,
  1225. nil,
  1226. )
  1227. }
  1228. // avg(
  1229. // avg_over_time(
  1230. // kubecost_pv_info{
  1231. // <some_custom_filter>
  1232. // }[1h]
  1233. // )
  1234. // ) by (cluster_id, storageclass, persistentvolume, provider_id)
  1235. func NewPVInfoMetricCollector() *metric.MetricCollector {
  1236. return metric.NewMetricCollector(
  1237. metric.PVInfoID,
  1238. metric.KubecostPVInfo,
  1239. []string{
  1240. source.PVLabel,
  1241. source.StorageClassLabel,
  1242. source.ProviderIDLabel,
  1243. source.UIDLabel,
  1244. },
  1245. aggregator.AverageOverTime,
  1246. nil,
  1247. )
  1248. }
  1249. // sum(
  1250. // increase(
  1251. // kubecost_pod_network_egress_bytes_total{
  1252. // internet="false",
  1253. // same_zone="false",
  1254. // same_region="true",
  1255. // <some_custom_filter>
  1256. // }[1h]
  1257. // )
  1258. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1259. //
  1260. func NewNetZoneGiBMetricCollector() *metric.MetricCollector {
  1261. return metric.NewMetricCollector(
  1262. metric.NetZoneGiBID,
  1263. metric.KubecostPodNetworkEgressBytesTotal,
  1264. []string{
  1265. source.NamespaceLabel,
  1266. source.PodNameLabel,
  1267. source.UIDLabel,
  1268. },
  1269. aggregator.Increase,
  1270. func(labels map[string]string) bool {
  1271. return labels[source.InternetLabel] == "false" && labels[source.SameZoneLabel] == "false" && labels[source.SameRegionLabel] == "true"
  1272. },
  1273. )
  1274. }
  1275. // avg(
  1276. // avg_over_time(
  1277. // kubecost_network_zone_egress_cost{
  1278. // <some_custom_filter>
  1279. // }[1h]
  1280. // )
  1281. // ) by (cluster_id)
  1282. //
  1283. func NewNetZonePricePerGiBMetricCollector() *metric.MetricCollector {
  1284. return metric.NewMetricCollector(
  1285. metric.NetZonePricePerGiBID,
  1286. metric.KubecostNetworkZoneEgressCost,
  1287. []string{},
  1288. aggregator.AverageOverTime,
  1289. nil,
  1290. )
  1291. }
  1292. // sum(
  1293. // increase(
  1294. // kubecost_pod_network_egress_bytes_total{
  1295. // internet="false",
  1296. // same_zone="false",
  1297. // same_region="false",
  1298. // <some_custom_filter>
  1299. // }[1h]
  1300. // )
  1301. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1302. func NewNetRegionGiBMetricCollector() *metric.MetricCollector {
  1303. return metric.NewMetricCollector(
  1304. metric.NetRegionGiBID,
  1305. metric.KubecostPodNetworkEgressBytesTotal,
  1306. []string{
  1307. source.NamespaceLabel,
  1308. source.PodNameLabel,
  1309. source.UIDLabel,
  1310. },
  1311. aggregator.Increase,
  1312. func(labels map[string]string) bool {
  1313. return labels[source.InternetLabel] == "false" && labels[source.SameZoneLabel] == "false" && labels[source.SameRegionLabel] == "false"
  1314. },
  1315. )
  1316. }
  1317. // avg(
  1318. // avg_over_time(
  1319. // kubecost_network_region_egress_cost{
  1320. // <some_custom_filter>
  1321. // }[1h]
  1322. // )
  1323. // ) by (cluster_id)
  1324. func NewNetRegionPricePerGiBMetricCollector() *metric.MetricCollector {
  1325. return metric.NewMetricCollector(
  1326. metric.NetRegionPricePerGiBID,
  1327. metric.KubecostNetworkRegionEgressCost,
  1328. []string{},
  1329. aggregator.AverageOverTime,
  1330. nil,
  1331. )
  1332. }
  1333. // sum(
  1334. // increase(
  1335. // kubecost_pod_network_egress_bytes_total{
  1336. // internet="true",
  1337. // <some_custom_filter>
  1338. // }[1h]
  1339. // )
  1340. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1341. func NewNetInternetGiBMetricCollector() *metric.MetricCollector {
  1342. return metric.NewMetricCollector(
  1343. metric.NetInternetGiBID,
  1344. metric.KubecostPodNetworkEgressBytesTotal,
  1345. []string{
  1346. source.NamespaceLabel,
  1347. source.PodNameLabel,
  1348. source.UIDLabel,
  1349. },
  1350. aggregator.Increase,
  1351. func(labels map[string]string) bool {
  1352. return labels[source.InternetLabel] == "true"
  1353. },
  1354. )
  1355. }
  1356. // avg(
  1357. // avg_over_time(
  1358. // kubecost_network_internet_egress_cost{
  1359. // <some_custom_filter>
  1360. // }[1h]
  1361. // )
  1362. // ) by (cluster_id)
  1363. func NewNetInternetPricePerGiBMetricCollector() *metric.MetricCollector {
  1364. return metric.NewMetricCollector(
  1365. metric.NetInternetPricePerGiBID,
  1366. metric.KubecostNetworkInternetEgressCost,
  1367. []string{},
  1368. aggregator.AverageOverTime,
  1369. nil,
  1370. )
  1371. }
  1372. // sum(
  1373. // increase(
  1374. // kubecost_pod_network_egress_bytes_total{
  1375. // internet="true",
  1376. // <some_custom_filter>
  1377. // }[%s]
  1378. // )
  1379. // ) by (pod_name, namespace, service, %s) / 1024 / 1024 / 1024
  1380. func NewNetInternetServiceGiBMetricCollector() *metric.MetricCollector {
  1381. return metric.NewMetricCollector(
  1382. metric.NetInternetServiceGiBID,
  1383. metric.KubecostPodNetworkEgressBytesTotal,
  1384. []string{
  1385. source.NamespaceLabel,
  1386. source.PodNameLabel,
  1387. source.ServiceLabel,
  1388. source.UIDLabel,
  1389. },
  1390. aggregator.Increase,
  1391. func(labels map[string]string) bool {
  1392. return labels[source.InternetLabel] == "true"
  1393. },
  1394. )
  1395. }
  1396. // sum(
  1397. // increase(
  1398. // kubecost_pod_network_egress_bytes_total{
  1399. // nat_gateway="true",
  1400. // <some_custom_filter>
  1401. // }[1h]
  1402. // )
  1403. // ) by (pod_name, namespace, uid, cluster_id) / 1024 / 1024 / 1024
  1404. func NewNetNatGatewayGiBMetricCollector() *metric.MetricCollector {
  1405. return metric.NewMetricCollector(
  1406. metric.NetNatGatewayGiBID,
  1407. metric.KubecostPodNetworkEgressBytesTotal,
  1408. []string{
  1409. source.NamespaceLabel,
  1410. source.PodNameLabel,
  1411. source.UIDLabel,
  1412. },
  1413. aggregator.Increase,
  1414. func(labels map[string]string) bool {
  1415. natLabel, labelExists := labels[source.NatGatewayLabel]
  1416. return labelExists && natLabel == "true"
  1417. },
  1418. )
  1419. }
  1420. // avg(
  1421. // avg_over_time(
  1422. // kubecost_network_nat_gateway_egress_cost{
  1423. // <some_custom_filter>
  1424. // }[1h]
  1425. // )
  1426. // ) by (cluster_id)
  1427. func NewNetNatGatewayPricePerGiBMetricCollector() *metric.MetricCollector {
  1428. return metric.NewMetricCollector(
  1429. metric.NetNatGatewayPricePerGiBID,
  1430. metric.KubecostNetworkNatGatewayEgressCost,
  1431. []string{},
  1432. aggregator.AverageOverTime,
  1433. nil,
  1434. )
  1435. }
  1436. // sum(
  1437. // increase(
  1438. // container_network_receive_bytes_total{
  1439. // pod!="",
  1440. // <some_custom_filter>
  1441. // }[1h]
  1442. // )
  1443. // ) by (pod_name, pod, namespace, cluster_id)
  1444. func NewNetReceiveBytesMetricCollector() *metric.MetricCollector {
  1445. return metric.NewMetricCollector(
  1446. metric.NetReceiveBytesID,
  1447. metric.ContainerNetworkReceiveBytesTotal,
  1448. []string{
  1449. source.NamespaceLabel,
  1450. source.PodLabel,
  1451. source.UIDLabel,
  1452. },
  1453. aggregator.Increase,
  1454. func(labels map[string]string) bool {
  1455. return labels[source.PodLabel] != ""
  1456. },
  1457. )
  1458. }
  1459. // sum(
  1460. // increase(
  1461. // kubecost_pod_network_ingress_bytes_total{
  1462. // internet="false",
  1463. // same_zone="false",
  1464. // same_region="true",
  1465. // <some_custom_filter>
  1466. // }[1h]
  1467. // )
  1468. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1469. func NewNetZoneIngressGiBMetricCollector() *metric.MetricCollector {
  1470. return metric.NewMetricCollector(
  1471. metric.NetZoneIngressGiBID,
  1472. metric.KubecostPodNetworkIngressBytesTotal,
  1473. []string{
  1474. source.NamespaceLabel,
  1475. source.PodNameLabel,
  1476. source.UIDLabel,
  1477. },
  1478. aggregator.Increase,
  1479. func(labels map[string]string) bool {
  1480. return labels[source.InternetLabel] == "false" &&
  1481. labels[source.SameZoneLabel] == "false" &&
  1482. labels[source.SameRegionLabel] == "true"
  1483. },
  1484. )
  1485. }
  1486. // sum(
  1487. // increase(
  1488. // kubecost_pod_network_ingress_bytes_total{
  1489. // internet="false",
  1490. // same_zone="false",
  1491. // same_region="false",
  1492. // <some_custom_filter>
  1493. // }[1h]
  1494. // )
  1495. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1496. func NewNetRegionIngressGiBMetricCollector() *metric.MetricCollector {
  1497. return metric.NewMetricCollector(
  1498. metric.NetRegionIngressGiBID,
  1499. metric.KubecostPodNetworkIngressBytesTotal,
  1500. []string{
  1501. source.NamespaceLabel,
  1502. source.PodNameLabel,
  1503. source.UIDLabel,
  1504. },
  1505. aggregator.Increase,
  1506. func(labels map[string]string) bool {
  1507. return labels[source.InternetLabel] == "false" &&
  1508. labels[source.SameZoneLabel] == "false" &&
  1509. labels[source.SameRegionLabel] == "false"
  1510. },
  1511. )
  1512. }
  1513. // sum(
  1514. // increase(
  1515. // kubecost_pod_network_ingress_bytes_total{
  1516. // internet="true",
  1517. // <some_custom_filter>
  1518. // }[1h]
  1519. // )
  1520. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1521. func NewNetInternetIngressGiBMetricCollector() *metric.MetricCollector {
  1522. return metric.NewMetricCollector(
  1523. metric.NetInternetIngressGiBID,
  1524. metric.KubecostPodNetworkIngressBytesTotal,
  1525. []string{
  1526. source.NamespaceLabel,
  1527. source.PodNameLabel,
  1528. source.UIDLabel,
  1529. },
  1530. aggregator.Increase,
  1531. func(labels map[string]string) bool {
  1532. return labels[source.InternetLabel] == "true"
  1533. },
  1534. )
  1535. }
  1536. // `sum(
  1537. // increase(
  1538. // kubecost_pod_network_ingress_bytes_total{
  1539. // internet="true",
  1540. // <some_custom_filter>
  1541. // }[1h]
  1542. // )
  1543. // ) by (pod_name, namespace, service, cluster_id) / 1024 / 1024 / 1024
  1544. func NewNetInternetServiceIngressGiBMetricCollector() *metric.MetricCollector {
  1545. return metric.NewMetricCollector(
  1546. metric.NetInternetServiceIngressGiBID,
  1547. metric.KubecostPodNetworkIngressBytesTotal,
  1548. []string{
  1549. source.NamespaceLabel,
  1550. source.PodNameLabel,
  1551. source.ServiceLabel,
  1552. source.UIDLabel,
  1553. },
  1554. aggregator.Increase,
  1555. func(labels map[string]string) bool {
  1556. return labels[source.InternetLabel] == "true"
  1557. },
  1558. )
  1559. }
  1560. // avg(
  1561. // avg_over_time(
  1562. // kubecost_network_nat_gateway_ingress_cost{
  1563. // <some_custom_filter>
  1564. // }[1h]
  1565. // )
  1566. // ) by (cluster_id)
  1567. func NewNetNatGatewayIngressPricePerGiBMetricCollector() *metric.MetricCollector {
  1568. return metric.NewMetricCollector(
  1569. metric.NetNatGatewayIngressPricePerGiBID,
  1570. metric.KubecostNetworkNatGatewayIngressCost,
  1571. []string{},
  1572. aggregator.AverageOverTime,
  1573. nil,
  1574. )
  1575. }
  1576. // sum(
  1577. // increase(
  1578. // kubecost_pod_network_ingress_bytes_total{
  1579. // nat_gateway="true",
  1580. // <some_custom_filter>
  1581. // }[1h]
  1582. // )
  1583. // ) by (pod_name, namespace, uid, cluster_id) / 1024 / 1024 / 1024
  1584. func NewNetNatGatewayIngressGiBMetricCollector() *metric.MetricCollector {
  1585. return metric.NewMetricCollector(
  1586. metric.NetNatGatewayIngressGiBID,
  1587. metric.KubecostPodNetworkIngressBytesTotal,
  1588. []string{
  1589. source.NamespaceLabel,
  1590. source.PodNameLabel,
  1591. source.UIDLabel,
  1592. },
  1593. aggregator.Increase,
  1594. func(labels map[string]string) bool {
  1595. natLabel, labelExists := labels[source.NatGatewayLabel]
  1596. return labelExists && natLabel == "true"
  1597. },
  1598. )
  1599. }
  1600. // sum(
  1601. // increase(
  1602. // container_network_transmit_bytes_total{
  1603. // pod!="",
  1604. // <some_custom_filter>
  1605. // }[1h]
  1606. // )
  1607. // ) by (pod_name, pod, namespace, cluster_id)
  1608. func NewNetTransferBytesMetricCollector() *metric.MetricCollector {
  1609. return metric.NewMetricCollector(
  1610. metric.NetTransferBytesID,
  1611. metric.ContainerNetworkTransmitBytesTotal,
  1612. []string{
  1613. source.NamespaceLabel,
  1614. source.PodLabel,
  1615. source.UIDLabel,
  1616. },
  1617. aggregator.Increase,
  1618. func(labels map[string]string) bool {
  1619. return labels[source.PodLabel] != ""
  1620. },
  1621. )
  1622. }
  1623. // avg(
  1624. // namespace_info{
  1625. // <some_custom_filter>
  1626. // }
  1627. // ) by (uid)[%s:%dm]
  1628. func NewNamespaceUptimeMetricCollector() *metric.MetricCollector {
  1629. return metric.NewMetricCollector(
  1630. metric.NamespaceUptimeID,
  1631. metric.NamespaceInfo,
  1632. []string{
  1633. source.UIDLabel,
  1634. },
  1635. aggregator.Uptime,
  1636. nil,
  1637. )
  1638. }
  1639. // avg_over_time(
  1640. // kube_namespace_labels{
  1641. // <some_custom_filter>
  1642. // }[1h]
  1643. // )
  1644. func NewNamespaceLabelsMetricCollector() *metric.MetricCollector {
  1645. return metric.NewMetricCollector(
  1646. metric.NamespaceLabelsID,
  1647. metric.KubeNamespaceLabels,
  1648. []string{
  1649. source.NamespaceLabel,
  1650. source.UIDLabel,
  1651. },
  1652. aggregator.Info,
  1653. nil,
  1654. )
  1655. }
  1656. // avg_over_time(
  1657. // kube_namespace_annotations{
  1658. // <some_custom_filter>
  1659. // }[1h]
  1660. // )
  1661. func NewNamespaceAnnotationsMetricCollector() *metric.MetricCollector {
  1662. return metric.NewMetricCollector(
  1663. metric.NamespaceAnnotationsID,
  1664. metric.KubeNamespaceAnnotations,
  1665. []string{
  1666. source.NamespaceLabel,
  1667. source.UIDLabel,
  1668. },
  1669. aggregator.Info,
  1670. nil,
  1671. )
  1672. }
  1673. // avg_over_time(
  1674. // kube_pod_labels{
  1675. // <some_custom_filter>
  1676. // }[1h]
  1677. // )
  1678. func NewPodLabelsMetricCollector() *metric.MetricCollector {
  1679. return metric.NewMetricCollector(
  1680. metric.PodLabelsID,
  1681. metric.KubePodLabels,
  1682. []string{
  1683. source.NamespaceLabel,
  1684. source.PodLabel,
  1685. source.UIDLabel,
  1686. },
  1687. aggregator.Info,
  1688. nil,
  1689. )
  1690. }
  1691. // avg_over_time(
  1692. // kube_pod_annotations{
  1693. // <some_custom_filter>
  1694. // }[1h]
  1695. // )
  1696. func NewPodAnnotationsMetricCollector() *metric.MetricCollector {
  1697. return metric.NewMetricCollector(
  1698. metric.PodAnnotationsID,
  1699. metric.KubePodAnnotations,
  1700. []string{
  1701. source.NamespaceLabel,
  1702. source.PodLabel,
  1703. source.UIDLabel,
  1704. },
  1705. aggregator.Info,
  1706. nil,
  1707. )
  1708. }
  1709. // avg_over_time(
  1710. // service_selector_labels{
  1711. // <some_custom_filter>
  1712. // }[1h]
  1713. // )
  1714. func NewServiceLabelsMetricCollector() *metric.MetricCollector {
  1715. return metric.NewMetricCollector(
  1716. metric.ServiceLabelsID,
  1717. metric.ServiceSelectorLabels,
  1718. []string{
  1719. source.NamespaceLabel,
  1720. source.ServiceLabel,
  1721. source.UIDLabel,
  1722. },
  1723. aggregator.Info,
  1724. nil,
  1725. )
  1726. }
  1727. // avg_over_time(
  1728. // deployment_match_labels{
  1729. // <some_custom_filter>
  1730. // }[1h]
  1731. // )
  1732. func NewDeploymentLabelsMetricCollector() *metric.MetricCollector {
  1733. return metric.NewMetricCollector(
  1734. metric.DeploymentLabelsID,
  1735. metric.DeploymentMatchLabels,
  1736. []string{
  1737. source.NamespaceLabel,
  1738. source.DeploymentLabel,
  1739. source.UIDLabel,
  1740. },
  1741. aggregator.Info,
  1742. nil,
  1743. )
  1744. }
  1745. // avg_over_time(
  1746. // statefulSet_match_labels{
  1747. // <some_custom_filter>
  1748. // }[1h]
  1749. // )
  1750. func NewStatefulSetLabelsMetricCollector() *metric.MetricCollector {
  1751. return metric.NewMetricCollector(
  1752. metric.StatefulSetLabelsID,
  1753. metric.StatefulSetMatchLabels,
  1754. []string{
  1755. source.NamespaceLabel,
  1756. source.StatefulSetLabel,
  1757. source.UIDLabel,
  1758. },
  1759. aggregator.Info,
  1760. nil,
  1761. )
  1762. }
  1763. // sum(
  1764. // avg_over_time(
  1765. // kube_pod_owner{
  1766. // owner_kind="DaemonSet",
  1767. // <some_custom_filter>
  1768. // }[1h]
  1769. // )
  1770. // ) by (pod, owner_name, namespace, cluster_id)
  1771. func NewDaemonSetLabelsMetricCollector() *metric.MetricCollector {
  1772. return metric.NewMetricCollector(
  1773. metric.DaemonSetLabelsID,
  1774. metric.KubePodOwner,
  1775. []string{
  1776. source.NamespaceLabel,
  1777. source.PodLabel,
  1778. source.UIDLabel,
  1779. source.OwnerNameLabel,
  1780. },
  1781. aggregator.Info,
  1782. func(labels map[string]string) bool {
  1783. return labels[source.OwnerKindLabel] == "DaemonSet"
  1784. },
  1785. )
  1786. }
  1787. // sum(
  1788. // avg_over_time(
  1789. // kube_pod_owner{
  1790. // owner_kind="Job",
  1791. // <some_custom_filter>
  1792. // }[1h]
  1793. // )
  1794. // ) by (pod, owner_name, namespace, cluster_id)
  1795. func NewJobLabelsMetricCollector() *metric.MetricCollector {
  1796. return metric.NewMetricCollector(
  1797. metric.JobLabelsID,
  1798. metric.KubePodOwner,
  1799. []string{
  1800. source.NamespaceLabel,
  1801. source.PodLabel,
  1802. source.UIDLabel,
  1803. source.OwnerNameLabel,
  1804. },
  1805. aggregator.Info,
  1806. func(labels map[string]string) bool {
  1807. return labels[source.OwnerKindLabel] == "Job"
  1808. },
  1809. )
  1810. }
  1811. // sum(
  1812. // avg_over_time(
  1813. // kube_pod_owner{
  1814. // owner_kind="ReplicaSet",
  1815. // <some_custom_filter>
  1816. // }[1h]
  1817. // )
  1818. // ) by (pod, owner_name, namespace, cluster_id)
  1819. func NewPodsWithReplicaSetOwnerMetricCollector() *metric.MetricCollector {
  1820. return metric.NewMetricCollector(
  1821. metric.PodsWithReplicaSetOwnerID,
  1822. metric.KubePodOwner,
  1823. []string{
  1824. source.NamespaceLabel,
  1825. source.PodLabel,
  1826. source.UIDLabel,
  1827. source.OwnerNameLabel,
  1828. },
  1829. aggregator.Info,
  1830. func(labels map[string]string) bool {
  1831. return labels[source.OwnerKindLabel] == "ReplicaSet"
  1832. },
  1833. )
  1834. }
  1835. // sum(
  1836. // avg_over_time(
  1837. // kube_replicaset_owner{
  1838. // owner_kind="<none>",
  1839. // owner_name="<none>",
  1840. // <some_custom_filter>
  1841. // }[1h]
  1842. // )
  1843. // ) by (replicaset, namespace, cluster_id)
  1844. func NewReplicaSetsWithoutOwnersMetricCollector() *metric.MetricCollector {
  1845. return metric.NewMetricCollector(
  1846. metric.ReplicaSetsWithoutOwnersID,
  1847. metric.KubeReplicasetOwner,
  1848. []string{
  1849. source.NamespaceLabel,
  1850. source.ReplicaSetLabel,
  1851. source.UIDLabel,
  1852. },
  1853. aggregator.Info,
  1854. func(labels map[string]string) bool {
  1855. return labels[source.OwnerKindLabel] == "<none>" && labels[source.OwnerNameLabel] == "<none>"
  1856. },
  1857. )
  1858. }
  1859. // sum(
  1860. // avg_over_time(
  1861. // kube_replicaset_owner{
  1862. // owner_kind="Rollout",
  1863. // <some_custom_filter>
  1864. // }[1h]
  1865. // )
  1866. // ) by (replicaset, namespace, owner_kind, owner_name, cluster_id)
  1867. func NewReplicaSetsWithRolloutMetricCollector() *metric.MetricCollector {
  1868. return metric.NewMetricCollector(
  1869. metric.ReplicaSetsWithRolloutID,
  1870. metric.KubeReplicasetOwner,
  1871. []string{
  1872. source.NamespaceLabel,
  1873. source.ReplicaSetLabel,
  1874. source.UIDLabel,
  1875. source.OwnerNameLabel,
  1876. source.OwnerKindLabel,
  1877. },
  1878. aggregator.Info,
  1879. func(labels map[string]string) bool {
  1880. return labels[source.OwnerKindLabel] == "Rollout"
  1881. },
  1882. )
  1883. }
  1884. // avg(
  1885. // resourcequota_info{
  1886. // <some_custom_filter>
  1887. // }
  1888. // ) by (uid)[%s:%dm]
  1889. func NewResourceQuotaUptimeMetricCollector() *metric.MetricCollector {
  1890. return metric.NewMetricCollector(
  1891. metric.ResourceQuotaUptimeID,
  1892. metric.ResourceQuotaInfo,
  1893. []string{
  1894. source.UIDLabel,
  1895. },
  1896. aggregator.Uptime,
  1897. nil,
  1898. )
  1899. }
  1900. func NewResourceQuotaSpecCPURequestAverageMetricCollector() *metric.MetricCollector {
  1901. return metric.NewMetricCollector(
  1902. metric.ResourceQuotaSpecCPURequestAverageID,
  1903. metric.KubeResourceQuotaSpecResourceRequests,
  1904. []string{
  1905. source.NamespaceLabel,
  1906. source.ResourceQuotaLabel,
  1907. source.UIDLabel,
  1908. },
  1909. aggregator.AverageOverTime,
  1910. func(labels map[string]string) bool {
  1911. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  1912. },
  1913. )
  1914. }
  1915. // max(
  1916. // max_over_time(
  1917. // resourcequota_spec_resource_requests{
  1918. // resource="cpu",
  1919. // unit="core",
  1920. // <some_custom_filter>
  1921. // }[1h]
  1922. // )
  1923. //) by (resourcequota, namespace, uid, cluster_id)
  1924. func NewResourceQuotaSpecCPURequestMaxMetricCollector() *metric.MetricCollector {
  1925. return metric.NewMetricCollector(
  1926. metric.ResourceQuotaSpecCPURequestMaxID,
  1927. metric.KubeResourceQuotaSpecResourceRequests,
  1928. []string{
  1929. source.NamespaceLabel,
  1930. source.ResourceQuotaLabel,
  1931. source.UIDLabel,
  1932. },
  1933. aggregator.MaxOverTime,
  1934. func(labels map[string]string) bool {
  1935. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  1936. },
  1937. )
  1938. }
  1939. // avg(
  1940. // avg_over_time(
  1941. // resourcequota_spec_resource_requests{
  1942. // resource="memory",
  1943. // unit="byte",
  1944. // <some_custom_filter>
  1945. // }[1h]
  1946. // )
  1947. //) by (resourcequota, namespace, uid, cluster_id)
  1948. func NewResourceQuotaSpecRAMRequestAverageMetricCollector() *metric.MetricCollector {
  1949. return metric.NewMetricCollector(
  1950. metric.ResourceQuotaSpecRAMRequestAverageID,
  1951. metric.KubeResourceQuotaSpecResourceRequests,
  1952. []string{
  1953. source.NamespaceLabel,
  1954. source.ResourceQuotaLabel,
  1955. source.UIDLabel,
  1956. },
  1957. aggregator.AverageOverTime,
  1958. func(labels map[string]string) bool {
  1959. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  1960. },
  1961. )
  1962. }
  1963. // max(
  1964. // max_over_time(
  1965. // resourcequota_spec_resource_requests{
  1966. // resource="memory",
  1967. // unit="byte",
  1968. // <some_custom_filter>
  1969. // }[1h]
  1970. // )
  1971. //) by (resourcequota, namespace, uid, cluster_id)
  1972. func NewResourceQuotaSpecRAMRequestMaxMetricCollector() *metric.MetricCollector {
  1973. return metric.NewMetricCollector(
  1974. metric.ResourceQuotaSpecRAMRequestMaxID,
  1975. metric.KubeResourceQuotaSpecResourceRequests,
  1976. []string{
  1977. source.NamespaceLabel,
  1978. source.ResourceQuotaLabel,
  1979. source.UIDLabel,
  1980. },
  1981. aggregator.MaxOverTime,
  1982. func(labels map[string]string) bool {
  1983. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  1984. },
  1985. )
  1986. }
  1987. // avg(
  1988. // avg_over_time(
  1989. // resourcequota_spec_resource_limits{
  1990. // resource="cpu",
  1991. // unit="core",
  1992. // <some_custom_filter>
  1993. // }[1h]
  1994. // )
  1995. //) by (resourcequota, namespace, uid, cluster_id)
  1996. func NewResourceQuotaSpecCPULimitAverageMetricCollector() *metric.MetricCollector {
  1997. return metric.NewMetricCollector(
  1998. metric.ResourceQuotaSpecCPULimitAverageID,
  1999. metric.KubeResourceQuotaSpecResourceLimits,
  2000. []string{
  2001. source.NamespaceLabel,
  2002. source.ResourceQuotaLabel,
  2003. source.UIDLabel,
  2004. },
  2005. aggregator.AverageOverTime,
  2006. func(labels map[string]string) bool {
  2007. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2008. },
  2009. )
  2010. }
  2011. // max(
  2012. // max_over_time(
  2013. // resourcequota_spec_resource_limits{
  2014. // resource="cpu",
  2015. // unit="core",
  2016. // <some_custom_filter>
  2017. // }[1h]
  2018. // )
  2019. //) by (resourcequota, namespace, uid, cluster_id)
  2020. func NewResourceQuotaSpecCPULimitMaxMetricCollector() *metric.MetricCollector {
  2021. return metric.NewMetricCollector(
  2022. metric.ResourceQuotaSpecCPULimitMaxID,
  2023. metric.KubeResourceQuotaSpecResourceLimits,
  2024. []string{
  2025. source.NamespaceLabel,
  2026. source.ResourceQuotaLabel,
  2027. source.UIDLabel,
  2028. },
  2029. aggregator.MaxOverTime,
  2030. func(labels map[string]string) bool {
  2031. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2032. },
  2033. )
  2034. }
  2035. // avg(
  2036. // avg_over_time(
  2037. // resourcequota_spec_resource_limits{
  2038. // resource="memory",
  2039. // unit="byte",
  2040. // <some_custom_filter>
  2041. // }[1h]
  2042. // )
  2043. //) by (resourcequota, namespace, uid, cluster_id)
  2044. func NewResourceQuotaSpecRAMLimitAverageMetricCollector() *metric.MetricCollector {
  2045. return metric.NewMetricCollector(
  2046. metric.ResourceQuotaSpecRAMLimitAverageID,
  2047. metric.KubeResourceQuotaSpecResourceLimits,
  2048. []string{
  2049. source.NamespaceLabel,
  2050. source.ResourceQuotaLabel,
  2051. source.UIDLabel,
  2052. },
  2053. aggregator.AverageOverTime,
  2054. func(labels map[string]string) bool {
  2055. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2056. },
  2057. )
  2058. }
  2059. // max(
  2060. // max_over_time(
  2061. // resourcequota_spec_resource_limits{
  2062. // resource="memory",
  2063. // unit="byte",
  2064. // <some_custom_filter>
  2065. // }[1h]
  2066. // )
  2067. //) by (resourcequota, namespace, uid, cluster_id)
  2068. func NewResourceQuotaSpecRAMLimitMaxMetricCollector() *metric.MetricCollector {
  2069. return metric.NewMetricCollector(
  2070. metric.ResourceQuotaSpecRAMLimitMaxID,
  2071. metric.KubeResourceQuotaSpecResourceLimits,
  2072. []string{
  2073. source.NamespaceLabel,
  2074. source.ResourceQuotaLabel,
  2075. source.UIDLabel,
  2076. },
  2077. aggregator.MaxOverTime,
  2078. func(labels map[string]string) bool {
  2079. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2080. },
  2081. )
  2082. }
  2083. // avg(
  2084. // avg_over_time(
  2085. // resourcequota_status_used_resource_requests{
  2086. // resource="cpu",
  2087. // unit="core",
  2088. // <some_custom_filter>
  2089. // }[1h]
  2090. // )
  2091. //) by (resourcequota, namespace, uid, cluster_id)
  2092. func NewResourceQuotaStatusUsedCPURequestAverageMetricCollector() *metric.MetricCollector {
  2093. return metric.NewMetricCollector(
  2094. metric.ResourceQuotaStatusUsedCPURequestAverageID,
  2095. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2096. []string{
  2097. source.NamespaceLabel,
  2098. source.ResourceQuotaLabel,
  2099. source.UIDLabel,
  2100. },
  2101. aggregator.AverageOverTime,
  2102. func(labels map[string]string) bool {
  2103. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2104. },
  2105. )
  2106. }
  2107. // max(
  2108. // max_over_time(
  2109. // resourcequota_status_used_resource_requests{
  2110. // resource="cpu",
  2111. // unit="core",
  2112. // <some_custom_filter>
  2113. // }[1h]
  2114. // )
  2115. //) by (resourcequota, namespace, uid, cluster_id)
  2116. func NewResourceQuotaStatusUsedCPURequestMaxMetricCollector() *metric.MetricCollector {
  2117. return metric.NewMetricCollector(
  2118. metric.ResourceQuotaStatusUsedCPURequestMaxID,
  2119. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2120. []string{
  2121. source.NamespaceLabel,
  2122. source.ResourceQuotaLabel,
  2123. source.UIDLabel,
  2124. },
  2125. aggregator.MaxOverTime,
  2126. func(labels map[string]string) bool {
  2127. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2128. },
  2129. )
  2130. }
  2131. // avg(
  2132. // avg_over_time(
  2133. // resourcequota_status_used_resource_requests{
  2134. // resource="memory",
  2135. // unit="byte",
  2136. // <some_custom_filter>
  2137. // }[1h]
  2138. // )
  2139. //) by (resourcequota, namespace, uid, cluster_id)
  2140. func NewResourceQuotaStatusUsedRAMRequestAverageMetricCollector() *metric.MetricCollector {
  2141. return metric.NewMetricCollector(
  2142. metric.ResourceQuotaStatusUsedRAMRequestAverageID,
  2143. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2144. []string{
  2145. source.NamespaceLabel,
  2146. source.ResourceQuotaLabel,
  2147. source.UIDLabel,
  2148. },
  2149. aggregator.AverageOverTime,
  2150. func(labels map[string]string) bool {
  2151. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2152. },
  2153. )
  2154. }
  2155. // max(
  2156. // max_over_time(
  2157. // resourcequota_status_used_resource_requests{
  2158. // resource="memory",
  2159. // unit="byte",
  2160. // <some_custom_filter>
  2161. // }[1h]
  2162. // )
  2163. //) by (resourcequota, namespace, uid, cluster_id)
  2164. func NewResourceQuotaStatusUsedRAMRequestMaxMetricCollector() *metric.MetricCollector {
  2165. return metric.NewMetricCollector(
  2166. metric.ResourceQuotaStatusUsedRAMRequestMaxID,
  2167. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2168. []string{
  2169. source.NamespaceLabel,
  2170. source.ResourceQuotaLabel,
  2171. source.UIDLabel,
  2172. },
  2173. aggregator.MaxOverTime,
  2174. func(labels map[string]string) bool {
  2175. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2176. },
  2177. )
  2178. }
  2179. // avg(
  2180. // avg_over_time(
  2181. // resourcequota_status_used_resource_limits{
  2182. // resource="cpu",
  2183. // unit="core",
  2184. // <some_custom_filter>
  2185. // }[1h]
  2186. // )
  2187. //) by (resourcequota, namespace, uid, cluster_id)
  2188. func NewResourceQuotaStatusUsedCPULimitAverageMetricCollector() *metric.MetricCollector {
  2189. return metric.NewMetricCollector(
  2190. metric.ResourceQuotaStatusUsedCPULimitAverageID,
  2191. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2192. []string{
  2193. source.NamespaceLabel,
  2194. source.ResourceQuotaLabel,
  2195. source.UIDLabel,
  2196. },
  2197. aggregator.AverageOverTime,
  2198. func(labels map[string]string) bool {
  2199. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2200. },
  2201. )
  2202. }
  2203. // max(
  2204. // max_over_time(
  2205. // resourcequota_status_used_resource_limits{
  2206. // resource="cpu",
  2207. // unit="core",
  2208. // <some_custom_filter>
  2209. // }[1h]
  2210. // )
  2211. //) by (resourcequota, namespace, uid, cluster_id)
  2212. func NewResourceQuotaStatusUsedCPULimitMaxMetricCollector() *metric.MetricCollector {
  2213. return metric.NewMetricCollector(
  2214. metric.ResourceQuotaStatusUsedCPULimitMaxID,
  2215. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2216. []string{
  2217. source.NamespaceLabel,
  2218. source.ResourceQuotaLabel,
  2219. source.UIDLabel,
  2220. },
  2221. aggregator.MaxOverTime,
  2222. func(labels map[string]string) bool {
  2223. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2224. },
  2225. )
  2226. }
  2227. // avg(
  2228. // avg_over_time(
  2229. // resourcequota_status_used_resource_limits{
  2230. // resource="memory",
  2231. // unit="byte",
  2232. // <some_custom_filter>
  2233. // }[1h]
  2234. // )
  2235. //) by (resourcequota, namespace, uid, cluster_id)
  2236. func NewResourceQuotaStatusUsedRAMLimitAverageMetricCollector() *metric.MetricCollector {
  2237. return metric.NewMetricCollector(
  2238. metric.ResourceQuotaStatusUsedRAMLimitAverageID,
  2239. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2240. []string{
  2241. source.NamespaceLabel,
  2242. source.ResourceQuotaLabel,
  2243. source.UIDLabel,
  2244. },
  2245. aggregator.AverageOverTime,
  2246. func(labels map[string]string) bool {
  2247. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2248. },
  2249. )
  2250. }
  2251. // max(
  2252. // max_over_time(
  2253. // resourcequota_status_used_resource_limits{
  2254. // resource="memory",
  2255. // unit="byte",
  2256. // <some_custom_filter>
  2257. // }[1h]
  2258. // )
  2259. //) by (resourcequota, namespace, uid, cluster_id)
  2260. func NewResourceQuotaStatusUsedRAMLimitMaxMetricCollector() *metric.MetricCollector {
  2261. return metric.NewMetricCollector(
  2262. metric.ResourceQuotaStatusUsedRAMLimitMaxID,
  2263. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2264. []string{
  2265. source.NamespaceLabel,
  2266. source.ResourceQuotaLabel,
  2267. source.UIDLabel,
  2268. },
  2269. aggregator.MaxOverTime,
  2270. func(labels map[string]string) bool {
  2271. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2272. },
  2273. )
  2274. }