Skip to main content
Glama
cloudwatch-weekly.cjsโ€ข5.11 kB
#!/usr/bin/env node const { spawn } = require('child_process'); async function getCloudWatchWeekly() { console.log('๐Ÿ“… CLOUDWATCH COSTS - WEEKLY CHUNKS'); console.log('Getting real daily costs in smaller batches'); console.log('=' .repeat(60)); const server = spawn('node', ['dist/index.js'], { stdio: ['pipe', 'pipe', 'pipe'], cwd: process.cwd(), env: { ...process.env, UMBRELLA_API_BASE_URL: 'https://api-front.umbrellacost.io/api/v1' } }); const responses = []; let requestId = 1; server.stdout.on('data', (data) => { const lines = data.toString().split('\n').filter(line => line.trim()); for (const line of lines) { try { const response = JSON.parse(line); responses.push(response); } catch (e) {} } }); server.stderr.on('data', () => {}); // Suppress logs await new Promise(resolve => setTimeout(resolve, 3000)); // Auth const authRequest = { jsonrpc: "2.0", id: requestId++, method: "tools/call", params: { name: 'authenticate_user', arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' } } }; server.stdin.write(JSON.stringify(authRequest) + '\n'); await new Promise(resolve => setTimeout(resolve, 5000)); if (!responses.find(r => r.id === authRequest.id && r.result?.content?.[0]?.text?.includes('Successfully authenticated'))) { console.log('โŒ Auth failed'); server.kill(); return; } console.log('โœ… Authenticated'); // Try just last week first (Aug 19-26) console.log('\n๐Ÿ“Š Getting last week (Aug 19-26)...'); const weekRequest = { jsonrpc: "2.0", id: requestId++, method: "tools/call", params: { name: 'api___invoices_caui', arguments: { startDate: "2025-08-19", endDate: "2025-08-26", costType: ["cost", "discount"], periodGranLevel: "day", groupBy: "service", isAmortized: true, accountId: "932213950603" } } }; server.stdin.write(JSON.stringify(weekRequest) + '\n'); // Wait up to 15 seconds let found = false; for (let i = 0; i < 15 && !found; i++) { await new Promise(resolve => setTimeout(resolve, 1000)); const response = responses.find(r => r.id === weekRequest.id); if (response) { found = true; if (response.result?.content?.[0]?.text) { const text = response.result.content[0].text; const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { const data = JSON.parse(jsonMatch[1]); const cloudwatchData = data.filter(item => (item.service_name || '').toLowerCase() === 'amazoncloudwatch' ); if (cloudwatchData.length > 0) { console.log(`โœ… Found ${cloudwatchData.length} CloudWatch records for last week\n`); const dailyCosts = {}; cloudwatchData.forEach(item => { const date = item.usage_date.split('T')[0]; const cost = parseFloat(item.total_cost) || 0; dailyCosts[date] = cost; }); console.log('๐Ÿ—“๏ธ LAST WEEK ACTUAL CLOUDWATCH COSTS:'); console.log('='.repeat(45)); const sortedDates = Object.keys(dailyCosts).sort(); let weekTotal = 0; sortedDates.forEach((date, index) => { const cost = dailyCosts[date]; weekTotal += cost; const dateObj = new Date(date + 'T12:00:00Z'); const dayName = dateObj.toLocaleDateString('en-US', { weekday: 'short' }); const monthDay = dateObj.toLocaleDateString('en-US', { month: 'short', day: '2-digit' }); console.log(`${monthDay} (${dayName}): $${cost.toFixed(2)}`); }); console.log('='.repeat(45)); console.log(`๐Ÿ’ฐ Week Total: $${weekTotal.toFixed(2)}`); console.log(`๐Ÿ“Š Daily Average: $${(weekTotal / sortedDates.length).toFixed(2)}`); // Show the variation const costs = Object.values(dailyCosts); const maxCost = Math.max(...costs); const minCost = Math.min(...costs); console.log(`๐Ÿ“ˆ Highest: $${maxCost.toFixed(2)}`); console.log(`๐Ÿ“‰ Lowest: $${minCost.toFixed(2)}`); console.log(`๐ŸŽฏ Daily Variation: $${(maxCost - minCost).toFixed(2)}`); // Extrapolate to 30 days const avgDaily = weekTotal / sortedDates.length; console.log(`\n๐Ÿ”ฎ 30-Day Projection: $${(avgDaily * 30).toFixed(2)}`); } else { console.log('โŒ No CloudWatch data in response'); } } } else { console.log('โŒ No data in response'); } } } if (!found) { console.log('โŒ No response received'); } server.kill(); } getCloudWatchWeekly().catch(console.error);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daviddraiumbrella/invoice-monitoring'

If you have feedback or need assistance with the MCP directory API, please join our Discord server