collector.go 78 KB

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