aboutsummaryrefslogtreecommitdiff
path: root/README
blob: 3f99135bd8db3087ef817539fa01660d23e5a22c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-*- mode: org -*-

This Guile library provides instrumentation code intended to be used
with the Prometheus time series service.

Counter, gauge and histogram metric types are supported.

This client library is still in early development, and there will be
probably be breaking changes in the future, prior to the first stable
release.

Some information on how to use this library can be found in the
docstrings of exported procedures in the prometheus.scm file.

** Web service example

The following example demonstrates a Guile web server, with some
instrumentation for the number of requests. Each time a request is
handled, the metric is instrumented. For the /metrics path, the
response is the metrics and their values. This is intended to be
scraped by Prometheus so that it can retrieve and record the metric
values.

#+BEGIN_SRC scheme
(use-modules (web server)
             (web request)
             (web response)
             (web uri)
             (prometheus))

(define my-registry (make-metrics-registry #:namespace "exampleapp"))

(define request-counter (make-counter-metric my-registry
                                             "requests_count"))

(define (request-handler request body)
  (metric-increment request-counter)

  (if (equal? (split-and-decode-uri-path (uri-path (request-uri request)))
              '("metrics"))
      (values '((content-type . (text/plain)))
              (lambda (port)
                (write-metrics my-registry port)))
      (values '((content-type . (text/plain)))
              (lambda (port)
                (display "Incrementing metric\n" port)))))

(run-server request-handler)
#+END_SRC