opencost.go 2.2 KB

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