dashboard changes
This commit is contained in:
parent
cc68af5a68
commit
98187b4c0b
@ -242,3 +242,30 @@ export const accountsWithDateRange = (startDate, endDate) => `
|
||||
GROUP BY line_item_usage_account_id
|
||||
ORDER BY totalCost DESC
|
||||
`;
|
||||
//dashboard/usage-per-month?startDate=2024-01-01&endDate=2025-12-31
|
||||
|
||||
export const usageCostPerMonthWithDateRange = (startDate, endDate) => `
|
||||
SELECT
|
||||
CONCAT(year, '-', LPAD(month, 2, '0')) AS month,
|
||||
SUM(line_item_usage_amount) AS totalUsageAmount,
|
||||
SUM(line_item_unblended_cost) AS totalUnblendedCost,
|
||||
SUM(line_item_blended_cost) AS totalBlendedCost
|
||||
FROM ${process.env.ATHENA_CU_TABLE}
|
||||
WHERE line_item_usage_start_date >= date('${startDate}')
|
||||
AND line_item_usage_start_date <= date('${endDate}')
|
||||
AND line_item_blended_cost > 0
|
||||
GROUP BY year, month
|
||||
ORDER BY month ASC;
|
||||
`;
|
||||
//dashboard/yearly-spend
|
||||
export const yearlySpendSummary = `
|
||||
SELECT
|
||||
year AS usageYear,
|
||||
SUM(line_item_usage_amount) AS totalUsageAmount,
|
||||
SUM(line_item_unblended_cost) AS totalUnblendedCost,
|
||||
SUM(line_item_blended_cost) AS totalBlendedCost
|
||||
FROM ${process.env.ATHENA_CU_TABLE}
|
||||
WHERE line_item_blended_cost > 0
|
||||
GROUP BY year
|
||||
ORDER BY usageYear ASC;
|
||||
`;
|
||||
|
||||
20
server.js
20
server.js
@ -2,7 +2,7 @@ import Fastify from "fastify";
|
||||
import cors from "@fastify/cors";
|
||||
import sequelizePlugin from "./plugins/sequelize.js";
|
||||
import dotenv from "dotenv";
|
||||
import cors from "@fastify/cors";
|
||||
|
||||
import { executeQueryAsync, retrieveResultsAsync } from "./services/athena.js";
|
||||
dotenv.config();
|
||||
import * as dashboard from "./queries/dashboard.js";
|
||||
@ -10,9 +10,7 @@ import * as queries from "./queries/queries.js";
|
||||
import * as dashboardQueries from "./queries/dashboard.js";
|
||||
|
||||
const server = Fastify({ logger: true });
|
||||
await server.register(cors, {
|
||||
origin: "*",
|
||||
});
|
||||
|
||||
server.register(sequelizePlugin);
|
||||
|
||||
await server.register(cors, {
|
||||
@ -376,6 +374,20 @@ server.get("/dashboard/accounts/:accountId/trends", async (request, reply) => {
|
||||
};
|
||||
});
|
||||
|
||||
server.get("/dashboard/usage-per-month", async (request, reply) => {
|
||||
const { startDate, endDate } = request.query;
|
||||
const query = dashboardQueries.usageCostPerMonthWithDateRange(startDate, endDate);
|
||||
const queryExecutionId = await executeQueryAsync(query);
|
||||
const results = await retrieveResultsAsync(queryExecutionId);
|
||||
return results;
|
||||
});
|
||||
server.get("/dashboard/yearly-spend", async (request, reply) => {
|
||||
const query = dashboardQueries.yearlySpendSummary;
|
||||
const queryExecutionId = await executeQueryAsync(query);
|
||||
const results = await retrieveResultsAsync(queryExecutionId);
|
||||
return results;
|
||||
});
|
||||
|
||||
|
||||
try {
|
||||
await server.listen({ port: 3000 })
|
||||
|
||||
Loading…
Reference in New Issue
Block a user