Pull or push: who starts the conversation — scrape targets, the up metric and service discovery
When the monitor pulls each target on its own schedule, a failed fetch itself says the target is down, while when apps push, short-lived jobs can still report but silence becomes ambiguous: dead, or just quiet?
Totals survive missed reads; now we decide who starts each read and what a failed read tells us.
Scene 04
Pull or push: who starts the conversation
- Watch
- Try it
- Predict
- Capture
How do the numbers get from the app to the monitor, and what does each direction cost? Here the monitor does the asking. It first gets Kubernetes' list of checkout pods that exist right now (finding targets this way is called service discovery), then walks that list, fetching each pod's page of numbers every 15 s (example). Watch the second round: pod-7 hangs while Kubernetes still lists it.
Highlighted lines are the ones running in the diagram right now.
def scrape_all(): # every 15 s (example)targets = kubernetes.list_pods("checkout")for target in targets:page = http_get(target.url + "/metrics")if page is None:store.write("up", target, 0)continuestore.write("up", target, 1)for series, value in parse(page):store.write(series, target, value)
def push_loop(target): # the monitor, or a relaywhile True:totals = read_totals()target.send(self.name, totals)sleep(push_interval) # 15 s (example)
last = {}def on_push(sender, totals):last[sender] = totalsdef on_scrape():return [(sender, totals)for sender, totals in last.items()]
def run_job(target):serve("/metrics") # open only while runningresult = do_work() # 3 s, 30 s or 5 minif target is not None:target.send("batch-job", result)exit()
Where this sits in Metrics / Monitoring System
Scene 04 of 18, in the Collect act — Running totals, and who starts the conversation.. When the monitor pulls each target on its own schedule, a failed fetch itself says the target is down; when apps push, silence becomes ambiguous — dead, or just quiet?
Up next. Now that the monitor reliably collects every pod's running totals, the next question is how to turn ever-growing totals from many pods into one honest requests-per-second line.
All 18 scenes in Metrics / Monitoring System · Every curriculum