collector.go 57 KB

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