collector.go 60 KB

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