Example
(defparameter *http-requests-counter* (prom:make-counter :name "http_requests_count" :help "HTTP requests counter" :labels '("app")))
(defparameter *http-requests-duration* (prom:make-histogram :name "http_requests_duration" :help "HTTP requests duration[ms]" :labels '("app") :buckets '(10 25 50 75 100 250 500 750 1000 1500 2000 3000)))
(defclass acceptor (tbnl:acceptor)
((application :accessor application-of :initarg :applicaton)
(requests-counter :reader acceptor-requests-counter)
(requests-duration :reader acceptor-requests-duration))
(:default-initargs
:request-class 'request
:reply-class 'reply))
(defmethod initialize-instance :after ((acceptor acceptor) &rest args)
(declare (ignore args))
(let ((labels (list (string-downcase (class-name (class-of (application-of acceptor)))))))
(setf (slot-value acceptor 'requests-counter)
(prom:get-metric *http-requests-counter* labels)
(slot-value acceptor 'requests-duration)
(prom:get-metric *http-requests-duration* labels))))
(defmethod tbnl:acceptor-dispatch-request ((acceptor acceptor) request)
(prom:counter.inc (acceptor-requests-counter acceptor))
(prom:histogram.time (acceptor-requests-duration acceptor)
...
))
For more information, see the repository
License: MIT
Topics: Distributed Monitoring