collector.go 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256
  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(NewPVCBytesUsedAverageMetricCollector())
  17. memStore.Register(NewPVCBytesUsedMaxMetricCollector())
  18. memStore.Register(NewPVCUptimeMetricCollector())
  19. memStore.Register(NewPVInfoMetricCollector())
  20. memStore.Register(NewKMPVInfoMetricCollector())
  21. memStore.Register(NewPVUptimeMetricCollector())
  22. memStore.Register(NewPVActiveMinutesMetricCollector())
  23. memStore.Register(NewPVBytesMetricCollector())
  24. memStore.Register(NewLocalStorageUsedActiveMinutesMetricCollector())
  25. memStore.Register(NewLocalStorageUsedAverageMetricCollector())
  26. memStore.Register(NewLocalStorageUsedMaxMetricCollector())
  27. memStore.Register(NewLocalStorageBytesMetricCollector())
  28. memStore.Register(NewLocalStorageActiveMinutesMetricCollector())
  29. memStore.Register(NewKMLocalStorageUsedAverageMetricCollector())
  30. memStore.Register(NewKMLocalStorageUsedMaxMetricCollector())
  31. memStore.Register(NewKMLocalStorageBytesMetricCollector())
  32. memStore.Register(NewKMPVCInfoMetricCollector())
  33. memStore.Register(NewNodeInfoMetricCollector())
  34. memStore.Register(NewNodeUptimeMetricCollector())
  35. memStore.Register(NewNodeResourceCapacitiesMetricCollector())
  36. memStore.Register(NewNodeResourcesAllocatableMetricCollector())
  37. memStore.Register(NewNodeCPUCoresCapacityMetricCollector())
  38. memStore.Register(NewNodeCPUCoresAllocatableMetricCollector())
  39. memStore.Register(NewNodeRAMBytesCapacityMetricCollector())
  40. memStore.Register(NewNodeRAMBytesAllocatableMetricCollector())
  41. memStore.Register(NewNodeGPUCountMetricCollector())
  42. memStore.Register(NewNodeLabelsMetricCollector())
  43. memStore.Register(NewNodeActiveMinutesMetricCollector())
  44. memStore.Register(NewNodeCPUModeTotalMetricCollector())
  45. memStore.Register(NewNodeRAMSystemUsageAverageMetricCollector())
  46. memStore.Register(NewNodeRAMUserUsageAverageMetricCollector())
  47. memStore.Register(NewLBPricePerHourMetricCollector())
  48. memStore.Register(NewLBActiveMinutesMetricCollector())
  49. memStore.Register(NewClusterInfoMetricCollector())
  50. memStore.Register(NewClusterUptimeMetricCollector())
  51. memStore.Register(NewClusterManagementDurationMetricCollector())
  52. memStore.Register(NewClusterManagementPricePerHourMetricCollector())
  53. memStore.Register(NewPodActiveMinutesMetricCollector())
  54. memStore.Register(NewRAMBytesAllocatedMetricCollector())
  55. memStore.Register(NewRAMRequestsMetricCollector())
  56. memStore.Register(NewRAMLimitsMetricCollector())
  57. memStore.Register(NewRAMUsageAverageMetricCollector())
  58. memStore.Register(NewRAMUsageMaxMetricCollector())
  59. memStore.Register(NewCPUCoresAllocatedMetricCollector())
  60. memStore.Register(NewCPURequestsMetricCollector())
  61. memStore.Register(NewCPULimitsMetricCollector())
  62. memStore.Register(NewCPUUsageAverageMetricCollector())
  63. memStore.Register(NewCPUUsageMaxMetricCollector())
  64. memStore.Register(NewGPUsRequestedMetricCollector())
  65. memStore.Register(NewGPUsUsageAverageMetricCollector())
  66. memStore.Register(NewGPUsUsageMaxMetricCollector())
  67. memStore.Register(NewGPUsAllocatedMetricCollector())
  68. memStore.Register(NewIsGPUSharedMetricCollector())
  69. memStore.Register(NewGPUInfoMetricCollector())
  70. memStore.Register(NewDCGMInfoMetricCollector())
  71. memStore.Register(NewDCGMUptimeMetricCollector())
  72. memStore.Register(NewDCGMContainerUsageAvgMetricCollector())
  73. memStore.Register(NewDCGMContainerUsageMaxMetricCollector())
  74. for _, gpuSaturationCollector := range NewGPUSaturationMetricCollectors() {
  75. memStore.Register(gpuSaturationCollector)
  76. }
  77. for _, gpuDeviceCollector := range NewGPUDeviceMetricCollectors() {
  78. memStore.Register(gpuDeviceCollector)
  79. }
  80. memStore.Register(NewNodeCPUPricePerHourMetricCollector())
  81. memStore.Register(NewNodeRAMPricePerGiBHourMetricCollector())
  82. memStore.Register(NewNodeGPUPricePerHourMetricCollector())
  83. memStore.Register(NewNodeIsSpotMetricCollector())
  84. memStore.Register(NewPodPVCAllocationMetricCollector())
  85. memStore.Register(NewPVCBytesRequestedMetricCollector())
  86. memStore.Register(NewNetZoneGiBMetricCollector())
  87. memStore.Register(NewNetZonePricePerGiBMetricCollector())
  88. memStore.Register(NewNetRegionGiBMetricCollector())
  89. memStore.Register(NewNetRegionPricePerGiBMetricCollector())
  90. memStore.Register(NewNetInternetGiBMetricCollector())
  91. memStore.Register(NewNetInternetPricePerGiBMetricCollector())
  92. memStore.Register(NewNetInternetServiceGiBMetricCollector())
  93. memStore.Register(NewNetNatGatewayGiBMetricCollector())
  94. memStore.Register(NewNetNatGatewayPricePerGiBMetricCollector())
  95. memStore.Register(NewNetReceiveBytesMetricCollector())
  96. memStore.Register(NewNetZoneIngressGiBMetricCollector())
  97. memStore.Register(NewNetRegionIngressGiBMetricCollector())
  98. memStore.Register(NewNetInternetIngressGiBMetricCollector())
  99. memStore.Register(NewNetInternetServiceIngressGiBMetricCollector())
  100. memStore.Register(NewNetNatGatewayIngressPricePerGiBMetricCollector())
  101. memStore.Register(NewNetNatGatewayIngressGiBMetricCollector())
  102. memStore.Register(NewNetTransferBytesMetricCollector())
  103. memStore.Register(NewNamespaceInfoMetricCollector())
  104. memStore.Register(NewNamespaceUptimeMetricCollector())
  105. memStore.Register(NewNamespaceLabelsMetricCollector())
  106. memStore.Register(NewNamespaceAnnotationsMetricCollector())
  107. memStore.Register(NewPodLabelsMetricCollector())
  108. memStore.Register(NewPodAnnotationsMetricCollector())
  109. memStore.Register(NewServiceInfoMetricCollector())
  110. memStore.Register(NewServiceUptimeMetricCollector())
  111. memStore.Register(NewServiceLabelsMetricCollector())
  112. memStore.Register(NewDeploymentInfoMetricCollector())
  113. memStore.Register(NewDeploymentUptimeMetricCollector())
  114. memStore.Register(NewDeploymentLabelsMetricCollector())
  115. memStore.Register(NewDeploymentAnnotationsMetricCollector())
  116. memStore.Register(NewDeploymentMatchLabelsMetricCollector())
  117. memStore.Register(NewStatefulSetInfoMetricCollector())
  118. memStore.Register(NewStatefulSetUptimeMetricCollector())
  119. memStore.Register(NewStatefulSetLabelsMetricCollector())
  120. memStore.Register(NewStatefulSetAnnotationsMetricCollector())
  121. memStore.Register(NewStatefulSetMatchLabelsMetricCollector())
  122. memStore.Register(NewDaemonSetInfoMetricCollector())
  123. memStore.Register(NewDaemonSetUptimeMetricCollector())
  124. memStore.Register(NewDaemonSetLabelsMetricCollector())
  125. memStore.Register(NewDaemonSetAnnotationsMetricCollector())
  126. memStore.Register(NewJobInfoMetricCollector())
  127. memStore.Register(NewJobUptimeMetricCollector())
  128. memStore.Register(NewJobLabelsMetricCollector())
  129. memStore.Register(NewJobAnnotationsMetricCollector())
  130. memStore.Register(NewCronJobInfoMetricCollector())
  131. memStore.Register(NewCronJobUptimeMetricCollector())
  132. memStore.Register(NewCronJobLabelsMetricCollector())
  133. memStore.Register(NewCronJobAnnotationsMetricCollector())
  134. memStore.Register(NewReplicaSetInfoMetricCollector())
  135. memStore.Register(NewReplicaSetUptimeMetricCollector())
  136. memStore.Register(NewReplicaSetLabelsMetricCollector())
  137. memStore.Register(NewReplicaSetAnnotationsMetricCollector())
  138. memStore.Register(NewReplicaSetOwnerMetricCollector())
  139. memStore.Register(NewPodsWithDaemonSetOwnerMetricCollector())
  140. memStore.Register(NewPodsWithJobOwnerMetricCollector())
  141. memStore.Register(NewPodsWithReplicaSetOwnerMetricCollector())
  142. memStore.Register(NewPodInfoMetricCollector())
  143. memStore.Register(NewPodUptimeMetricCollector())
  144. memStore.Register(NewPodOwnerMetricCollector())
  145. memStore.Register(NewPodPVCVolumeMetricCollector())
  146. memStore.Register(NewPodNetworkEgressBytesMetricCollector())
  147. memStore.Register(NewPodNetworkIngressBytesMetricCollector())
  148. memStore.Register(NewContainerUptimeMetricCollector())
  149. memStore.Register(NewContainerResourceRequestsMetricCollector())
  150. memStore.Register(NewContainerResourceLimitsMetricCollector())
  151. memStore.Register(NewReplicaSetsWithoutOwnersMetricCollector())
  152. memStore.Register(NewReplicaSetsWithRolloutMetricCollector())
  153. memStore.Register(NewResourceQuotaInfoMetricCollector())
  154. memStore.Register(NewResourceQuotaUptimeMetricCollector())
  155. memStore.Register(NewResourceQuotaSpecCPURequestAverageMetricCollector())
  156. memStore.Register(NewResourceQuotaSpecCPURequestMaxMetricCollector())
  157. memStore.Register(NewResourceQuotaSpecRAMRequestAverageMetricCollector())
  158. memStore.Register(NewResourceQuotaSpecRAMRequestMaxMetricCollector())
  159. memStore.Register(NewResourceQuotaSpecCPULimitAverageMetricCollector())
  160. memStore.Register(NewResourceQuotaSpecCPULimitMaxMetricCollector())
  161. memStore.Register(NewResourceQuotaSpecRAMLimitAverageMetricCollector())
  162. memStore.Register(NewResourceQuotaSpecRAMLimitMaxMetricCollector())
  163. memStore.Register(NewResourceQuotaStatusUsedCPURequestAverageMetricCollector())
  164. memStore.Register(NewResourceQuotaStatusUsedCPURequestMaxMetricCollector())
  165. memStore.Register(NewResourceQuotaStatusUsedRAMRequestAverageMetricCollector())
  166. memStore.Register(NewResourceQuotaStatusUsedRAMRequestMaxMetricCollector())
  167. memStore.Register(NewResourceQuotaStatusUsedCPULimitAverageMetricCollector())
  168. memStore.Register(NewResourceQuotaStatusUsedCPULimitMaxMetricCollector())
  169. memStore.Register(NewResourceQuotaStatusUsedRAMLimitAverageMetricCollector())
  170. memStore.Register(NewResourceQuotaStatusUsedRAMLimitMaxMetricCollector())
  171. return memStore
  172. }
  173. // avg(
  174. // avg_over_time(
  175. // pv_hourly_cost{
  176. // <some_custom_filter>
  177. // }[1h]
  178. // )
  179. // ) by (cluster_id, persistentvolume, volumename, provider_id)
  180. func NewPVPricePerGiBHourMetricCollector() *metric.MetricCollector {
  181. return metric.NewMetricCollector(
  182. metric.PVPricePerGiBHourID,
  183. metric.PVHourlyCost,
  184. []string{
  185. source.VolumeNameLabel,
  186. source.PVLabel,
  187. source.ProviderIDLabel,
  188. source.UIDLabel,
  189. },
  190. aggregator.AverageOverTime,
  191. nil,
  192. )
  193. }
  194. // avg(
  195. // avg_over_time(
  196. // kubelet_volume_stats_used_bytes{
  197. // <some_custom_filter>
  198. // }[1h]
  199. // )
  200. // ) by (cluster_id, persistentvolumeclaim, namespace)
  201. func NewPVUsedAverageMetricCollector() *metric.MetricCollector {
  202. return metric.NewMetricCollector(
  203. metric.PVUsedAverageID,
  204. metric.KubeletVolumeStatsUsedBytes,
  205. []string{
  206. source.NamespaceLabel,
  207. source.PVCLabel,
  208. source.UIDLabel,
  209. },
  210. aggregator.AverageOverTime,
  211. nil,
  212. )
  213. }
  214. // max(
  215. // max_over_time(
  216. // kubelet_volume_stats_used_bytes{
  217. // <some_custom_filter>
  218. // }[1h]
  219. // )
  220. // ) by (cluster_id, persistentvolumeclaim, namespace)
  221. func NewPVUsedMaxMetricCollector() *metric.MetricCollector {
  222. return metric.NewMetricCollector(
  223. metric.PVUsedMaxID,
  224. metric.KubeletVolumeStatsUsedBytes,
  225. []string{
  226. source.NamespaceLabel,
  227. source.PVCLabel,
  228. source.UIDLabel,
  229. },
  230. aggregator.MaxOverTime,
  231. nil,
  232. )
  233. }
  234. func NewPVCBytesUsedAverageMetricCollector() *metric.MetricCollector {
  235. return metric.NewMetricCollector(
  236. metric.PVCBytesUsedAverageID,
  237. metric.KubeletVolumeStatsUsedBytes,
  238. []string{
  239. source.PVCUIDLabel,
  240. },
  241. aggregator.AverageOverTime,
  242. nil,
  243. )
  244. }
  245. func NewPVCBytesUsedMaxMetricCollector() *metric.MetricCollector {
  246. return metric.NewMetricCollector(
  247. metric.PVCBytesUsedMaxID,
  248. metric.KubeletVolumeStatsUsedBytes,
  249. []string{
  250. source.PVCUIDLabel,
  251. },
  252. aggregator.MaxOverTime,
  253. nil,
  254. )
  255. }
  256. // avg(
  257. // kube_persistentvolumeclaim_info{
  258. // volumename != "",
  259. // <some_custom_filter>
  260. // }
  261. // ) by (persistentvolumeclaim, storageclass, volumename, namespace, cluster_id)[0:10m]
  262. func NewPVCInfoMetricCollector() *metric.MetricCollector {
  263. return metric.NewMetricCollector(
  264. metric.PVCInfoID,
  265. metric.KubePersistentVolumeClaimInfo,
  266. []string{
  267. source.NamespaceLabel,
  268. source.VolumeNameLabel,
  269. source.PVCLabel,
  270. source.StorageClassLabel,
  271. source.UIDLabel,
  272. },
  273. aggregator.Uptime,
  274. func(labels map[string]string) bool {
  275. return labels[source.VolumeNameLabel] != ""
  276. },
  277. )
  278. }
  279. func NewPVCUptimeMetricCollector() *metric.MetricCollector {
  280. return metric.NewMetricCollector(
  281. metric.PVCUptimeID,
  282. metric.KubePersistentVolumeClaimInfo,
  283. []string{
  284. source.UIDLabel,
  285. },
  286. aggregator.Uptime,
  287. nil,
  288. )
  289. }
  290. // avg(
  291. // kube_persistentvolume_capacity_bytes{
  292. // <some_custom_filter>
  293. // }
  294. // ) by (cluster_id, persistentvolume)[0:10m]
  295. func NewPVActiveMinutesMetricCollector() *metric.MetricCollector {
  296. return metric.NewMetricCollector(
  297. metric.PVActiveMinutesID,
  298. metric.KubePersistentVolumeCapacityBytes,
  299. []string{
  300. source.UIDLabel,
  301. source.PVLabel,
  302. },
  303. aggregator.Uptime,
  304. nil,
  305. )
  306. }
  307. func NewKMPVInfoMetricCollector() *metric.MetricCollector {
  308. return metric.NewMetricCollector(
  309. metric.KMPVInfoID,
  310. metric.KubecostPVInfo,
  311. []string{
  312. source.UIDLabel,
  313. },
  314. aggregator.Info,
  315. nil,
  316. )
  317. }
  318. func NewPVUptimeMetricCollector() *metric.MetricCollector {
  319. return metric.NewMetricCollector(
  320. metric.PVUptimeID,
  321. metric.KubecostPVInfo,
  322. []string{
  323. source.UIDLabel,
  324. },
  325. aggregator.Uptime,
  326. nil,
  327. )
  328. }
  329. // sum_over_time(
  330. //
  331. // sum(
  332. // container_fs_usage_bytes{
  333. // device=~"/dev/(nvme|sda).*",
  334. // id="/",
  335. // <some_custom_filter>
  336. // }
  337. // ) by (instance, device, cluster_id)[%s:%dm]
  338. //
  339. // ) / 1024 / 1024 / 1024 * %f * %f`
  340. func NewLocalStorageUsedActiveMinutesMetricCollector() *metric.MetricCollector {
  341. return metric.NewMetricCollector(
  342. metric.LocalStorageUsedActiveMinutesID,
  343. metric.ContainerFSUsageBytes,
  344. []string{
  345. source.InstanceLabel,
  346. source.DeviceLabel,
  347. },
  348. aggregator.Uptime,
  349. nil, // filter not required here because only container root file system is being scraped
  350. )
  351. }
  352. // avg(
  353. // sum(
  354. // avg_over_time(
  355. // container_fs_usage_bytes{
  356. // device=~"/dev/(nvme|sda).*",
  357. // id="/",
  358. // <some_custom_filter>
  359. // }[1h]
  360. // )
  361. // ) by (instance, device, cluster_id, job)
  362. // ) by (instance, device, cluster_id)
  363. func NewLocalStorageUsedAverageMetricCollector() *metric.MetricCollector {
  364. return metric.NewMetricCollector(
  365. metric.LocalStorageUsedAverageID,
  366. metric.ContainerFSUsageBytes,
  367. []string{
  368. source.InstanceLabel,
  369. source.DeviceLabel,
  370. },
  371. aggregator.AverageOverTime,
  372. nil, // filter not required here because only container root file system is being scraped
  373. )
  374. }
  375. // max(
  376. //
  377. // sum(
  378. // max_over_time(
  379. // container_fs_usage_bytes{
  380. // device=~"/dev/(nvme|sda).*",
  381. // id="/",
  382. // <some_custom_filter>
  383. // }[1h]
  384. // )
  385. // ) by (instance, device, cluster_id, job)
  386. //
  387. // ) by (instance, device, cluster_id)
  388. func NewLocalStorageUsedMaxMetricCollector() *metric.MetricCollector {
  389. return metric.NewMetricCollector(
  390. metric.LocalStorageUsedMaxID,
  391. metric.ContainerFSUsageBytes,
  392. []string{
  393. source.InstanceLabel,
  394. source.DeviceLabel,
  395. },
  396. aggregator.MaxOverTime,
  397. nil, // filter not required here because only container root file system is being scraped
  398. )
  399. }
  400. // avg_over_time(
  401. //
  402. // sum(
  403. // container_fs_limit_bytes{
  404. // device=~"/dev/(nvme|sda).*",
  405. // id="/",
  406. // <some_custom_filter>
  407. // }
  408. // ) by (instance, device, cluster_id)[%s:%dm]
  409. //
  410. // )
  411. func NewLocalStorageBytesMetricCollector() *metric.MetricCollector {
  412. return metric.NewMetricCollector(
  413. metric.LocalStorageBytesID,
  414. metric.NodeFSCapacityBytes,
  415. []string{
  416. source.InstanceLabel,
  417. source.DeviceLabel,
  418. source.UIDLabel,
  419. },
  420. aggregator.AverageOverTime,
  421. nil, // filter not required here because only node root file system is being scraped
  422. )
  423. }
  424. func NewKMLocalStorageUsedAverageMetricCollector() *metric.MetricCollector {
  425. return metric.NewMetricCollector(
  426. metric.KMLocalStorageUsedAverageID,
  427. metric.ContainerFSUsageBytes,
  428. []string{
  429. source.NodeUIDLabel,
  430. },
  431. aggregator.AverageOverTime,
  432. nil,
  433. )
  434. }
  435. func NewKMLocalStorageUsedMaxMetricCollector() *metric.MetricCollector {
  436. return metric.NewMetricCollector(
  437. metric.KMLocalStorageUsedMaxID,
  438. metric.ContainerFSUsageBytes,
  439. []string{
  440. source.NodeUIDLabel,
  441. },
  442. aggregator.MaxOverTime,
  443. nil,
  444. )
  445. }
  446. func NewKMLocalStorageBytesMetricCollector() *metric.MetricCollector {
  447. return metric.NewMetricCollector(
  448. metric.KMLocalStorageBytesID,
  449. metric.NodeFSCapacityBytes,
  450. []string{
  451. source.UIDLabel,
  452. },
  453. aggregator.AverageOverTime,
  454. nil,
  455. )
  456. }
  457. func NewKMPVCInfoMetricCollector() *metric.MetricCollector {
  458. return metric.NewMetricCollector(
  459. metric.KMPVCInfoID,
  460. metric.KubePersistentVolumeClaimInfo,
  461. []string{
  462. source.UIDLabel,
  463. },
  464. aggregator.Info,
  465. nil,
  466. )
  467. }
  468. // count(
  469. //
  470. // kube_node_labels{
  471. // <some_custom_filter>
  472. // }
  473. //
  474. // ) by (cluster_id, node, instance, provider_id)[%s:%dm]
  475. func NewLocalStorageActiveMinutesMetricCollector() *metric.MetricCollector {
  476. return metric.NewMetricCollector(
  477. metric.LocalStorageActiveMinutesID,
  478. metric.KubeNodeLabels,
  479. []string{
  480. source.NodeLabel,
  481. source.ProviderIDLabel,
  482. source.UIDLabel,
  483. },
  484. aggregator.Uptime,
  485. nil,
  486. )
  487. }
  488. func NewNodeInfoMetricCollector() *metric.MetricCollector {
  489. return metric.NewMetricCollector(
  490. metric.NodeInfoID,
  491. metric.NodeInfo,
  492. []string{
  493. source.NodeLabel,
  494. source.UIDLabel,
  495. source.ProviderIDLabel,
  496. source.InstanceTypeLabel,
  497. },
  498. aggregator.Info,
  499. nil,
  500. )
  501. }
  502. func NewNodeUptimeMetricCollector() *metric.MetricCollector {
  503. return metric.NewMetricCollector(
  504. metric.NodeUptimeID,
  505. metric.NodeInfo,
  506. []string{
  507. source.UIDLabel,
  508. },
  509. aggregator.Uptime,
  510. nil,
  511. )
  512. }
  513. func NewNodeResourceCapacitiesMetricCollector() *metric.MetricCollector {
  514. return metric.NewMetricCollector(
  515. metric.NodeResourceCapacitiesID,
  516. metric.NodeResourceCapacities,
  517. []string{
  518. source.UIDLabel,
  519. source.ResourceLabel,
  520. source.UnitLabel,
  521. },
  522. aggregator.AverageOverTime,
  523. nil,
  524. )
  525. }
  526. func NewNodeResourcesAllocatableMetricCollector() *metric.MetricCollector {
  527. return metric.NewMetricCollector(
  528. metric.NodeResourcesAllocatableID,
  529. metric.NodeResourcesAllocatable,
  530. []string{
  531. source.UIDLabel,
  532. source.ResourceLabel,
  533. source.UnitLabel,
  534. },
  535. aggregator.AverageOverTime,
  536. nil,
  537. )
  538. }
  539. // avg(
  540. //
  541. // avg_over_time(
  542. // kube_node_status_capacity_cpu_cores{
  543. // <some_custom_filter>
  544. // }[1h]
  545. // )
  546. //
  547. // ) by (cluster_id, node)
  548. func NewNodeCPUCoresCapacityMetricCollector() *metric.MetricCollector {
  549. return metric.NewMetricCollector(
  550. metric.NodeCPUCoresCapacityID,
  551. metric.KubeNodeStatusCapacityCPUCores,
  552. []string{
  553. source.NodeLabel,
  554. source.UIDLabel,
  555. },
  556. aggregator.AverageOverTime,
  557. nil,
  558. )
  559. }
  560. // avg(
  561. // avg_over_time(
  562. // kube_node_status_allocatable_cpu_cores{
  563. // <some_custom_filter>
  564. // }[1h]
  565. // )
  566. // ) by (cluster_id, node)
  567. func NewNodeCPUCoresAllocatableMetricCollector() *metric.MetricCollector {
  568. return metric.NewMetricCollector(
  569. metric.NodeCPUCoresAllocatableID,
  570. metric.KubeNodeStatusAllocatableCPUCores,
  571. []string{
  572. source.NodeLabel,
  573. source.UIDLabel,
  574. },
  575. aggregator.AverageOverTime,
  576. nil,
  577. )
  578. }
  579. // avg(
  580. // avg_over_time(
  581. // kube_node_status_capacity_memory_bytes{
  582. // <some_custom_filter>
  583. // }[1h]
  584. // )
  585. // ) by (cluster_id, node)
  586. func NewNodeRAMBytesCapacityMetricCollector() *metric.MetricCollector {
  587. return metric.NewMetricCollector(
  588. metric.NodeRAMBytesCapacityID,
  589. metric.KubeNodeStatusCapacityMemoryBytes,
  590. []string{
  591. source.NodeLabel,
  592. source.UIDLabel,
  593. },
  594. aggregator.AverageOverTime,
  595. nil,
  596. )
  597. }
  598. // avg(
  599. // avg_over_time(
  600. // kube_node_status_allocatable_memory_bytes{
  601. // <some_custom_filter>
  602. // }[1h]
  603. // )
  604. // ) by (cluster_id, node)
  605. func NewNodeRAMBytesAllocatableMetricCollector() *metric.MetricCollector {
  606. return metric.NewMetricCollector(
  607. metric.NodeRAMBytesAllocatableID,
  608. metric.KubeNodeStatusAllocatableMemoryBytes,
  609. []string{
  610. source.NodeLabel,
  611. source.UIDLabel,
  612. },
  613. aggregator.AverageOverTime,
  614. nil,
  615. )
  616. }
  617. // avg(
  618. // avg_over_time(
  619. // node_gpu_count{
  620. // <some_custom_filter>
  621. // }[1h]
  622. // )
  623. // ) by (cluster_id, node, provider_id)
  624. func NewNodeGPUCountMetricCollector() *metric.MetricCollector {
  625. return metric.NewMetricCollector(
  626. metric.NodeGPUCountID,
  627. metric.NodeGPUCount,
  628. []string{
  629. source.NodeLabel,
  630. source.ProviderIDLabel,
  631. source.UIDLabel,
  632. },
  633. aggregator.AverageOverTime,
  634. nil,
  635. )
  636. }
  637. // avg_over_time(
  638. // kube_node_labels{
  639. // <some_custom_filter>
  640. // }[1h]
  641. // )
  642. func NewNodeLabelsMetricCollector() *metric.MetricCollector {
  643. return metric.NewMetricCollector(
  644. metric.NodeLabelsID,
  645. metric.KubeNodeLabels,
  646. []string{
  647. source.NodeLabel,
  648. source.UIDLabel,
  649. },
  650. aggregator.Info,
  651. nil,
  652. )
  653. }
  654. // avg(
  655. // kube_node_labels{
  656. // <some_custom_filter>
  657. // }
  658. // ) by (node, cluster_id, provider_id)[%s:%dm]
  659. func NewNodeActiveMinutesMetricCollector() *metric.MetricCollector {
  660. return metric.NewMetricCollector(
  661. metric.NodeActiveMinutesID,
  662. metric.KubeNodeLabels,
  663. []string{
  664. source.NodeLabel,
  665. source.ProviderIDLabel,
  666. source.UIDLabel,
  667. },
  668. aggregator.Uptime,
  669. nil,
  670. )
  671. }
  672. // sum(
  673. // rate(
  674. // node_cpu_seconds_total{
  675. // <some_custom_filter>
  676. // }[%s:%dm]
  677. // )
  678. // ) by (kubernetes_node, cluster_id, mode)
  679. func NewNodeCPUModeTotalMetricCollector() *metric.MetricCollector {
  680. return metric.NewMetricCollector(
  681. metric.NodeCPUModeTotalID,
  682. metric.NodeCPUSecondsTotal,
  683. []string{
  684. source.KubernetesNodeLabel,
  685. source.ModeLabel,
  686. source.UIDLabel,
  687. },
  688. aggregator.Rate,
  689. nil,
  690. )
  691. }
  692. // avg(
  693. // avg_over_time(
  694. // container_memory_working_set_bytes{
  695. // container_name!="POD",
  696. // container_name!="",
  697. // namespace="kube-system",
  698. // <some_custom_filter>
  699. // }[%s:%dm]
  700. // )
  701. // ) by (instance, cluster_id)
  702. func NewNodeRAMSystemUsageAverageMetricCollector() *metric.MetricCollector {
  703. return metric.NewMetricCollector(
  704. metric.NodeRAMSystemUsageAverageID,
  705. metric.ContainerMemoryWorkingSetBytes,
  706. []string{
  707. source.InstanceLabel,
  708. source.UIDLabel,
  709. },
  710. aggregator.AverageOverTime,
  711. func(labels map[string]string) bool {
  712. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NamespaceLabel] == "kube-system"
  713. },
  714. )
  715. }
  716. // avg(
  717. // avg_over_time(
  718. // container_memory_working_set_bytes{
  719. // container_name!="POD",
  720. // container_name!="",
  721. // namespace!="kube-system",
  722. // <some_custom_filter>
  723. // }[%s:%dm]
  724. // )
  725. // ) by (instance, cluster_id)
  726. func NewNodeRAMUserUsageAverageMetricCollector() *metric.MetricCollector {
  727. return metric.NewMetricCollector(
  728. metric.NodeRAMUserUsageAverageID,
  729. metric.ContainerMemoryWorkingSetBytes,
  730. []string{
  731. source.InstanceLabel,
  732. source.UIDLabel,
  733. },
  734. aggregator.AverageOverTime,
  735. func(labels map[string]string) bool {
  736. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NamespaceLabel] != "kube-system"
  737. },
  738. )
  739. }
  740. // avg(
  741. // avg_over_time(
  742. // kubecost_load_balancer_cost{
  743. // <some_custom_filter>
  744. // }[1h]
  745. // )
  746. // ) by (namespace, service_name, ingress_ip, cluster_id)
  747. func NewLBPricePerHourMetricCollector() *metric.MetricCollector {
  748. return metric.NewMetricCollector(
  749. metric.LBPricePerHourID,
  750. metric.KubecostLoadBalancerCost,
  751. []string{
  752. source.NamespaceLabel,
  753. source.ServiceNameLabel,
  754. source.IngressIPLabel,
  755. source.UIDLabel,
  756. },
  757. aggregator.AverageOverTime,
  758. nil,
  759. )
  760. }
  761. // avg(
  762. // kubecost_load_balancer_cost{
  763. // <some_custom_filter>
  764. // }
  765. // ) by (namespace, service_name, cluster_id, ingress_ip)[%s:%dm]
  766. func NewLBActiveMinutesMetricCollector() *metric.MetricCollector {
  767. return metric.NewMetricCollector(
  768. metric.LBActiveMinutesID,
  769. metric.KubecostLoadBalancerCost,
  770. []string{
  771. source.NamespaceLabel,
  772. source.ServiceNameLabel,
  773. source.IngressIPLabel,
  774. source.UIDLabel,
  775. },
  776. aggregator.Uptime,
  777. nil,
  778. )
  779. }
  780. func NewClusterInfoMetricCollector() *metric.MetricCollector {
  781. return metric.NewMetricCollector(
  782. metric.ClusterInfoID,
  783. metric.ClusterInfo,
  784. []string{
  785. source.UIDLabel,
  786. },
  787. aggregator.Info,
  788. nil,
  789. )
  790. }
  791. // avg(
  792. // cluster_info{
  793. // <some_custom_filter>
  794. // }
  795. // ) by (uid)[%s:%dm]
  796. func NewClusterUptimeMetricCollector() *metric.MetricCollector {
  797. return metric.NewMetricCollector(
  798. metric.ClusterUptimeID,
  799. metric.ClusterInfo,
  800. []string{
  801. source.UIDLabel,
  802. },
  803. aggregator.Uptime,
  804. nil,
  805. )
  806. }
  807. // avg(
  808. // kubecost_cluster_management_cost{
  809. // <some_custom_filter>
  810. // }
  811. // ) by (cluster_id, provisioner_name)[%s:%dm]
  812. func NewClusterManagementDurationMetricCollector() *metric.MetricCollector {
  813. return metric.NewMetricCollector(
  814. metric.ClusterManagementDurationID,
  815. metric.KubecostClusterManagementCost,
  816. []string{
  817. source.ProvisionerNameLabel,
  818. source.UIDLabel,
  819. },
  820. aggregator.Uptime,
  821. nil,
  822. )
  823. }
  824. // avg(
  825. // avg_over_time(
  826. // kubecost_cluster_management_cost{
  827. // <some_custom_filter>
  828. // }[1h]
  829. // )
  830. // ) by (cluster_id, provisioner_name)
  831. func NewClusterManagementPricePerHourMetricCollector() *metric.MetricCollector {
  832. return metric.NewMetricCollector(
  833. metric.ClusterManagementPricePerHourID,
  834. metric.KubecostClusterManagementCost,
  835. []string{
  836. source.ProvisionerNameLabel,
  837. source.UIDLabel,
  838. },
  839. aggregator.AverageOverTime,
  840. nil,
  841. )
  842. }
  843. // avg(
  844. // kube_pod_container_status_running{
  845. // <some_custom_filter>
  846. // } != 0
  847. // ) by (pod, namespace, uid, cluster_id)[%s:%s]
  848. func NewPodActiveMinutesMetricCollector() *metric.MetricCollector {
  849. return metric.NewMetricCollector(
  850. metric.PodActiveMinutesID,
  851. metric.KubePodContainerStatusRunning,
  852. []string{
  853. source.UIDLabel,
  854. source.NamespaceLabel,
  855. source.PodLabel,
  856. },
  857. aggregator.Uptime,
  858. nil,
  859. )
  860. }
  861. func NewPodInfoMetricCollector() *metric.MetricCollector {
  862. return metric.NewMetricCollector(
  863. metric.PodInfoID,
  864. metric.PodInfo,
  865. []string{
  866. source.UIDLabel,
  867. },
  868. aggregator.Info,
  869. nil,
  870. )
  871. }
  872. func NewPodUptimeMetricCollector() *metric.MetricCollector {
  873. return metric.NewMetricCollector(
  874. metric.PodUptimeID,
  875. metric.PodInfo,
  876. []string{
  877. source.UIDLabel,
  878. },
  879. aggregator.Uptime,
  880. nil,
  881. )
  882. }
  883. func NewPodOwnerMetricCollector() *metric.MetricCollector {
  884. return metric.NewMetricCollector(
  885. metric.PodOwnerID,
  886. metric.KubePodOwner,
  887. []string{
  888. source.UIDLabel,
  889. source.OwnerUIDLabel,
  890. source.OwnerKindLabel,
  891. },
  892. aggregator.Info,
  893. nil,
  894. )
  895. }
  896. func NewPodPVCVolumeMetricCollector() *metric.MetricCollector {
  897. return metric.NewMetricCollector(
  898. metric.PodPVCVolumeID,
  899. metric.PodPVCVolume,
  900. []string{
  901. source.UIDLabel,
  902. source.PVCUIDLabel,
  903. source.PodVolumeNameLabel,
  904. },
  905. aggregator.Info,
  906. nil,
  907. )
  908. }
  909. func NewPodNetworkEgressBytesMetricCollector() *metric.MetricCollector {
  910. return metric.NewMetricCollector(
  911. metric.PodNetworkEgressBytesID,
  912. metric.KubecostPodNetworkEgressBytesTotal,
  913. []string{
  914. source.UIDLabel,
  915. source.ServiceLabel,
  916. source.InternetLabel,
  917. source.SameRegionLabel,
  918. source.SameZoneLabel,
  919. source.NatGatewayLabel,
  920. },
  921. aggregator.Increase,
  922. func(labels map[string]string) bool {
  923. return labels[source.UIDLabel] != ""
  924. },
  925. )
  926. }
  927. func NewPodNetworkIngressBytesMetricCollector() *metric.MetricCollector {
  928. return metric.NewMetricCollector(
  929. metric.PodNetworkIngressBytesID,
  930. metric.KubecostPodNetworkIngressBytesTotal,
  931. []string{
  932. source.UIDLabel,
  933. source.NatGatewayLabel,
  934. source.ServiceLabel,
  935. source.SameZoneLabel,
  936. source.SameRegionLabel,
  937. source.InternetLabel,
  938. },
  939. aggregator.Increase,
  940. func(labels map[string]string) bool {
  941. return labels[source.UIDLabel] != ""
  942. },
  943. )
  944. }
  945. func NewContainerUptimeMetricCollector() *metric.MetricCollector {
  946. return metric.NewMetricCollector(
  947. metric.ContainerUptimeID,
  948. metric.KubePodContainerStatusRunning,
  949. []string{
  950. source.UIDLabel,
  951. source.ContainerLabel,
  952. },
  953. aggregator.Uptime,
  954. nil,
  955. )
  956. }
  957. // avg(
  958. // avg_over_time(
  959. // container_memory_allocation_bytes{
  960. // container!="",
  961. // container!="POD",
  962. // node!="",
  963. // <some_custom_filter>
  964. // }[1h]
  965. // )
  966. // ) by (container, pod, namespace, node, cluster_id, provider_id)
  967. func NewRAMBytesAllocatedMetricCollector() *metric.MetricCollector {
  968. return metric.NewMetricCollector(
  969. metric.RAMBytesAllocatedID,
  970. metric.ContainerMemoryAllocationBytes,
  971. []string{
  972. source.NodeLabel,
  973. source.InstanceLabel,
  974. source.NamespaceLabel,
  975. source.PodLabel,
  976. source.UIDLabel,
  977. source.ContainerLabel,
  978. },
  979. aggregator.AverageOverTime,
  980. func(labels map[string]string) bool {
  981. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  982. },
  983. )
  984. }
  985. // avg(
  986. // avg_over_time(
  987. // kube_pod_container_resource_requests{
  988. // resource="memory",
  989. // unit="byte",
  990. // container!="",
  991. // container!="POD",
  992. // node!="",
  993. // <some_custom_filter>
  994. // }[1h]
  995. // )
  996. //) by (container, pod, namespace, node, cluster_id)
  997. func NewRAMRequestsMetricCollector() *metric.MetricCollector {
  998. return metric.NewMetricCollector(
  999. metric.RAMRequestsID,
  1000. metric.KubePodContainerResourceRequests,
  1001. []string{
  1002. source.NodeLabel,
  1003. source.InstanceLabel,
  1004. source.NamespaceLabel,
  1005. source.PodLabel,
  1006. source.UIDLabel,
  1007. source.ContainerLabel,
  1008. },
  1009. aggregator.AverageOverTime,
  1010. func(labels map[string]string) bool {
  1011. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  1012. },
  1013. )
  1014. }
  1015. // avg(
  1016. // avg_over_time(
  1017. // kube_pod_container_resource_limits{
  1018. // resource="memory",
  1019. // unit="byte",
  1020. // container!="",
  1021. // container!="POD",
  1022. // node!="",
  1023. // <some_custom_filter>
  1024. // }[1h]
  1025. // )
  1026. //) by (container, pod, namespace, node, cluster_id)
  1027. func NewRAMLimitsMetricCollector() *metric.MetricCollector {
  1028. return metric.NewMetricCollector(
  1029. metric.RAMLimitsID,
  1030. metric.KubePodContainerResourceLimits,
  1031. []string{
  1032. source.NodeLabel,
  1033. source.InstanceLabel,
  1034. source.NamespaceLabel,
  1035. source.PodLabel,
  1036. source.ContainerLabel,
  1037. },
  1038. aggregator.AverageOverTime,
  1039. func(labels map[string]string) bool {
  1040. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  1041. },
  1042. )
  1043. }
  1044. // avg(
  1045. // avg_over_time(
  1046. // container_memory_working_set_bytes{
  1047. // container!="",
  1048. // container!="POD",
  1049. // <some_custom_filter>
  1050. // }[1h]
  1051. // )
  1052. // ) by (container, pod, namespace, instance, cluster_id)
  1053. func NewRAMUsageAverageMetricCollector() *metric.MetricCollector {
  1054. return metric.NewMetricCollector(
  1055. metric.RAMUsageAverageID,
  1056. metric.ContainerMemoryWorkingSetBytes,
  1057. []string{
  1058. source.NodeLabel,
  1059. source.InstanceLabel,
  1060. source.NamespaceLabel,
  1061. source.PodLabel,
  1062. source.UIDLabel,
  1063. source.ContainerLabel,
  1064. },
  1065. aggregator.AverageOverTime,
  1066. func(labels map[string]string) bool {
  1067. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != ""
  1068. },
  1069. )
  1070. }
  1071. // max(
  1072. // max_over_time(
  1073. // container_memory_working_set_bytes{
  1074. // container!="",
  1075. // container_name!="POD",
  1076. // container!="POD",
  1077. // <some_custom_filter>
  1078. // }[%s]
  1079. // )
  1080. // ) by (container_name, container, pod_name, pod, namespace, node, instance, %s)
  1081. func NewRAMUsageMaxMetricCollector() *metric.MetricCollector {
  1082. return metric.NewMetricCollector(
  1083. metric.RAMUsageMaxID,
  1084. metric.ContainerMemoryWorkingSetBytes,
  1085. []string{
  1086. source.NodeLabel,
  1087. source.InstanceLabel,
  1088. source.NamespaceLabel,
  1089. source.PodLabel,
  1090. source.UIDLabel,
  1091. source.ContainerLabel,
  1092. },
  1093. aggregator.MaxOverTime,
  1094. func(labels map[string]string) bool {
  1095. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD" && labels[source.NodeLabel] != ""
  1096. },
  1097. )
  1098. }
  1099. // avg(
  1100. // avg_over_time(
  1101. // container_cpu_allocation{
  1102. // container!="",
  1103. // container!="POD",
  1104. // node!="",
  1105. // <some_custom_filter>
  1106. // }[1h]
  1107. // )
  1108. // ) by (container, pod, namespace, node, cluster_id)
  1109. func NewCPUCoresAllocatedMetricCollector() *metric.MetricCollector {
  1110. return metric.NewMetricCollector(
  1111. metric.CPUCoresAllocatedID,
  1112. metric.ContainerCPUAllocation,
  1113. []string{
  1114. source.NodeLabel,
  1115. source.InstanceLabel,
  1116. source.NamespaceLabel,
  1117. source.PodLabel,
  1118. source.UIDLabel,
  1119. source.ContainerLabel,
  1120. },
  1121. aggregator.AverageOverTime,
  1122. func(labels map[string]string) bool {
  1123. return labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  1124. },
  1125. )
  1126. }
  1127. // avg(
  1128. // avg_over_time(
  1129. // kube_pod_container_resource_requests{
  1130. // resource="cpu",
  1131. // unit="core",
  1132. // container!="",
  1133. // container!="POD",
  1134. // node!="",
  1135. // <some_custom_filter>
  1136. // }[1h]
  1137. // )
  1138. // ) by (container, pod, namespace, node, cluster_id)
  1139. func NewCPURequestsMetricCollector() *metric.MetricCollector {
  1140. return metric.NewMetricCollector(
  1141. metric.CPURequestsID,
  1142. metric.KubePodContainerResourceRequests,
  1143. []string{
  1144. source.NodeLabel,
  1145. source.InstanceLabel,
  1146. source.NamespaceLabel,
  1147. source.PodLabel,
  1148. source.UIDLabel,
  1149. source.ContainerLabel,
  1150. },
  1151. aggregator.AverageOverTime,
  1152. func(labels map[string]string) bool {
  1153. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  1154. },
  1155. )
  1156. }
  1157. // avg(
  1158. // avg_over_time(
  1159. // kube_pod_container_resource_limits{
  1160. // resource="cpu",
  1161. // unit="core",
  1162. // container!="",
  1163. // container!="POD",
  1164. // node!="",
  1165. // <some_custom_filter>
  1166. // }[1h]
  1167. // )
  1168. // ) by (container, pod, namespace, node, cluster_id)
  1169. func NewCPULimitsMetricCollector() *metric.MetricCollector {
  1170. return metric.NewMetricCollector(
  1171. metric.CPULimitsID,
  1172. metric.KubePodContainerResourceLimits,
  1173. []string{
  1174. source.NodeLabel,
  1175. source.InstanceLabel,
  1176. source.NamespaceLabel,
  1177. source.PodLabel,
  1178. source.ContainerLabel,
  1179. },
  1180. aggregator.AverageOverTime,
  1181. func(labels map[string]string) bool {
  1182. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  1183. },
  1184. )
  1185. }
  1186. func NewContainerResourceRequestsMetricCollector() *metric.MetricCollector {
  1187. return metric.NewMetricCollector(
  1188. metric.ContainerResourceRequestsID,
  1189. metric.KubePodContainerResourceRequests,
  1190. []string{
  1191. source.UIDLabel,
  1192. source.ContainerLabel,
  1193. source.ResourceLabel,
  1194. source.UnitLabel,
  1195. },
  1196. aggregator.AverageOverTime,
  1197. nil,
  1198. )
  1199. }
  1200. func NewContainerResourceLimitsMetricCollector() *metric.MetricCollector {
  1201. return metric.NewMetricCollector(
  1202. metric.ContainerResourceLimitsID,
  1203. metric.KubePodContainerResourceLimits,
  1204. []string{
  1205. source.UIDLabel,
  1206. source.ContainerLabel,
  1207. source.ResourceLabel,
  1208. source.UnitLabel,
  1209. },
  1210. aggregator.AverageOverTime,
  1211. nil,
  1212. )
  1213. }
  1214. // avg(
  1215. // rate(
  1216. // container_cpu_usage_seconds_total{
  1217. // container!="",
  1218. // container_name!="POD",
  1219. // container!="POD",
  1220. // <some_custom_filter>
  1221. // }[1h]
  1222. // )
  1223. // ) by (container_name, container, pod_name, pod, namespace, node, instance, cluster_id)
  1224. func NewCPUUsageAverageMetricCollector() *metric.MetricCollector {
  1225. return metric.NewMetricCollector(
  1226. metric.CPUUsageAverageID,
  1227. metric.ContainerCPUUsageSecondsTotal,
  1228. []string{
  1229. source.NodeLabel,
  1230. source.InstanceLabel,
  1231. source.NamespaceLabel,
  1232. source.PodLabel,
  1233. source.UIDLabel,
  1234. source.ContainerLabel,
  1235. },
  1236. aggregator.Rate,
  1237. func(labels map[string]string) bool {
  1238. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD"
  1239. },
  1240. )
  1241. }
  1242. // max(
  1243. //
  1244. // max_over_time(
  1245. // irate(
  1246. // container_cpu_usage_seconds_total{
  1247. // container!="POD",
  1248. // container!="",
  1249. // <some_custom_filter>
  1250. // }[1h]
  1251. // )[%s:%s]
  1252. // )
  1253. //
  1254. // ) by (container, pod_name, pod, namespace, node, instance, cluster_id)
  1255. func NewCPUUsageMaxMetricCollector() *metric.MetricCollector {
  1256. return metric.NewMetricCollector(
  1257. metric.CPUUsageMaxID,
  1258. metric.ContainerCPUUsageSecondsTotal,
  1259. []string{
  1260. source.NodeLabel,
  1261. source.InstanceLabel,
  1262. source.NamespaceLabel,
  1263. source.PodLabel,
  1264. source.UIDLabel,
  1265. source.ContainerLabel,
  1266. },
  1267. aggregator.IRateMax,
  1268. func(labels map[string]string) bool {
  1269. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD"
  1270. },
  1271. )
  1272. }
  1273. // avg(
  1274. // avg_over_time(
  1275. // kube_pod_container_resource_requests{
  1276. // resource="nvidia_com_gpu",
  1277. // container!="",
  1278. // container!="POD",
  1279. // node!="",
  1280. // <some_custom_filter>
  1281. // }[1h]
  1282. // )
  1283. // ) by (container, pod, namespace, node, cluster_id)
  1284. func NewGPUsRequestedMetricCollector() *metric.MetricCollector {
  1285. return metric.NewMetricCollector(
  1286. metric.GPUsRequestedID,
  1287. metric.KubePodContainerResourceRequests,
  1288. []string{
  1289. source.NamespaceLabel,
  1290. source.PodLabel,
  1291. source.UIDLabel,
  1292. source.ContainerLabel,
  1293. },
  1294. aggregator.AverageOverTime,
  1295. func(labels map[string]string) bool {
  1296. return labels[source.ResourceLabel] == "nvidia_com_gpu" && labels[source.ContainerLabel] != "POD" && labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != ""
  1297. },
  1298. )
  1299. }
  1300. // avg(
  1301. // avg_over_time(
  1302. // DCGM_FI_PROF_GR_ENGINE_ACTIVE{
  1303. // container!=""
  1304. // }[1h]
  1305. // )
  1306. // ) by (container, pod, namespace, cluster_id)
  1307. func NewGPUsUsageAverageMetricCollector() *metric.MetricCollector {
  1308. return metric.NewMetricCollector(
  1309. metric.GPUsUsageAverageID,
  1310. metric.DCGMFIPROFGRENGINEACTIVE,
  1311. []string{
  1312. source.NamespaceLabel,
  1313. source.PodLabel,
  1314. source.PodUIDLabel,
  1315. source.ContainerLabel,
  1316. },
  1317. aggregator.AverageOverTime,
  1318. func(labels map[string]string) bool {
  1319. return labels[source.ContainerLabel] != ""
  1320. },
  1321. )
  1322. }
  1323. // max(
  1324. // max_over_time(
  1325. // DCGM_FI_PROF_GR_ENGINE_ACTIVE{
  1326. // container!=""
  1327. // }[1h]
  1328. // )
  1329. // ) by (container, pod, namespace, cluster_id)
  1330. func NewGPUsUsageMaxMetricCollector() *metric.MetricCollector {
  1331. return metric.NewMetricCollector(
  1332. metric.GPUsUsageMaxID,
  1333. metric.DCGMFIPROFGRENGINEACTIVE,
  1334. []string{
  1335. source.NamespaceLabel,
  1336. source.PodLabel,
  1337. source.PodUIDLabel,
  1338. source.ContainerLabel,
  1339. },
  1340. aggregator.MaxOverTime,
  1341. func(labels map[string]string) bool {
  1342. return labels[source.ContainerLabel] != ""
  1343. },
  1344. )
  1345. }
  1346. // avg(
  1347. // avg_over_time(
  1348. // container_gpu_allocation{
  1349. // container!="",
  1350. // container!="POD",
  1351. // node!="",
  1352. // <some_custom_filter>
  1353. // }[1h]
  1354. // )
  1355. // ) by (container, pod, namespace, node, cluster_id)
  1356. func NewGPUsAllocatedMetricCollector() *metric.MetricCollector {
  1357. return metric.NewMetricCollector(
  1358. metric.GPUsAllocatedID,
  1359. metric.ContainerGPUAllocation,
  1360. []string{
  1361. source.NamespaceLabel,
  1362. source.PodLabel,
  1363. source.UIDLabel,
  1364. source.ContainerLabel,
  1365. },
  1366. aggregator.AverageOverTime,
  1367. func(labels map[string]string) bool {
  1368. return labels[source.ContainerLabel] != "" && labels[source.ContainerLabel] != "POD" && labels[source.NodeLabel] != ""
  1369. },
  1370. )
  1371. }
  1372. // avg(
  1373. // avg_over_time(
  1374. // kube_pod_container_resource_requests{
  1375. // container!="",
  1376. // node != "",
  1377. // pod != "",
  1378. // container!= "",
  1379. // unit = "integer",
  1380. // <some_custom_filter>
  1381. // }[1h]
  1382. // )
  1383. // ) by (container, pod, namespace, node, resource, cluster_id)
  1384. func NewIsGPUSharedMetricCollector() *metric.MetricCollector {
  1385. return metric.NewMetricCollector(
  1386. metric.IsGPUSharedID,
  1387. metric.KubePodContainerResourceRequests,
  1388. []string{
  1389. source.NamespaceLabel,
  1390. source.PodLabel,
  1391. source.UIDLabel,
  1392. source.ContainerLabel,
  1393. source.ResourceLabel,
  1394. },
  1395. aggregator.AverageOverTime,
  1396. func(labels map[string]string) bool {
  1397. return labels[source.ContainerLabel] != "" && labels[source.NodeLabel] != "" && labels[source.PodLabel] != "" && labels[source.UnitLabel] == "integer"
  1398. },
  1399. )
  1400. }
  1401. // avg(
  1402. // avg_over_time(
  1403. // DCGM_FI_DEV_DEC_UTIL{
  1404. // container!="",
  1405. // <some_custom_filter>
  1406. // }[1h]
  1407. // )
  1408. // ) by (container, pod, namespace, device, modelName, UUID, cluster_id)
  1409. func NewGPUInfoMetricCollector() *metric.MetricCollector {
  1410. return metric.NewMetricCollector(
  1411. metric.GPUInfoID,
  1412. metric.DCGMFIDEVDECUTIL,
  1413. []string{
  1414. source.NamespaceLabel,
  1415. source.PodLabel,
  1416. source.PodUIDLabel,
  1417. source.ContainerLabel,
  1418. source.DeviceLabel,
  1419. source.ModelNameLabel,
  1420. source.UUIDLabel,
  1421. },
  1422. aggregator.Info,
  1423. func(labels map[string]string) bool {
  1424. return labels[source.ContainerLabel] != ""
  1425. },
  1426. )
  1427. }
  1428. func NewDCGMInfoMetricCollector() *metric.MetricCollector {
  1429. return metric.NewMetricCollector(
  1430. metric.DCGMInfoID,
  1431. metric.DCGMFIDEVDECUTIL,
  1432. []string{
  1433. source.UUIDLabel,
  1434. },
  1435. aggregator.Info,
  1436. nil,
  1437. )
  1438. }
  1439. func NewDCGMUptimeMetricCollector() *metric.MetricCollector {
  1440. return metric.NewMetricCollector(
  1441. metric.DCGMUptimeID,
  1442. metric.DCGMFIDEVDECUTIL,
  1443. []string{
  1444. source.UUIDLabel,
  1445. },
  1446. aggregator.Uptime,
  1447. nil,
  1448. )
  1449. }
  1450. func NewDCGMContainerUsageAvgMetricCollector() *metric.MetricCollector {
  1451. return metric.NewMetricCollector(
  1452. metric.DCGMContainerUsageAvgID,
  1453. metric.DCGMFIPROFGRENGINEACTIVE,
  1454. []string{
  1455. source.UUIDLabel,
  1456. source.PodUIDLabel,
  1457. source.ContainerLabel,
  1458. },
  1459. aggregator.AverageOverTime,
  1460. func(labels map[string]string) bool {
  1461. return labels[source.ContainerLabel] != ""
  1462. },
  1463. )
  1464. }
  1465. func NewDCGMContainerUsageMaxMetricCollector() *metric.MetricCollector {
  1466. return metric.NewMetricCollector(
  1467. metric.DCGMContainerUsageMaxID,
  1468. metric.DCGMFIPROFGRENGINEACTIVE,
  1469. []string{
  1470. source.UUIDLabel,
  1471. source.PodUIDLabel,
  1472. source.ContainerLabel,
  1473. },
  1474. aggregator.MaxOverTime,
  1475. func(labels map[string]string) bool {
  1476. return labels[source.ContainerLabel] != ""
  1477. },
  1478. )
  1479. }
  1480. // avg(
  1481. // avg_over_time(
  1482. // node_cpu_hourly_cost{
  1483. // <some_custom_filter>
  1484. // }[1h]
  1485. // )
  1486. // ) by (node, cluster_id, instance_type, provider_id)
  1487. func NewNodeCPUPricePerHourMetricCollector() *metric.MetricCollector {
  1488. return metric.NewMetricCollector(
  1489. metric.NodeCPUPricePerHourID,
  1490. metric.NodeCPUHourlyCost,
  1491. []string{
  1492. source.NodeLabel,
  1493. source.InstanceTypeLabel,
  1494. source.ProviderIDLabel,
  1495. source.UIDLabel,
  1496. },
  1497. aggregator.AverageOverTime,
  1498. nil,
  1499. )
  1500. }
  1501. // avg(
  1502. // avg_over_time(
  1503. // node_ram_hourly_cost{
  1504. // <some_custom_filter>
  1505. // }[1h]
  1506. // )
  1507. // ) by (node, cluster_id, instance_type, provider_id)
  1508. func NewNodeRAMPricePerGiBHourMetricCollector() *metric.MetricCollector {
  1509. return metric.NewMetricCollector(
  1510. metric.NodeRAMPricePerGiBHourID,
  1511. metric.NodeRAMHourlyCost,
  1512. []string{
  1513. source.NodeLabel,
  1514. source.InstanceTypeLabel,
  1515. source.ProviderIDLabel,
  1516. source.UIDLabel,
  1517. },
  1518. aggregator.AverageOverTime,
  1519. nil,
  1520. )
  1521. }
  1522. // avg(
  1523. // avg_over_time(
  1524. // node_gpu_hourly_cost{
  1525. // <some_custom_filter>
  1526. // }[1h]
  1527. // )
  1528. // ) by (node, cluster_id, instance_type, provider_id)
  1529. func NewNodeGPUPricePerHourMetricCollector() *metric.MetricCollector {
  1530. return metric.NewMetricCollector(
  1531. metric.NodeGPUPricePerHourID,
  1532. metric.NodeGPUHourlyCost,
  1533. []string{
  1534. source.NodeLabel,
  1535. source.InstanceTypeLabel,
  1536. source.ProviderIDLabel,
  1537. source.UIDLabel,
  1538. },
  1539. aggregator.AverageOverTime,
  1540. nil,
  1541. )
  1542. }
  1543. // avg_over_time(
  1544. // kubecost_node_is_spot{
  1545. // <some_custom_filter>
  1546. // }[1h]
  1547. // )
  1548. func NewNodeIsSpotMetricCollector() *metric.MetricCollector {
  1549. return metric.NewMetricCollector(
  1550. metric.NodeIsSpotID,
  1551. metric.KubecostNodeIsSpot,
  1552. []string{
  1553. source.NodeLabel,
  1554. source.ProviderIDLabel,
  1555. source.UIDLabel,
  1556. },
  1557. aggregator.AverageOverTime,
  1558. nil,
  1559. )
  1560. }
  1561. // avg(
  1562. // avg_over_time(
  1563. // pod_pvc_allocation{
  1564. // <some_custom_filter>
  1565. // }[1h]
  1566. // )
  1567. // ) by (persistentvolume, persistentvolumeclaim, pod, namespace, cluster_id)
  1568. func NewPodPVCAllocationMetricCollector() *metric.MetricCollector {
  1569. return metric.NewMetricCollector(
  1570. metric.PodPVCAllocationID,
  1571. metric.PodPVCAllocation,
  1572. []string{
  1573. source.NamespaceLabel,
  1574. source.PodLabel,
  1575. source.UIDLabel,
  1576. source.PVLabel,
  1577. source.PVCLabel,
  1578. },
  1579. aggregator.AverageOverTime,
  1580. nil,
  1581. )
  1582. }
  1583. // avg(
  1584. // avg_over_time(
  1585. // kube_persistentvolumeclaim_resource_requests_storage_bytes{
  1586. // <some_custom_filter>
  1587. // }[1h]
  1588. // )
  1589. // ) by (persistentvolumeclaim, namespace, cluster_id)
  1590. func NewPVCBytesRequestedMetricCollector() *metric.MetricCollector {
  1591. return metric.NewMetricCollector(
  1592. metric.PVCBytesRequestedID,
  1593. metric.KubePersistentVolumeClaimResourceRequestsStorageBytes,
  1594. []string{
  1595. source.NamespaceLabel,
  1596. source.PVCLabel,
  1597. source.UIDLabel,
  1598. },
  1599. aggregator.AverageOverTime,
  1600. nil,
  1601. )
  1602. }
  1603. // avg(
  1604. // avg_over_time(
  1605. // kube_persistentvolume_capacity_bytes{
  1606. // <some_custom_filter>
  1607. // }[1h]
  1608. // )
  1609. // ) by (persistentvolume, cluster_id)
  1610. func NewPVBytesMetricCollector() *metric.MetricCollector {
  1611. return metric.NewMetricCollector(
  1612. metric.PVBytesID,
  1613. metric.KubePersistentVolumeCapacityBytes,
  1614. []string{
  1615. source.PVLabel,
  1616. source.UIDLabel,
  1617. },
  1618. aggregator.AverageOverTime,
  1619. nil,
  1620. )
  1621. }
  1622. // avg(
  1623. // avg_over_time(
  1624. // kubecost_pv_info{
  1625. // <some_custom_filter>
  1626. // }[1h]
  1627. // )
  1628. // ) by (cluster_id, storageclass, persistentvolume, provider_id)
  1629. func NewPVInfoMetricCollector() *metric.MetricCollector {
  1630. return metric.NewMetricCollector(
  1631. metric.PVInfoID,
  1632. metric.KubecostPVInfo,
  1633. []string{
  1634. source.UIDLabel,
  1635. source.PVLabel,
  1636. source.StorageClassLabel,
  1637. source.ProviderIDLabel,
  1638. },
  1639. aggregator.AverageOverTime,
  1640. nil,
  1641. )
  1642. }
  1643. // sum(
  1644. // increase(
  1645. // kubecost_pod_network_egress_bytes_total{
  1646. // internet="false",
  1647. // same_zone="false",
  1648. // same_region="true",
  1649. // <some_custom_filter>
  1650. // }[1h]
  1651. // )
  1652. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1653. //
  1654. func NewNetZoneGiBMetricCollector() *metric.MetricCollector {
  1655. return metric.NewMetricCollector(
  1656. metric.NetZoneGiBID,
  1657. metric.KubecostPodNetworkEgressBytesTotal,
  1658. []string{
  1659. source.NamespaceLabel,
  1660. source.PodNameLabel,
  1661. source.UIDLabel,
  1662. },
  1663. aggregator.Increase,
  1664. func(labels map[string]string) bool {
  1665. return labels[source.InternetLabel] == "false" && labels[source.SameZoneLabel] == "false" && labels[source.SameRegionLabel] == "true"
  1666. },
  1667. )
  1668. }
  1669. // avg(
  1670. // avg_over_time(
  1671. // kubecost_network_zone_egress_cost{
  1672. // <some_custom_filter>
  1673. // }[1h]
  1674. // )
  1675. // ) by (cluster_id)
  1676. //
  1677. func NewNetZonePricePerGiBMetricCollector() *metric.MetricCollector {
  1678. return metric.NewMetricCollector(
  1679. metric.NetZonePricePerGiBID,
  1680. metric.KubecostNetworkZoneEgressCost,
  1681. []string{},
  1682. aggregator.AverageOverTime,
  1683. nil,
  1684. )
  1685. }
  1686. // sum(
  1687. // increase(
  1688. // kubecost_pod_network_egress_bytes_total{
  1689. // internet="false",
  1690. // same_zone="false",
  1691. // same_region="false",
  1692. // <some_custom_filter>
  1693. // }[1h]
  1694. // )
  1695. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1696. func NewNetRegionGiBMetricCollector() *metric.MetricCollector {
  1697. return metric.NewMetricCollector(
  1698. metric.NetRegionGiBID,
  1699. metric.KubecostPodNetworkEgressBytesTotal,
  1700. []string{
  1701. source.NamespaceLabel,
  1702. source.PodNameLabel,
  1703. source.UIDLabel,
  1704. },
  1705. aggregator.Increase,
  1706. func(labels map[string]string) bool {
  1707. return labels[source.InternetLabel] == "false" && labels[source.SameZoneLabel] == "false" && labels[source.SameRegionLabel] == "false"
  1708. },
  1709. )
  1710. }
  1711. // avg(
  1712. // avg_over_time(
  1713. // kubecost_network_region_egress_cost{
  1714. // <some_custom_filter>
  1715. // }[1h]
  1716. // )
  1717. // ) by (cluster_id)
  1718. func NewNetRegionPricePerGiBMetricCollector() *metric.MetricCollector {
  1719. return metric.NewMetricCollector(
  1720. metric.NetRegionPricePerGiBID,
  1721. metric.KubecostNetworkRegionEgressCost,
  1722. []string{},
  1723. aggregator.AverageOverTime,
  1724. nil,
  1725. )
  1726. }
  1727. // sum(
  1728. // increase(
  1729. // kubecost_pod_network_egress_bytes_total{
  1730. // internet="true",
  1731. // <some_custom_filter>
  1732. // }[1h]
  1733. // )
  1734. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1735. func NewNetInternetGiBMetricCollector() *metric.MetricCollector {
  1736. return metric.NewMetricCollector(
  1737. metric.NetInternetGiBID,
  1738. metric.KubecostPodNetworkEgressBytesTotal,
  1739. []string{
  1740. source.NamespaceLabel,
  1741. source.PodNameLabel,
  1742. source.UIDLabel,
  1743. },
  1744. aggregator.Increase,
  1745. func(labels map[string]string) bool {
  1746. return labels[source.InternetLabel] == "true"
  1747. },
  1748. )
  1749. }
  1750. // avg(
  1751. // avg_over_time(
  1752. // kubecost_network_internet_egress_cost{
  1753. // <some_custom_filter>
  1754. // }[1h]
  1755. // )
  1756. // ) by (cluster_id)
  1757. func NewNetInternetPricePerGiBMetricCollector() *metric.MetricCollector {
  1758. return metric.NewMetricCollector(
  1759. metric.NetInternetPricePerGiBID,
  1760. metric.KubecostNetworkInternetEgressCost,
  1761. []string{},
  1762. aggregator.AverageOverTime,
  1763. nil,
  1764. )
  1765. }
  1766. // sum(
  1767. // increase(
  1768. // kubecost_pod_network_egress_bytes_total{
  1769. // internet="true",
  1770. // <some_custom_filter>
  1771. // }[%s]
  1772. // )
  1773. // ) by (pod_name, namespace, service, %s) / 1024 / 1024 / 1024
  1774. func NewNetInternetServiceGiBMetricCollector() *metric.MetricCollector {
  1775. return metric.NewMetricCollector(
  1776. metric.NetInternetServiceGiBID,
  1777. metric.KubecostPodNetworkEgressBytesTotal,
  1778. []string{
  1779. source.NamespaceLabel,
  1780. source.PodNameLabel,
  1781. source.ServiceLabel,
  1782. source.UIDLabel,
  1783. },
  1784. aggregator.Increase,
  1785. func(labels map[string]string) bool {
  1786. return labels[source.InternetLabel] == "true"
  1787. },
  1788. )
  1789. }
  1790. // sum(
  1791. // increase(
  1792. // kubecost_pod_network_egress_bytes_total{
  1793. // nat_gateway="true",
  1794. // <some_custom_filter>
  1795. // }[1h]
  1796. // )
  1797. // ) by (pod_name, namespace, uid, cluster_id) / 1024 / 1024 / 1024
  1798. func NewNetNatGatewayGiBMetricCollector() *metric.MetricCollector {
  1799. return metric.NewMetricCollector(
  1800. metric.NetNatGatewayGiBID,
  1801. metric.KubecostPodNetworkEgressBytesTotal,
  1802. []string{
  1803. source.NamespaceLabel,
  1804. source.PodNameLabel,
  1805. source.UIDLabel,
  1806. },
  1807. aggregator.Increase,
  1808. func(labels map[string]string) bool {
  1809. natLabel, labelExists := labels[source.NatGatewayLabel]
  1810. return labelExists && natLabel == "true"
  1811. },
  1812. )
  1813. }
  1814. // avg(
  1815. // avg_over_time(
  1816. // kubecost_network_nat_gateway_egress_cost{
  1817. // <some_custom_filter>
  1818. // }[1h]
  1819. // )
  1820. // ) by (cluster_id)
  1821. func NewNetNatGatewayPricePerGiBMetricCollector() *metric.MetricCollector {
  1822. return metric.NewMetricCollector(
  1823. metric.NetNatGatewayPricePerGiBID,
  1824. metric.KubecostNetworkNatGatewayEgressCost,
  1825. []string{},
  1826. aggregator.AverageOverTime,
  1827. nil,
  1828. )
  1829. }
  1830. // sum(
  1831. // increase(
  1832. // container_network_receive_bytes_total{
  1833. // pod!="",
  1834. // <some_custom_filter>
  1835. // }[1h]
  1836. // )
  1837. // ) by (pod_name, pod, namespace, cluster_id)
  1838. func NewNetReceiveBytesMetricCollector() *metric.MetricCollector {
  1839. return metric.NewMetricCollector(
  1840. metric.NetReceiveBytesID,
  1841. metric.ContainerNetworkReceiveBytesTotal,
  1842. []string{
  1843. source.NamespaceLabel,
  1844. source.PodLabel,
  1845. source.UIDLabel,
  1846. },
  1847. aggregator.Increase,
  1848. func(labels map[string]string) bool {
  1849. return labels[source.PodLabel] != ""
  1850. },
  1851. )
  1852. }
  1853. // sum(
  1854. // increase(
  1855. // kubecost_pod_network_ingress_bytes_total{
  1856. // internet="false",
  1857. // same_zone="false",
  1858. // same_region="true",
  1859. // <some_custom_filter>
  1860. // }[1h]
  1861. // )
  1862. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1863. func NewNetZoneIngressGiBMetricCollector() *metric.MetricCollector {
  1864. return metric.NewMetricCollector(
  1865. metric.NetZoneIngressGiBID,
  1866. metric.KubecostPodNetworkIngressBytesTotal,
  1867. []string{
  1868. source.NamespaceLabel,
  1869. source.PodNameLabel,
  1870. source.UIDLabel,
  1871. },
  1872. aggregator.Increase,
  1873. func(labels map[string]string) bool {
  1874. return labels[source.InternetLabel] == "false" &&
  1875. labels[source.SameZoneLabel] == "false" &&
  1876. labels[source.SameRegionLabel] == "true"
  1877. },
  1878. )
  1879. }
  1880. // sum(
  1881. // increase(
  1882. // kubecost_pod_network_ingress_bytes_total{
  1883. // internet="false",
  1884. // same_zone="false",
  1885. // same_region="false",
  1886. // <some_custom_filter>
  1887. // }[1h]
  1888. // )
  1889. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1890. func NewNetRegionIngressGiBMetricCollector() *metric.MetricCollector {
  1891. return metric.NewMetricCollector(
  1892. metric.NetRegionIngressGiBID,
  1893. metric.KubecostPodNetworkIngressBytesTotal,
  1894. []string{
  1895. source.NamespaceLabel,
  1896. source.PodNameLabel,
  1897. source.UIDLabel,
  1898. },
  1899. aggregator.Increase,
  1900. func(labels map[string]string) bool {
  1901. return labels[source.InternetLabel] == "false" &&
  1902. labels[source.SameZoneLabel] == "false" &&
  1903. labels[source.SameRegionLabel] == "false"
  1904. },
  1905. )
  1906. }
  1907. // sum(
  1908. // increase(
  1909. // kubecost_pod_network_ingress_bytes_total{
  1910. // internet="true",
  1911. // <some_custom_filter>
  1912. // }[1h]
  1913. // )
  1914. // ) by (pod_name, namespace, cluster_id) / 1024 / 1024 / 1024
  1915. func NewNetInternetIngressGiBMetricCollector() *metric.MetricCollector {
  1916. return metric.NewMetricCollector(
  1917. metric.NetInternetIngressGiBID,
  1918. metric.KubecostPodNetworkIngressBytesTotal,
  1919. []string{
  1920. source.NamespaceLabel,
  1921. source.PodNameLabel,
  1922. source.UIDLabel,
  1923. },
  1924. aggregator.Increase,
  1925. func(labels map[string]string) bool {
  1926. return labels[source.InternetLabel] == "true"
  1927. },
  1928. )
  1929. }
  1930. // `sum(
  1931. // increase(
  1932. // kubecost_pod_network_ingress_bytes_total{
  1933. // internet="true",
  1934. // <some_custom_filter>
  1935. // }[1h]
  1936. // )
  1937. // ) by (pod_name, namespace, service, cluster_id) / 1024 / 1024 / 1024
  1938. func NewNetInternetServiceIngressGiBMetricCollector() *metric.MetricCollector {
  1939. return metric.NewMetricCollector(
  1940. metric.NetInternetServiceIngressGiBID,
  1941. metric.KubecostPodNetworkIngressBytesTotal,
  1942. []string{
  1943. source.NamespaceLabel,
  1944. source.PodNameLabel,
  1945. source.ServiceLabel,
  1946. source.UIDLabel,
  1947. },
  1948. aggregator.Increase,
  1949. func(labels map[string]string) bool {
  1950. return labels[source.InternetLabel] == "true"
  1951. },
  1952. )
  1953. }
  1954. // avg(
  1955. // avg_over_time(
  1956. // kubecost_network_nat_gateway_ingress_cost{
  1957. // <some_custom_filter>
  1958. // }[1h]
  1959. // )
  1960. // ) by (cluster_id)
  1961. func NewNetNatGatewayIngressPricePerGiBMetricCollector() *metric.MetricCollector {
  1962. return metric.NewMetricCollector(
  1963. metric.NetNatGatewayIngressPricePerGiBID,
  1964. metric.KubecostNetworkNatGatewayIngressCost,
  1965. []string{},
  1966. aggregator.AverageOverTime,
  1967. nil,
  1968. )
  1969. }
  1970. // sum(
  1971. // increase(
  1972. // kubecost_pod_network_ingress_bytes_total{
  1973. // nat_gateway="true",
  1974. // <some_custom_filter>
  1975. // }[1h]
  1976. // )
  1977. // ) by (pod_name, namespace, uid, cluster_id) / 1024 / 1024 / 1024
  1978. func NewNetNatGatewayIngressGiBMetricCollector() *metric.MetricCollector {
  1979. return metric.NewMetricCollector(
  1980. metric.NetNatGatewayIngressGiBID,
  1981. metric.KubecostPodNetworkIngressBytesTotal,
  1982. []string{
  1983. source.NamespaceLabel,
  1984. source.PodNameLabel,
  1985. source.UIDLabel,
  1986. },
  1987. aggregator.Increase,
  1988. func(labels map[string]string) bool {
  1989. natLabel, labelExists := labels[source.NatGatewayLabel]
  1990. return labelExists && natLabel == "true"
  1991. },
  1992. )
  1993. }
  1994. // sum(
  1995. // increase(
  1996. // container_network_transmit_bytes_total{
  1997. // pod!="",
  1998. // <some_custom_filter>
  1999. // }[1h]
  2000. // )
  2001. // ) by (pod_name, pod, namespace, cluster_id)
  2002. func NewNetTransferBytesMetricCollector() *metric.MetricCollector {
  2003. return metric.NewMetricCollector(
  2004. metric.NetTransferBytesID,
  2005. metric.ContainerNetworkTransmitBytesTotal,
  2006. []string{
  2007. source.NamespaceLabel,
  2008. source.PodLabel,
  2009. source.UIDLabel,
  2010. },
  2011. aggregator.Increase,
  2012. func(labels map[string]string) bool {
  2013. return labels[source.PodLabel] != ""
  2014. },
  2015. )
  2016. }
  2017. func NewNamespaceInfoMetricCollector() *metric.MetricCollector {
  2018. return metric.NewMetricCollector(
  2019. metric.NamespaceInfoID,
  2020. metric.NamespaceInfo,
  2021. []string{
  2022. source.UIDLabel,
  2023. },
  2024. aggregator.Info,
  2025. nil,
  2026. )
  2027. }
  2028. // avg(
  2029. // namespace_info{
  2030. // <some_custom_filter>
  2031. // }
  2032. // ) by (uid)[%s:%dm]
  2033. func NewNamespaceUptimeMetricCollector() *metric.MetricCollector {
  2034. return metric.NewMetricCollector(
  2035. metric.NamespaceUptimeID,
  2036. metric.NamespaceInfo,
  2037. []string{
  2038. source.UIDLabel,
  2039. },
  2040. aggregator.Uptime,
  2041. nil,
  2042. )
  2043. }
  2044. // avg_over_time(
  2045. // kube_namespace_labels{
  2046. // <some_custom_filter>
  2047. // }[1h]
  2048. // )
  2049. func NewNamespaceLabelsMetricCollector() *metric.MetricCollector {
  2050. return metric.NewMetricCollector(
  2051. metric.NamespaceLabelsID,
  2052. metric.KubeNamespaceLabels,
  2053. []string{
  2054. source.NamespaceLabel,
  2055. source.UIDLabel,
  2056. },
  2057. aggregator.Info,
  2058. nil,
  2059. )
  2060. }
  2061. // avg_over_time(
  2062. // kube_namespace_annotations{
  2063. // <some_custom_filter>
  2064. // }[1h]
  2065. // )
  2066. func NewNamespaceAnnotationsMetricCollector() *metric.MetricCollector {
  2067. return metric.NewMetricCollector(
  2068. metric.NamespaceAnnotationsID,
  2069. metric.KubeNamespaceAnnotations,
  2070. []string{
  2071. source.NamespaceLabel,
  2072. source.UIDLabel,
  2073. },
  2074. aggregator.Info,
  2075. nil,
  2076. )
  2077. }
  2078. // avg_over_time(
  2079. // kube_pod_labels{
  2080. // <some_custom_filter>
  2081. // }[1h]
  2082. // )
  2083. func NewPodLabelsMetricCollector() *metric.MetricCollector {
  2084. return metric.NewMetricCollector(
  2085. metric.PodLabelsID,
  2086. metric.KubePodLabels,
  2087. []string{
  2088. source.NamespaceLabel,
  2089. source.PodLabel,
  2090. source.UIDLabel,
  2091. },
  2092. aggregator.Info,
  2093. nil,
  2094. )
  2095. }
  2096. // avg_over_time(
  2097. // kube_pod_annotations{
  2098. // <some_custom_filter>
  2099. // }[1h]
  2100. // )
  2101. func NewPodAnnotationsMetricCollector() *metric.MetricCollector {
  2102. return metric.NewMetricCollector(
  2103. metric.PodAnnotationsID,
  2104. metric.KubePodAnnotations,
  2105. []string{
  2106. source.NamespaceLabel,
  2107. source.PodLabel,
  2108. source.UIDLabel,
  2109. },
  2110. aggregator.Info,
  2111. nil,
  2112. )
  2113. }
  2114. func NewServiceInfoMetricCollector() *metric.MetricCollector {
  2115. return metric.NewMetricCollector(
  2116. metric.ServiceInfoID,
  2117. metric.ServiceInfo,
  2118. []string{
  2119. source.UIDLabel,
  2120. },
  2121. aggregator.Info,
  2122. nil,
  2123. )
  2124. }
  2125. func NewServiceUptimeMetricCollector() *metric.MetricCollector {
  2126. return metric.NewMetricCollector(
  2127. metric.ServiceUptimeID,
  2128. metric.ServiceInfo,
  2129. []string{
  2130. source.UIDLabel,
  2131. },
  2132. aggregator.Uptime,
  2133. nil,
  2134. )
  2135. }
  2136. // avg_over_time(
  2137. // service_selector_labels{
  2138. // <some_custom_filter>
  2139. // }[1h]
  2140. // )
  2141. func NewServiceLabelsMetricCollector() *metric.MetricCollector {
  2142. return metric.NewMetricCollector(
  2143. metric.ServiceLabelsID,
  2144. metric.ServiceSelectorLabels,
  2145. []string{
  2146. source.NamespaceLabel,
  2147. source.ServiceLabel,
  2148. source.UIDLabel,
  2149. },
  2150. aggregator.Info,
  2151. nil,
  2152. )
  2153. }
  2154. // avg_over_time(
  2155. // deployment_match_labels{
  2156. // <some_custom_filter>
  2157. // }[1h]
  2158. // )
  2159. func NewDeploymentInfoMetricCollector() *metric.MetricCollector {
  2160. return metric.NewMetricCollector(
  2161. metric.DeploymentInfoID,
  2162. metric.DeploymentInfo,
  2163. []string{
  2164. source.UIDLabel,
  2165. },
  2166. aggregator.Info,
  2167. nil,
  2168. )
  2169. }
  2170. func NewDeploymentUptimeMetricCollector() *metric.MetricCollector {
  2171. return metric.NewMetricCollector(
  2172. metric.DeploymentUptimeID,
  2173. metric.DeploymentInfo,
  2174. []string{
  2175. source.UIDLabel,
  2176. source.NamespaceUIDLabel,
  2177. source.DeploymentLabel,
  2178. },
  2179. aggregator.Uptime,
  2180. nil,
  2181. )
  2182. }
  2183. func NewDeploymentLabelsMetricCollector() *metric.MetricCollector {
  2184. return metric.NewMetricCollector(
  2185. metric.DeploymentLabelsID,
  2186. metric.DeploymentLabels,
  2187. []string{
  2188. source.UIDLabel,
  2189. },
  2190. aggregator.Info,
  2191. nil,
  2192. )
  2193. }
  2194. func NewDeploymentAnnotationsMetricCollector() *metric.MetricCollector {
  2195. return metric.NewMetricCollector(
  2196. metric.DeploymentAnnotationsID,
  2197. metric.DeploymentAnnotations,
  2198. []string{
  2199. source.UIDLabel,
  2200. },
  2201. aggregator.Info,
  2202. nil,
  2203. )
  2204. }
  2205. func NewDeploymentMatchLabelsMetricCollector() *metric.MetricCollector {
  2206. return metric.NewMetricCollector(
  2207. metric.DeploymentMatchLabelsID,
  2208. metric.DeploymentMatchLabels,
  2209. []string{
  2210. source.NamespaceLabel,
  2211. source.DeploymentLabel,
  2212. source.UIDLabel,
  2213. },
  2214. aggregator.Info,
  2215. nil,
  2216. )
  2217. }
  2218. func NewStatefulSetInfoMetricCollector() *metric.MetricCollector {
  2219. return metric.NewMetricCollector(
  2220. metric.StatefulSetInfoID,
  2221. metric.StatefulSetInfo,
  2222. []string{
  2223. source.UIDLabel,
  2224. source.NamespaceUIDLabel,
  2225. source.StatefulSetLabel,
  2226. },
  2227. aggregator.Info,
  2228. nil,
  2229. )
  2230. }
  2231. func NewStatefulSetUptimeMetricCollector() *metric.MetricCollector {
  2232. return metric.NewMetricCollector(
  2233. metric.StatefulSetUptimeID,
  2234. metric.StatefulSetInfo,
  2235. []string{
  2236. source.UIDLabel,
  2237. },
  2238. aggregator.Uptime,
  2239. nil,
  2240. )
  2241. }
  2242. func NewStatefulSetLabelsMetricCollector() *metric.MetricCollector {
  2243. return metric.NewMetricCollector(
  2244. metric.StatefulSetLabelsID,
  2245. metric.StatefulSetLabels,
  2246. []string{
  2247. source.UIDLabel,
  2248. },
  2249. aggregator.Info,
  2250. nil,
  2251. )
  2252. }
  2253. func NewStatefulSetAnnotationsMetricCollector() *metric.MetricCollector {
  2254. return metric.NewMetricCollector(
  2255. metric.StatefulSetAnnotationsID,
  2256. metric.StatefulSetAnnotations,
  2257. []string{
  2258. source.UIDLabel,
  2259. },
  2260. aggregator.Info,
  2261. nil,
  2262. )
  2263. }
  2264. // avg_over_time(
  2265. // statefulSet_match_labels{
  2266. // <some_custom_filter>
  2267. // }[1h]
  2268. // )
  2269. func NewStatefulSetMatchLabelsMetricCollector() *metric.MetricCollector {
  2270. return metric.NewMetricCollector(
  2271. metric.StatefulSetMatchLabelsID,
  2272. metric.StatefulSetMatchLabels,
  2273. []string{
  2274. source.UIDLabel,
  2275. },
  2276. aggregator.Info,
  2277. nil,
  2278. )
  2279. }
  2280. func NewDaemonSetInfoMetricCollector() *metric.MetricCollector {
  2281. return metric.NewMetricCollector(
  2282. metric.DaemonSetInfoID,
  2283. metric.DaemonSetInfo,
  2284. []string{
  2285. source.UIDLabel,
  2286. },
  2287. aggregator.Info,
  2288. nil,
  2289. )
  2290. }
  2291. func NewDaemonSetUptimeMetricCollector() *metric.MetricCollector {
  2292. return metric.NewMetricCollector(
  2293. metric.DaemonSetUptimeID,
  2294. metric.DaemonSetInfo,
  2295. []string{
  2296. source.UIDLabel,
  2297. },
  2298. aggregator.Uptime,
  2299. nil,
  2300. )
  2301. }
  2302. func NewDaemonSetLabelsMetricCollector() *metric.MetricCollector {
  2303. return metric.NewMetricCollector(
  2304. metric.DaemonSetLabelsID,
  2305. metric.DaemonSetLabels,
  2306. []string{
  2307. source.UIDLabel,
  2308. },
  2309. aggregator.Info,
  2310. nil,
  2311. )
  2312. }
  2313. func NewDaemonSetAnnotationsMetricCollector() *metric.MetricCollector {
  2314. return metric.NewMetricCollector(
  2315. metric.DaemonSetAnnotationsID,
  2316. metric.DaemonSetAnnotations,
  2317. []string{
  2318. source.UIDLabel,
  2319. },
  2320. aggregator.Info,
  2321. nil,
  2322. )
  2323. }
  2324. func NewJobInfoMetricCollector() *metric.MetricCollector {
  2325. return metric.NewMetricCollector(
  2326. metric.JobInfoID,
  2327. metric.JobInfo,
  2328. []string{
  2329. source.UIDLabel,
  2330. },
  2331. aggregator.Info,
  2332. nil,
  2333. )
  2334. }
  2335. func NewJobUptimeMetricCollector() *metric.MetricCollector {
  2336. return metric.NewMetricCollector(
  2337. metric.JobUptimeID,
  2338. metric.JobInfo,
  2339. []string{
  2340. source.UIDLabel,
  2341. },
  2342. aggregator.Uptime,
  2343. nil,
  2344. )
  2345. }
  2346. func NewJobLabelsMetricCollector() *metric.MetricCollector {
  2347. return metric.NewMetricCollector(
  2348. metric.JobLabelsID,
  2349. metric.JobLabels,
  2350. []string{
  2351. source.NamespaceLabel,
  2352. source.JobLabel,
  2353. source.UIDLabel,
  2354. },
  2355. aggregator.Info,
  2356. nil,
  2357. )
  2358. }
  2359. func NewJobAnnotationsMetricCollector() *metric.MetricCollector {
  2360. return metric.NewMetricCollector(
  2361. metric.JobAnnotationsID,
  2362. metric.JobAnnotations,
  2363. []string{
  2364. source.NamespaceLabel,
  2365. source.JobLabel,
  2366. source.UIDLabel,
  2367. },
  2368. aggregator.Info,
  2369. nil,
  2370. )
  2371. }
  2372. func NewCronJobInfoMetricCollector() *metric.MetricCollector {
  2373. return metric.NewMetricCollector(
  2374. metric.CronJobInfoID,
  2375. metric.CronJobInfo,
  2376. []string{
  2377. source.UIDLabel,
  2378. source.NamespaceUIDLabel,
  2379. source.CronJobLabel,
  2380. },
  2381. aggregator.Info,
  2382. nil,
  2383. )
  2384. }
  2385. func NewCronJobUptimeMetricCollector() *metric.MetricCollector {
  2386. return metric.NewMetricCollector(
  2387. metric.CronJobUptimeID,
  2388. metric.CronJobInfo,
  2389. []string{
  2390. source.UIDLabel,
  2391. },
  2392. aggregator.Uptime,
  2393. nil,
  2394. )
  2395. }
  2396. func NewCronJobLabelsMetricCollector() *metric.MetricCollector {
  2397. return metric.NewMetricCollector(
  2398. metric.CronJobLabelsID,
  2399. metric.CronJobLabels,
  2400. []string{
  2401. source.NamespaceLabel,
  2402. source.CronJobLabel,
  2403. source.UIDLabel,
  2404. },
  2405. aggregator.Info,
  2406. nil,
  2407. )
  2408. }
  2409. func NewCronJobAnnotationsMetricCollector() *metric.MetricCollector {
  2410. return metric.NewMetricCollector(
  2411. metric.CronJobAnnotationsID,
  2412. metric.CronJobAnnotations,
  2413. []string{
  2414. source.NamespaceLabel,
  2415. source.CronJobLabel,
  2416. source.UIDLabel,
  2417. },
  2418. aggregator.Info,
  2419. nil,
  2420. )
  2421. }
  2422. func NewReplicaSetInfoMetricCollector() *metric.MetricCollector {
  2423. return metric.NewMetricCollector(
  2424. metric.ReplicaSetInfoID,
  2425. metric.ReplicaSetInfo,
  2426. []string{
  2427. source.UIDLabel,
  2428. source.NamespaceUIDLabel,
  2429. source.ReplicaSetLabel,
  2430. },
  2431. aggregator.Info,
  2432. nil,
  2433. )
  2434. }
  2435. func NewReplicaSetUptimeMetricCollector() *metric.MetricCollector {
  2436. return metric.NewMetricCollector(
  2437. metric.ReplicaSetUptimeID,
  2438. metric.ReplicaSetInfo,
  2439. []string{
  2440. source.UIDLabel,
  2441. },
  2442. aggregator.Uptime,
  2443. nil,
  2444. )
  2445. }
  2446. func NewReplicaSetLabelsMetricCollector() *metric.MetricCollector {
  2447. return metric.NewMetricCollector(
  2448. metric.ReplicaSetLabelsID,
  2449. metric.ReplicaSetLabels,
  2450. []string{
  2451. source.NamespaceLabel,
  2452. source.ReplicaSetLabel,
  2453. source.UIDLabel,
  2454. },
  2455. aggregator.Info,
  2456. nil,
  2457. )
  2458. }
  2459. func NewReplicaSetAnnotationsMetricCollector() *metric.MetricCollector {
  2460. return metric.NewMetricCollector(
  2461. metric.ReplicaSetAnnotationsID,
  2462. metric.ReplicaSetAnnotations,
  2463. []string{
  2464. source.NamespaceLabel,
  2465. source.ReplicaSetLabel,
  2466. source.UIDLabel,
  2467. },
  2468. aggregator.Info,
  2469. nil,
  2470. )
  2471. }
  2472. func NewReplicaSetOwnerMetricCollector() *metric.MetricCollector {
  2473. return metric.NewMetricCollector(
  2474. metric.ReplicaSetOwnerID,
  2475. metric.KubeReplicasetOwner,
  2476. []string{
  2477. source.UIDLabel,
  2478. source.OwnerUIDLabel,
  2479. source.OwnerKindLabel,
  2480. },
  2481. aggregator.Info,
  2482. nil,
  2483. )
  2484. }
  2485. // sum(
  2486. // avg_over_time(
  2487. // kube_pod_owner{
  2488. // owner_kind="DaemonSet",
  2489. // <some_custom_filter>
  2490. // }[1h]
  2491. // )
  2492. // ) by (pod, owner_name, namespace, cluster_id)
  2493. func NewPodsWithDaemonSetOwnerMetricCollector() *metric.MetricCollector {
  2494. return metric.NewMetricCollector(
  2495. metric.PodsWithDaemonSetOwnerID,
  2496. metric.KubePodOwner,
  2497. []string{
  2498. source.NamespaceLabel,
  2499. source.PodLabel,
  2500. source.UIDLabel,
  2501. source.OwnerNameLabel,
  2502. },
  2503. aggregator.Info,
  2504. func(labels map[string]string) bool {
  2505. return labels[source.OwnerKindLabel] == "DaemonSet"
  2506. },
  2507. )
  2508. }
  2509. // sum(
  2510. // avg_over_time(
  2511. // kube_pod_owner{
  2512. // owner_kind="Job",
  2513. // <some_custom_filter>
  2514. // }[1h]
  2515. // )
  2516. // ) by (pod, owner_name, namespace, cluster_id)
  2517. func NewPodsWithJobOwnerMetricCollector() *metric.MetricCollector {
  2518. return metric.NewMetricCollector(
  2519. metric.PodsWithJobOwnerID,
  2520. metric.KubePodOwner,
  2521. []string{
  2522. source.NamespaceLabel,
  2523. source.PodLabel,
  2524. source.UIDLabel,
  2525. source.OwnerNameLabel,
  2526. },
  2527. aggregator.Info,
  2528. func(labels map[string]string) bool {
  2529. return labels[source.OwnerKindLabel] == "Job"
  2530. },
  2531. )
  2532. }
  2533. // sum(
  2534. // avg_over_time(
  2535. // kube_pod_owner{
  2536. // owner_kind="ReplicaSet",
  2537. // <some_custom_filter>
  2538. // }[1h]
  2539. // )
  2540. // ) by (pod, owner_name, namespace, cluster_id)
  2541. func NewPodsWithReplicaSetOwnerMetricCollector() *metric.MetricCollector {
  2542. return metric.NewMetricCollector(
  2543. metric.PodsWithReplicaSetOwnerID,
  2544. metric.KubePodOwner,
  2545. []string{
  2546. source.NamespaceLabel,
  2547. source.PodLabel,
  2548. source.UIDLabel,
  2549. source.OwnerNameLabel,
  2550. },
  2551. aggregator.Info,
  2552. func(labels map[string]string) bool {
  2553. return labels[source.OwnerKindLabel] == "ReplicaSet"
  2554. },
  2555. )
  2556. }
  2557. // sum(
  2558. // avg_over_time(
  2559. // kube_replicaset_owner{
  2560. // owner_kind="<none>",
  2561. // owner_name="<none>",
  2562. // <some_custom_filter>
  2563. // }[1h]
  2564. // )
  2565. // ) by (replicaset, namespace, cluster_id)
  2566. func NewReplicaSetsWithoutOwnersMetricCollector() *metric.MetricCollector {
  2567. return metric.NewMetricCollector(
  2568. metric.ReplicaSetsWithoutOwnersID,
  2569. metric.KubeReplicasetOwner,
  2570. []string{
  2571. source.NamespaceLabel,
  2572. source.ReplicaSetLabel,
  2573. source.UIDLabel,
  2574. },
  2575. aggregator.Info,
  2576. func(labels map[string]string) bool {
  2577. return labels[source.OwnerKindLabel] == "<none>" && labels[source.OwnerNameLabel] == "<none>"
  2578. },
  2579. )
  2580. }
  2581. // sum(
  2582. // avg_over_time(
  2583. // kube_replicaset_owner{
  2584. // owner_kind="Rollout",
  2585. // <some_custom_filter>
  2586. // }[1h]
  2587. // )
  2588. // ) by (replicaset, namespace, owner_kind, owner_name, cluster_id)
  2589. func NewReplicaSetsWithRolloutMetricCollector() *metric.MetricCollector {
  2590. return metric.NewMetricCollector(
  2591. metric.ReplicaSetsWithRolloutID,
  2592. metric.KubeReplicasetOwner,
  2593. []string{
  2594. source.NamespaceLabel,
  2595. source.ReplicaSetLabel,
  2596. source.UIDLabel,
  2597. source.OwnerNameLabel,
  2598. source.OwnerKindLabel,
  2599. },
  2600. aggregator.Info,
  2601. func(labels map[string]string) bool {
  2602. return labels[source.OwnerKindLabel] == "Rollout"
  2603. },
  2604. )
  2605. }
  2606. func NewResourceQuotaInfoMetricCollector() *metric.MetricCollector {
  2607. return metric.NewMetricCollector(
  2608. metric.ResourceQuotaInfoID,
  2609. metric.ResourceQuotaInfo,
  2610. []string{
  2611. source.UIDLabel,
  2612. },
  2613. aggregator.Info,
  2614. nil,
  2615. )
  2616. }
  2617. // avg(
  2618. // resourcequota_info{
  2619. // <some_custom_filter>
  2620. // }
  2621. // ) by (uid)[%s:%dm]
  2622. func NewResourceQuotaUptimeMetricCollector() *metric.MetricCollector {
  2623. return metric.NewMetricCollector(
  2624. metric.ResourceQuotaUptimeID,
  2625. metric.ResourceQuotaInfo,
  2626. []string{
  2627. source.UIDLabel,
  2628. },
  2629. aggregator.Uptime,
  2630. nil,
  2631. )
  2632. }
  2633. func NewResourceQuotaSpecCPURequestAverageMetricCollector() *metric.MetricCollector {
  2634. return metric.NewMetricCollector(
  2635. metric.ResourceQuotaSpecCPURequestAverageID,
  2636. metric.KubeResourceQuotaSpecResourceRequests,
  2637. []string{
  2638. source.NamespaceLabel,
  2639. source.ResourceQuotaLabel,
  2640. source.UIDLabel,
  2641. },
  2642. aggregator.AverageOverTime,
  2643. func(labels map[string]string) bool {
  2644. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2645. },
  2646. )
  2647. }
  2648. // max(
  2649. // max_over_time(
  2650. // resourcequota_spec_resource_requests{
  2651. // resource="cpu",
  2652. // unit="core",
  2653. // <some_custom_filter>
  2654. // }[1h]
  2655. // )
  2656. //) by (resourcequota, namespace, uid, cluster_id)
  2657. func NewResourceQuotaSpecCPURequestMaxMetricCollector() *metric.MetricCollector {
  2658. return metric.NewMetricCollector(
  2659. metric.ResourceQuotaSpecCPURequestMaxID,
  2660. metric.KubeResourceQuotaSpecResourceRequests,
  2661. []string{
  2662. source.NamespaceLabel,
  2663. source.ResourceQuotaLabel,
  2664. source.UIDLabel,
  2665. },
  2666. aggregator.MaxOverTime,
  2667. func(labels map[string]string) bool {
  2668. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2669. },
  2670. )
  2671. }
  2672. // avg(
  2673. // avg_over_time(
  2674. // resourcequota_spec_resource_requests{
  2675. // resource="memory",
  2676. // unit="byte",
  2677. // <some_custom_filter>
  2678. // }[1h]
  2679. // )
  2680. //) by (resourcequota, namespace, uid, cluster_id)
  2681. func NewResourceQuotaSpecRAMRequestAverageMetricCollector() *metric.MetricCollector {
  2682. return metric.NewMetricCollector(
  2683. metric.ResourceQuotaSpecRAMRequestAverageID,
  2684. metric.KubeResourceQuotaSpecResourceRequests,
  2685. []string{
  2686. source.NamespaceLabel,
  2687. source.ResourceQuotaLabel,
  2688. source.UIDLabel,
  2689. },
  2690. aggregator.AverageOverTime,
  2691. func(labels map[string]string) bool {
  2692. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2693. },
  2694. )
  2695. }
  2696. // max(
  2697. // max_over_time(
  2698. // resourcequota_spec_resource_requests{
  2699. // resource="memory",
  2700. // unit="byte",
  2701. // <some_custom_filter>
  2702. // }[1h]
  2703. // )
  2704. //) by (resourcequota, namespace, uid, cluster_id)
  2705. func NewResourceQuotaSpecRAMRequestMaxMetricCollector() *metric.MetricCollector {
  2706. return metric.NewMetricCollector(
  2707. metric.ResourceQuotaSpecRAMRequestMaxID,
  2708. metric.KubeResourceQuotaSpecResourceRequests,
  2709. []string{
  2710. source.NamespaceLabel,
  2711. source.ResourceQuotaLabel,
  2712. source.UIDLabel,
  2713. },
  2714. aggregator.MaxOverTime,
  2715. func(labels map[string]string) bool {
  2716. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2717. },
  2718. )
  2719. }
  2720. // avg(
  2721. // avg_over_time(
  2722. // resourcequota_spec_resource_limits{
  2723. // resource="cpu",
  2724. // unit="core",
  2725. // <some_custom_filter>
  2726. // }[1h]
  2727. // )
  2728. //) by (resourcequota, namespace, uid, cluster_id)
  2729. func NewResourceQuotaSpecCPULimitAverageMetricCollector() *metric.MetricCollector {
  2730. return metric.NewMetricCollector(
  2731. metric.ResourceQuotaSpecCPULimitAverageID,
  2732. metric.KubeResourceQuotaSpecResourceLimits,
  2733. []string{
  2734. source.NamespaceLabel,
  2735. source.ResourceQuotaLabel,
  2736. source.UIDLabel,
  2737. },
  2738. aggregator.AverageOverTime,
  2739. func(labels map[string]string) bool {
  2740. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2741. },
  2742. )
  2743. }
  2744. // max(
  2745. // max_over_time(
  2746. // resourcequota_spec_resource_limits{
  2747. // resource="cpu",
  2748. // unit="core",
  2749. // <some_custom_filter>
  2750. // }[1h]
  2751. // )
  2752. //) by (resourcequota, namespace, uid, cluster_id)
  2753. func NewResourceQuotaSpecCPULimitMaxMetricCollector() *metric.MetricCollector {
  2754. return metric.NewMetricCollector(
  2755. metric.ResourceQuotaSpecCPULimitMaxID,
  2756. metric.KubeResourceQuotaSpecResourceLimits,
  2757. []string{
  2758. source.NamespaceLabel,
  2759. source.ResourceQuotaLabel,
  2760. source.UIDLabel,
  2761. },
  2762. aggregator.MaxOverTime,
  2763. func(labels map[string]string) bool {
  2764. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2765. },
  2766. )
  2767. }
  2768. // avg(
  2769. // avg_over_time(
  2770. // resourcequota_spec_resource_limits{
  2771. // resource="memory",
  2772. // unit="byte",
  2773. // <some_custom_filter>
  2774. // }[1h]
  2775. // )
  2776. //) by (resourcequota, namespace, uid, cluster_id)
  2777. func NewResourceQuotaSpecRAMLimitAverageMetricCollector() *metric.MetricCollector {
  2778. return metric.NewMetricCollector(
  2779. metric.ResourceQuotaSpecRAMLimitAverageID,
  2780. metric.KubeResourceQuotaSpecResourceLimits,
  2781. []string{
  2782. source.NamespaceLabel,
  2783. source.ResourceQuotaLabel,
  2784. source.UIDLabel,
  2785. },
  2786. aggregator.AverageOverTime,
  2787. func(labels map[string]string) bool {
  2788. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2789. },
  2790. )
  2791. }
  2792. // max(
  2793. // max_over_time(
  2794. // resourcequota_spec_resource_limits{
  2795. // resource="memory",
  2796. // unit="byte",
  2797. // <some_custom_filter>
  2798. // }[1h]
  2799. // )
  2800. //) by (resourcequota, namespace, uid, cluster_id)
  2801. func NewResourceQuotaSpecRAMLimitMaxMetricCollector() *metric.MetricCollector {
  2802. return metric.NewMetricCollector(
  2803. metric.ResourceQuotaSpecRAMLimitMaxID,
  2804. metric.KubeResourceQuotaSpecResourceLimits,
  2805. []string{
  2806. source.NamespaceLabel,
  2807. source.ResourceQuotaLabel,
  2808. source.UIDLabel,
  2809. },
  2810. aggregator.MaxOverTime,
  2811. func(labels map[string]string) bool {
  2812. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2813. },
  2814. )
  2815. }
  2816. // avg(
  2817. // avg_over_time(
  2818. // resourcequota_status_used_resource_requests{
  2819. // resource="cpu",
  2820. // unit="core",
  2821. // <some_custom_filter>
  2822. // }[1h]
  2823. // )
  2824. //) by (resourcequota, namespace, uid, cluster_id)
  2825. func NewResourceQuotaStatusUsedCPURequestAverageMetricCollector() *metric.MetricCollector {
  2826. return metric.NewMetricCollector(
  2827. metric.ResourceQuotaStatusUsedCPURequestAverageID,
  2828. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2829. []string{
  2830. source.NamespaceLabel,
  2831. source.ResourceQuotaLabel,
  2832. source.UIDLabel,
  2833. },
  2834. aggregator.AverageOverTime,
  2835. func(labels map[string]string) bool {
  2836. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2837. },
  2838. )
  2839. }
  2840. // max(
  2841. // max_over_time(
  2842. // resourcequota_status_used_resource_requests{
  2843. // resource="cpu",
  2844. // unit="core",
  2845. // <some_custom_filter>
  2846. // }[1h]
  2847. // )
  2848. //) by (resourcequota, namespace, uid, cluster_id)
  2849. func NewResourceQuotaStatusUsedCPURequestMaxMetricCollector() *metric.MetricCollector {
  2850. return metric.NewMetricCollector(
  2851. metric.ResourceQuotaStatusUsedCPURequestMaxID,
  2852. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2853. []string{
  2854. source.NamespaceLabel,
  2855. source.ResourceQuotaLabel,
  2856. source.UIDLabel,
  2857. },
  2858. aggregator.MaxOverTime,
  2859. func(labels map[string]string) bool {
  2860. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2861. },
  2862. )
  2863. }
  2864. // avg(
  2865. // avg_over_time(
  2866. // resourcequota_status_used_resource_requests{
  2867. // resource="memory",
  2868. // unit="byte",
  2869. // <some_custom_filter>
  2870. // }[1h]
  2871. // )
  2872. //) by (resourcequota, namespace, uid, cluster_id)
  2873. func NewResourceQuotaStatusUsedRAMRequestAverageMetricCollector() *metric.MetricCollector {
  2874. return metric.NewMetricCollector(
  2875. metric.ResourceQuotaStatusUsedRAMRequestAverageID,
  2876. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2877. []string{
  2878. source.NamespaceLabel,
  2879. source.ResourceQuotaLabel,
  2880. source.UIDLabel,
  2881. },
  2882. aggregator.AverageOverTime,
  2883. func(labels map[string]string) bool {
  2884. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2885. },
  2886. )
  2887. }
  2888. // max(
  2889. // max_over_time(
  2890. // resourcequota_status_used_resource_requests{
  2891. // resource="memory",
  2892. // unit="byte",
  2893. // <some_custom_filter>
  2894. // }[1h]
  2895. // )
  2896. //) by (resourcequota, namespace, uid, cluster_id)
  2897. func NewResourceQuotaStatusUsedRAMRequestMaxMetricCollector() *metric.MetricCollector {
  2898. return metric.NewMetricCollector(
  2899. metric.ResourceQuotaStatusUsedRAMRequestMaxID,
  2900. metric.KubeResourceQuotaStatusUsedResourceRequests,
  2901. []string{
  2902. source.NamespaceLabel,
  2903. source.ResourceQuotaLabel,
  2904. source.UIDLabel,
  2905. },
  2906. aggregator.MaxOverTime,
  2907. func(labels map[string]string) bool {
  2908. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2909. },
  2910. )
  2911. }
  2912. // avg(
  2913. // avg_over_time(
  2914. // resourcequota_status_used_resource_limits{
  2915. // resource="cpu",
  2916. // unit="core",
  2917. // <some_custom_filter>
  2918. // }[1h]
  2919. // )
  2920. //) by (resourcequota, namespace, uid, cluster_id)
  2921. func NewResourceQuotaStatusUsedCPULimitAverageMetricCollector() *metric.MetricCollector {
  2922. return metric.NewMetricCollector(
  2923. metric.ResourceQuotaStatusUsedCPULimitAverageID,
  2924. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2925. []string{
  2926. source.NamespaceLabel,
  2927. source.ResourceQuotaLabel,
  2928. source.UIDLabel,
  2929. },
  2930. aggregator.AverageOverTime,
  2931. func(labels map[string]string) bool {
  2932. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2933. },
  2934. )
  2935. }
  2936. // max(
  2937. // max_over_time(
  2938. // resourcequota_status_used_resource_limits{
  2939. // resource="cpu",
  2940. // unit="core",
  2941. // <some_custom_filter>
  2942. // }[1h]
  2943. // )
  2944. //) by (resourcequota, namespace, uid, cluster_id)
  2945. func NewResourceQuotaStatusUsedCPULimitMaxMetricCollector() *metric.MetricCollector {
  2946. return metric.NewMetricCollector(
  2947. metric.ResourceQuotaStatusUsedCPULimitMaxID,
  2948. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2949. []string{
  2950. source.NamespaceLabel,
  2951. source.ResourceQuotaLabel,
  2952. source.UIDLabel,
  2953. },
  2954. aggregator.MaxOverTime,
  2955. func(labels map[string]string) bool {
  2956. return labels[source.ResourceLabel] == "cpu" && labels[source.UnitLabel] == "core"
  2957. },
  2958. )
  2959. }
  2960. // avg(
  2961. // avg_over_time(
  2962. // resourcequota_status_used_resource_limits{
  2963. // resource="memory",
  2964. // unit="byte",
  2965. // <some_custom_filter>
  2966. // }[1h]
  2967. // )
  2968. //) by (resourcequota, namespace, uid, cluster_id)
  2969. func NewResourceQuotaStatusUsedRAMLimitAverageMetricCollector() *metric.MetricCollector {
  2970. return metric.NewMetricCollector(
  2971. metric.ResourceQuotaStatusUsedRAMLimitAverageID,
  2972. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2973. []string{
  2974. source.NamespaceLabel,
  2975. source.ResourceQuotaLabel,
  2976. source.UIDLabel,
  2977. },
  2978. aggregator.AverageOverTime,
  2979. func(labels map[string]string) bool {
  2980. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  2981. },
  2982. )
  2983. }
  2984. // max(
  2985. // max_over_time(
  2986. // resourcequota_status_used_resource_limits{
  2987. // resource="memory",
  2988. // unit="byte",
  2989. // <some_custom_filter>
  2990. // }[1h]
  2991. // )
  2992. //) by (resourcequota, namespace, uid, cluster_id)
  2993. func NewResourceQuotaStatusUsedRAMLimitMaxMetricCollector() *metric.MetricCollector {
  2994. return metric.NewMetricCollector(
  2995. metric.ResourceQuotaStatusUsedRAMLimitMaxID,
  2996. metric.KubeResourceQuotaStatusUsedResourceLimits,
  2997. []string{
  2998. source.NamespaceLabel,
  2999. source.ResourceQuotaLabel,
  3000. source.UIDLabel,
  3001. },
  3002. aggregator.MaxOverTime,
  3003. func(labels map[string]string) bool {
  3004. return labels[source.ResourceLabel] == "memory" && labels[source.UnitLabel] == "byte"
  3005. },
  3006. )
  3007. }