Somen Swain
Somen Swain

Reputation: 31

Snowflake Cost Governance Queries

Need some pointers if we have any references/links on getting all the queries which would identify the various cost metrics. My requirement is to build Snowsight dashboards using those queries.

  1. Storage Cost
  2. Compute Cost
  3. Managed Service Cost(snowpipe/materialized view/etc..)

Sample query is given as below, need similar set of queries for all metrics as mentioned in description.

-- For Compute (this gives credits used by warehouse/hr)

select to_char(start_time,'HH24') as hour,
       WAREHOUSE_NAME,
       sum(credits_used)
from snowflake.account_usage.warehouse_metering_history wmh 
where wmh.start_time >= dateadd(month, -1, current_date())
group by to_char(start_time,'HH24'), WAREHOUSE_NAME
order by 1;

Upvotes: 0

Views: 332

Answers (1)

Raj Gajula
Raj Gajula

Reputation: 36

https://medium.com/snowflake/monitoring-your-snowflake-organization-with-snowsight-b1acd470dc17

Below are some sample queries and you can improvise these metrics to cater the needs:

--COST BY MONTH PER WAREHOUSE--

SELECT
WMH.WAREHOUSE_NAME,
MONTHNAME(WMH.START_TIME) MONTH,
SUM((4 * WMH.CREDITS_USED)) AS DOLLARS_USED
FROM
SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WMH
GROUP BY
WMH.WAREHOUSE_NAME,
MONTHNAME(WMH.START_TIME)

--MONTHLY COST BY WAREHOUSE (CUSTOM/SNOWFLAKE)--
SELECT
WMH.WAREHOUSE_NAME,
MONTHNAME(WMH.START_TIME) MONTH,
SUM(WMH.CREDITS_USED) AS TOTAL_CREDITS,
SUM(WMH.CREDITS_USED_COMPUTE) AS CUSTOMER_COMPUTE,
SUM(CREDITS_USED_CLOUD_SERVICES) AS SNOWFLAKE_COMPUTE
FROM
SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WMH
GROUP BY
WMH.WAREHOUSE_NAME,
MONTHNAME(WMH.START_TIME);

Upvotes: 1

Related Questions