providerstoragequeries.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package prom
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/opencost/opencost/core/pkg/util/timeutil"
  6. )
  7. // NOTE (bolt): This is currently not being used directly in the prometheus data source, but may be useful in the future
  8. // NOTE (bolt): when it comes to pricing local storage options per provider. Recommendation is to abstract this into some
  9. // NOTE (bolt): type of storage queury registry.
  10. var providerStorageQueries = map[string]func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string{
  11. "aws": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  12. return ""
  13. },
  14. "gcp": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  15. // TODO Set to the price for the appropriate storage class. It's not trivial to determine the local storage disk type
  16. // See https://cloud.google.com/compute/disks-image-pricing#persistentdisk
  17. localStorageCost := 0.04
  18. baseMetric := "container_fs_limit_bytes"
  19. if used {
  20. baseMetric = "container_fs_usage_bytes"
  21. }
  22. fmtCumulativeQuery := `sum(
  23. sum_over_time(%s{device!="tmpfs", id="/", %s}[%s:1m])
  24. ) by (%s) / 60 / 730 / 1024 / 1024 / 1024 * %f`
  25. fmtMonthlyQuery := `sum(
  26. avg_over_time(%s{device!="tmpfs", id="/", %s}[%s:1m])
  27. ) by (%s) / 1024 / 1024 / 1024 * %f`
  28. fmtQuery := fmtCumulativeQuery
  29. if rate {
  30. fmtQuery = fmtMonthlyQuery
  31. }
  32. fmtWindow := timeutil.DurationString(end.Sub(start))
  33. return fmt.Sprintf(fmtQuery, baseMetric, config.ClusterFilter, fmtWindow, config.ClusterLabel, localStorageCost)
  34. },
  35. "azure": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  36. return ""
  37. },
  38. "alibaba": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  39. return ""
  40. },
  41. "scaleway": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  42. return ""
  43. },
  44. "otc": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  45. return ""
  46. },
  47. "oracle": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  48. return ""
  49. },
  50. "csv": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  51. return ""
  52. },
  53. "custom": func(config *OpenCostPrometheusConfig, start, end time.Time, rate bool, used bool) string {
  54. return ""
  55. },
  56. }
  57. var _ = providerStorageQueries