Skip to content

Commit

Permalink
first pushgateway bits
Browse files Browse the repository at this point in the history
  • Loading branch information
deadtrickster committed Apr 15, 2016
1 parent ce9bf21 commit 19f3923
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions prometheus.pushgateway.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(asdf:defsystem :prometheus.pushgateway
:serial t
:version "0.1"
:licence "MIT"
:depends-on ("prometheus"
"prometheus.formats.text"
"drakma")
:author "Ilya Khaprov <ilya.kharpov@publitechs.com>"
:components ((:module "src/pushgateway"
:serial t
:components
((:file "package")
(:file "pushgateway"))))
:description "Prometheus.io Pushgateway client")
11 changes: 11 additions & 0 deletions src/pushgateway/package.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(in-package #:cl-user)

(defpackage #:prometheus.pushgateway
(:use #:cl #:alexandria)
(:nicknames #:prom.pushgateway)
(:shadow #:push
#:replace
#:delete)
(:export #:push
#:replace
#:delete))
26 changes: 26 additions & 0 deletions src/pushgateway/pushgateway.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(in-package #:prometheus.pushgateway)

(define-constant +default-pushgateway-address+ "localhost:9091" :test #'equal)

(defun http-request (gateway method job grouping-key content-type body)
(multiple-value-bind (body status-code headers)
(drakma:http-request (format nil "http://~a/metrics/job/~a~:[~;~:*/~{~a~^/~}~]" gateway job grouping-key)
:method method
:content-type content-type
:content body)
(if (>= status-code 400)
(error "Error talking to pushgateway. Response Code: ~a, body: ~a, headers: ~a" status-code body headers))))

(defun push (job &key (gateway +default-pushgateway-address+)
(registry prom:*default-registry*)
(grouping-key))
(http-request gateway :post job grouping-key prom.text:+content-type+ (prom.text:marshal registry)))

(defun replace (job &key (gateway +default-pushgateway-address+)
(registry prom:*default-registry*)
(grouping-key))
(http-request gateway :put job grouping-key prom.text:+content-type+ (prom.text:marshal registry)))

(defun delete (job &key (gateway +default-pushgateway-address+)
(grouping-key))
(http-request gateway :push job grouping-key prom.text:+content-type+ nil))

0 comments on commit 19f3923

Please sign in to comment.