collector.go 77 KB

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