opencost.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package scrape
  2. import (
  3. "github.com/opencost/opencost/modules/collector-source/pkg/scrape/target"
  4. )
  5. // Opencost Metrics
  6. const (
  7. KubecostClusterManagementCost = "kubecost_cluster_management_cost"
  8. KubecostNetworkZoneEgressCost = "kubecost_network_zone_egress_cost"
  9. KubecostNetworkRegionEgressCost = "kubecost_network_region_egress_cost"
  10. KubecostNetworkInternetEgressCost = "kubecost_network_internet_egress_cost"
  11. PVHourlyCost = "pv_hourly_cost"
  12. KubecostLoadBalancerCost = "kubecost_load_balancer_cost"
  13. NodeTotalHourlyCost = "node_total_hourly_cost"
  14. NodeCPUHourlyCost = "node_cpu_hourly_cost"
  15. NodeRAMHourlyCost = "node_ram_hourly_cost"
  16. NodeGPUHourlyCost = "node_gpu_hourly_cost"
  17. NodeGPUCount = "node_gpu_count"
  18. KubecostNodeIsSpot = "kubecost_node_is_spot"
  19. ContainerCPUAllocation = "container_cpu_allocation"
  20. ContainerMemoryAllocationBytes = "container_memory_allocation_bytes"
  21. ContainerGPUAllocation = "container_gpu_allocation"
  22. PodPVCAllocation = "pod_pvc_allocation"
  23. )
  24. func newOpenCostTargetProvider() target.TargetProvider {
  25. // localhost is used here because we are hitting an endpoint of this container
  26. return target.NewDefaultTargetProvider(target.NewUrlTarget("http://localhost:9003/metrics"))
  27. }
  28. func newOpenCostScraper() Scraper {
  29. return newOpencostTargetScraper(newOpenCostTargetProvider())
  30. }
  31. func newOpencostTargetScraper(provider target.TargetProvider) *TargetScraper {
  32. return newTargetScrapper(
  33. provider,
  34. []string{
  35. KubecostClusterManagementCost,
  36. KubecostNetworkZoneEgressCost,
  37. KubecostNetworkRegionEgressCost,
  38. KubecostNetworkInternetEgressCost,
  39. PVHourlyCost,
  40. KubecostLoadBalancerCost,
  41. NodeTotalHourlyCost,
  42. NodeCPUHourlyCost,
  43. NodeRAMHourlyCost,
  44. NodeGPUHourlyCost,
  45. NodeGPUCount,
  46. KubecostNodeIsSpot,
  47. ContainerCPUAllocation,
  48. ContainerMemoryAllocationBytes,
  49. ContainerGPUAllocation,
  50. PodPVCAllocation,
  51. },
  52. true)
  53. }