regions added

This commit is contained in:
Aravind U. S 2025-07-23 12:55:08 +05:30
parent 98187b4c0b
commit 3c70bcc5ec
2 changed files with 28 additions and 0 deletions

View File

@ -269,3 +269,18 @@ export const yearlySpendSummary = `
GROUP BY year
ORDER BY usageYear ASC;
`;
///dashboard/regions
export const resourceBreakdownByRegion = `
SELECT
COALESCE(NULLIF(TRIM(product_region_code), ''), 'global') AS regionCode,
SUM(line_item_blended_cost) AS totalBlendedCost,
COUNT(DISTINCT line_item_resource_id) AS resourceCount,
COUNT(DISTINCT line_item_product_code) AS serviceCount,
COUNT(DISTINCT line_item_usage_account_id) AS accountCount
FROM ${process.env.ATHENA_CU_TABLE}
WHERE line_item_blended_cost > 0
GROUP BY COALESCE(NULLIF(TRIM(product_region_code), ''), 'global')
ORDER BY totalBlendedCost DESC
`;

View File

@ -387,6 +387,19 @@ server.get("/dashboard/yearly-spend", async (request, reply) => {
const results = await retrieveResultsAsync(queryExecutionId);
return results;
});
server.get("/dashboard/regions", async (request, reply) => {
try {
const queryExecutionId = await executeQueryAsync(dashboardQueries.resourceBreakdownByRegion);
const results = await retrieveResultsAsync(queryExecutionId);
return results;
} catch (err) {
request.log.error(err);
return reply.status(500).send({
error: "Failed to fetch resource breakdown by region",
details: err.message
});
}
});
try {