Browse Source

make statsd less crashy

master
eta 3 months ago
parent
commit
8503ee36e6
  1. 32
      trackernet.lisp

32
trackernet.lisp

@ -5,6 +5,18 @@
(defparameter *trackernet-base-url* "http://cloud.tfl.gov.uk/TrackerNet")
(defun statsd-inc (&rest args)
(ignore-errors
(apply #'statsd:inc args)))
(defun statsd-gauge (&rest args)
(ignore-errors
(apply #'statsd:gauge args)))
(defun statsd-counter (&rest args)
(ignore-errors
(apply #'statsd:counter args)))
(defun read-all-from (file)
(with-open-file (source file
:element-type '(unsigned-byte 8))
@ -470,7 +482,7 @@
cl-ansi-text:+reset-color-string+
lcn-train-id
tid)
(statsd:inc "intertube.leading-car-no-change")))
(statsd-inc "intertube.leading-car-no-change")))
;; reserve the leading car no
(red:setex (format nil "~A-lcn-~A"
line-code leading-car-no)
@ -498,7 +510,7 @@
cl-ansi-text:+reset-color-string+
set-code-train-id
tid)
(statsd:inc "intertube.set-code-change")))
(statsd-inc "intertube.set-code-change")))
;; reserve the set number
(red:setex (format nil "~A-set-~A-trip-~A"
line-code set-no trip-no)
@ -730,7 +742,7 @@
;; a reporting gap
(unless (member last-reported-station *termini*
:test #'string=)
(statsd:inc "intertube.archived-early")
(statsd-inc "intertube.archived-early")
(format *error-output*
"~&archiver: WARNING: train ~A last reported at ~A~%"
(second train)
@ -783,16 +795,16 @@ Stop if *TRACKERNET-KILL-SWITCH* is set to T."
:start
(handler-case
(let ((pred (fetch-trackernet-prediction line-code station-code)))
(statsd:inc (format nil "scraper.~A-~A.scraped" line-code station-code))
(statsd:inc "intertube.scraped-total")
(statsd-inc (format nil "scraper.~A-~A.scraped" line-code station-code))
(statsd-inc "intertube.scraped-total")
(let ((num-trains (maybe-redis-trackernet-prediction pred)))
(when num-trains
(statsd:gauge (format nil "scraper.~A-~A.trains" line-code station-code) num-trains)
(statsd:inc (format nil "scraper.~A-~A.new" line-code station-code)))))
(statsd-gauge (format nil "scraper.~A-~A.trains" line-code station-code) num-trains)
(statsd-inc (format nil "scraper.~A-~A.new" line-code station-code)))))
;; (format t "~&scraper(~A-~A): new: ~A (~A trains)~%"
;; line-code station-code pred num-trains))))
(error (e)
(statsd:inc (format nil "scraper.~A-~A.errors" line-code station-code))
(statsd-inc (format nil "scraper.~A-~A.errors" line-code station-code))
(format *error-output* "~&scraper(~A-~A): error: ~A~%"
line-code station-code e)))
(go :sleep)
@ -837,7 +849,7 @@ Stop if *TRACKERNET-KILL-SWITCH* is set to T."
(redis:with-connection ()
(loop
while (not *trackernet-kill-switch*)
do (statsd:gauge (format nil "line.~A.active-trains" line-code)
do (statsd-gauge (format nil "line.~A.active-trains" line-code)
(length (trains-active-on-line line-code)))
do (sleep 1))))
@ -850,7 +862,7 @@ Stop if *TRACKERNET-KILL-SWITCH* is set to T."
(handler-case
(progn
(archive-trains-tar trains)
(statsd:counter "intertube.archived" (length trains))
(statsd-counter "intertube.archived" (length trains))
(mapc #'red:del trains))
(error (e)
(format *error-output* "~&archiver: failed: ~A~%" e))))))

Loading…
Cancel
Save