Skip to main content
Glama
cloudwatch-30day-final.cjsβ€’6.58 kB
#!/usr/bin/env node const { spawn } = require('child_process'); async function getCloudWatch30DayFinal() { console.log('πŸ’° CLOUDWATCH 30-DAY AMORTIZED COST - FINAL VERSION'); console.log('🏒 AWS Account: 932213950603'); console.log('πŸ“… Period: July 27 - August 26, 2025 (30 days)'); console.log('πŸ”§ Using fixed server-side filtering'); const server = spawn('node', ['dist/index.js'], { stdio: ['pipe', 'pipe', 'pipe'], env: { ...process.env, UMBRELLA_API_BASE_URL: 'https://api-front.umbrellacost.io/api/v1' } }); const responses = []; server.stdout.on('data', (data) => { const lines = data.toString().split('\n').filter(line => line.trim()); for (const line of lines) { try { responses.push(JSON.parse(line)); } catch (e) {} } }); // Show server logs for filter debugging server.stderr.on('data', (data) => { const msg = data.toString(); if (msg.includes('[CLOUDWATCH-FILTER]') || msg.includes('filters[service]')) { console.log('πŸ”§ SERVER:', msg.trim()); } }); await new Promise(resolve => setTimeout(resolve, 2000)); // Auth server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: 'authenticate_user', arguments: { username: 'david+saola@umbrellacost.com', password: 'Dsamsung1!' } } }) + '\n'); console.log('πŸ” Authenticating...'); await new Promise(resolve => setTimeout(resolve, 6000)); // First, let's test with a single day to see what service name works console.log('πŸ§ͺ Testing Aug 4th to find correct service name...'); server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: 'api___invoices_caui', arguments: { startDate: "2025-08-04", endDate: "2025-08-04", groupBy: "service", periodGranLevel: "day", costType: ["cost"], isAmortized: true, cloud_context: "aws", accountId: "932213950603" // NO FILTER - get all services to find CloudWatch } } }) + '\n'); await new Promise(resolve => setTimeout(resolve, 8000)); const allServicesResponse = responses.find(r => r.id === 2); let cloudwatchServiceName = null; if (allServicesResponse?.result?.content?.[0]?.text) { const text = allServicesResponse.result.content[0].text; const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { const data = JSON.parse(jsonMatch[1]); if (data.results && data.results.length > 0) { // Look for CloudWatch services data.results.forEach(result => { const service = result.service || result.service_name || ''; const cost = parseFloat(result.cost || result.total_cost || 0); if (service.toLowerCase().includes('cloudwatch') || service.toLowerCase().includes('amazon cloudwatch')) { console.log(`🎯 FOUND CloudWatch: "${service}" - $${cost.toFixed(2)}`); if (!cloudwatchServiceName && cost > 0) { cloudwatchServiceName = service; } } }); if (!cloudwatchServiceName) { console.log('❌ No CloudWatch service found in results'); console.log('Available services (first 10):'); data.results.slice(0, 10).forEach(r => { console.log(` "${r.service}" - $${parseFloat(r.cost || 0).toFixed(2)}`); }); } } } catch (e) { console.log('❌ Parse error:', e.message); } } } if (cloudwatchServiceName) { console.log(`\nβœ… Using CloudWatch service: "${cloudwatchServiceName}"`); console.log('πŸ” Now getting 30-day costs with proper filtering...'); // Now get 30-day costs with the correct service name server.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 3, method: "tools/call", params: { name: 'api___invoices_caui', arguments: { startDate: "2025-07-27", endDate: "2025-08-26", groupBy: "none", periodGranLevel: "day", costType: ["cost"], isAmortized: true, cloud_context: "aws", accountId: "932213950603", filters: { service: cloudwatchServiceName } } } }) + '\n'); await new Promise(resolve => setTimeout(resolve, 12000)); const costResponse = responses.find(r => r.id === 3); if (costResponse?.result?.content?.[0]?.text) { const text = costResponse.result.content[0].text; const jsonMatch = text.match(/```json\n([\s\S]*?)\n```/); if (jsonMatch) { try { const data = JSON.parse(jsonMatch[1]); if (Array.isArray(data) && data.length > 0) { // Handle array format let totalCost = 0; let dayCount = 0; console.log('\nπŸ’° CloudWatch Daily Costs (30 days):'); data.forEach((day, i) => { if (day && day.total_cost !== undefined) { const cost = parseFloat(day.total_cost || 0); const date = day.usage_date || `Day ${i+1}`; if (cost > 0) { totalCost += cost; dayCount++; console.log(`πŸ“… ${date}: $${cost.toFixed(8)}`); } } }); console.log(`\nπŸ† CLOUDWATCH 30-DAY AMORTIZED COST: $${totalCost.toFixed(8)}`); console.log(`πŸ“Š Days with costs: ${dayCount}/31`); console.log(`πŸ“ˆ Daily average: $${(totalCost/30).toFixed(8)}`); if (totalCost < 10000) { console.log('βœ… Realistic CloudWatch costs (not total account costs)'); } else { console.log('❌ Still looks like total account costs'); } } else { console.log('❌ Unexpected response format'); console.log('Response keys:', Object.keys(data)); } } catch (e) { console.log('❌ 30-day parse error:', e.message); } } } else { console.log('❌ No 30-day response received'); } } else { console.log('\n❌ Could not find CloudWatch service - cannot proceed with 30-day calculation'); } server.kill(); } getCloudWatch30DayFinal().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