resource.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package kubemodel
  2. import "github.com/opencost/opencost/core/pkg/stats"
  3. type Resource string
  4. const (
  5. ResourceCPU Resource = "cpu"
  6. ResourceMemory Resource = "memory"
  7. ResourceGPU Resource = "gpu"
  8. ResourceStorage Resource = "storage"
  9. )
  10. type Unit string
  11. const (
  12. UnitMillicore = "mCPU"
  13. UnitByte = "B"
  14. UnitMi = "Mi"
  15. UnitGB = "GB"
  16. UnitGPU = "GPU"
  17. UnitSecond = "s"
  18. UnitMinute = "m"
  19. UnitHour = "h"
  20. UnitMillicoreHour = "m-h"
  21. UnitByteHour = "B-h"
  22. UnitMiHour = "Mi-h"
  23. UnitGBHour = "GB-h"
  24. UnitGPUHour = "GPU-h"
  25. )
  26. type ResourceQuantity struct {
  27. Resource Resource
  28. Unit Unit
  29. Values stats.Stats
  30. }
  31. type ResourceQuantities map[Resource]ResourceQuantity
  32. func (rqs ResourceQuantities) Set(resource Resource, unit Unit, statType stats.StatType, value float64) {
  33. if _, ok := rqs[resource]; !ok {
  34. rqs[resource] = ResourceQuantity{
  35. Resource: resource,
  36. Unit: unit,
  37. Values: stats.NewStats(),
  38. }
  39. }
  40. rqs[resource].Values[statType] = value
  41. }