r/devops7 • u/Alternative_Pin9598 • 15h ago
Automate it #13: your cloud bill jumped $355 overnight. Sort by cost and the top line is just month-end ec2. The two lines that actually ran away are $31 and $79 — score each line against its own history instead of a dollar threshold
Yesterday's bill came in at $1,544.48. The morning before it was $1,189 — up $355 overnight. You open the cost explorer, sort by cost descending, and the top line is ec2-compute at $1,050, up $121. It's the last day of the month and ec2 is always the biggest line, so that jump is boring. Nothing else looks big. You close the tab.
What you didn't see: nat-gateway went from its usual ~$6/day to $79.20, and data-transfer from ~$8 to $31.40 — 13x and 4x their own normal, both still far too small in absolute dollars to trip any alert. That is where the leaks hide: the line that is weird for itself, not the line that is big.
The chore: after the bill moves, list the lines that are unusual for themselves, not just the expensive ones.
(This sub is run by the SynapCores team; the scoring step below is a SynapCores feature. Sample export, real output from 2.5.1.)
The input: the daily cost export, one row per service per day
day,service,cost
2026-12-02,ec2-compute,1050.00
2026-12-02,nat-gateway,79.20
2026-12-02,data-transfer,31.408 services, 42 days of history plus yesterday — 344 rows.
The usual check: big spenders, and big day-over-day jumps
WITH prev AS (SELECT service, cost AS ycost FROM cc_daily WHERE day = '2026-12-01')
SELECT cur.service, cur.cost, (cur.cost - prev.ycost) AS d_over_day,
CASE WHEN cur.cost > 500 THEN 'FIRES' ELSE '-' END AS over_500,
CASE WHEN (cur.cost - prev.ycost) > 100 THEN 'FIRES' ELSE '-' END AS jump_100
FROM cc_daily cur LEFT JOIN prev ON cur.service = prev.service
WHERE cur.day = '2026-12-02' ORDER BY cur.cost DESC
service cost vs yesterday >$500 jump>$100
ec2-compute 1050.00 +121.02 FIRES FIRES
nat-gateway 79.20 +73.54 - -
data-transfer 31.40 +22.63 - -Only ec2 fires — and ec2 is the false alarm. nat-gateway jumped 13x, but that is +$73, under the $100 line. data-transfer is +$22. Pick a dollar threshold low enough to catch those two and every month-end lights up red.
The payoff: score each line against its own history
Give each line three ratios — how yesterday compares to its own average, to the same weekday, and to its usual share of the bill — then let the engine learn "normal" from the 42 days and score how unusual yesterday is:
CREATE EXPERIMENT cc_exp AS
SELECT cost_x, dow_x, share_x FROM cc_daily WHERE day < '2026-12-02'
WITH (task_type = 'anomaly_detection', algorithms = ['isolation_forest'], max_trials = 5, random_seed = 42);
DEPLOY MODEL cc_model FROM EXPERIMENT cc_exp;
SELECT service, cost, cost_x, dow_x, share_x,
ANOMALY_SCORE('cc_model', cost_x, dow_x, share_x) AS score
FROM cc_daily WHERE day = '2026-12-02' ORDER BY score DESC
service cost cost_x dow_x share_x score
nat-gateway 79.20 13.18 13.37 10.15 0.769 ODD
data-transfer 31.40 4.32 3.95 3.33 0.769 ODD
ec2-compute 1050.00 1.31 1.15 1.01 0.667
rds-postgres 232.92 1.01 1.00 0.78 0.502
lambda 14.17 1.13 0.99 0.87 0.471(odd = above 0.745, the highest score anything reached across the 42-day history)
The two lines nobody budgets for sit at the top. ec2, the biggest number on the bill, lands well down the list at 1.3x its own normal — big, but not weird. CREATE EXPERIMENT trains the model and ANOMALY_SCORE scores a row, both in SQL: no notebook, no scikit-learn, no data leaving the box.
Wire it up: export your daily costs to CSV (day,service,cost), then run load and check after the bill moves. The 344 rows load in 0.17 s; training on the history and scoring the day comes back in about a tenth of a second on a Mac mini (Apple M4). billwatch.py is standard-library only; the script, a sample export and the full eight-line output are in the comments.
Free Community Edition: https://synapcores.com/download?utm_source=reddit&utm_medium=owned&utm_campaign=devops7-automate-it-13
How do you catch the quiet runaways today — a percent-change alert, a per-service budget, or do you find them on next month's bill?