-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce9bf21
commit 19f3923
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |