diff options
author | Christopher Baines <mail@cbaines.net> | 2020-04-26 07:36:48 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-04-26 07:36:48 +0100 |
commit | e44f7a520e136733738dbebe6e3055e44bb46e7d (patch) | |
tree | a5af74d9f3ce49947a226819b5ac7066f742aca7 | |
parent | eefd2e612bb4e182d4d5c623f9fd07028dc93c85 (diff) | |
download | build-coordinator-e44f7a520e136733738dbebe6e3055e44bb46e7d.tar build-coordinator-e44f7a520e136733738dbebe6e3055e44bb46e7d.tar.gz |
Add a new metrics module
To produce Prometheus style metrics for the counts of various things.
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | guix-build-coordinator/metrics.scm | 93 |
2 files changed, 94 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 9b7be08..747c597 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,4 +16,5 @@ SOURCES = \ guix-build-coordinator/datastore/postgresql.scm \ guix-build-coordinator/datastore/sqlite.scm \ guix-build-coordinator/hooks.scm \ + guix-build-coordinator/metrics.scm \ guix-build-coordinator/utils.scm diff --git a/guix-build-coordinator/metrics.scm b/guix-build-coordinator/metrics.scm new file mode 100644 index 0000000..1f93689 --- /dev/null +++ b/guix-build-coordinator/metrics.scm @@ -0,0 +1,93 @@ +;;; Guix Build Coordinator +;;; +;;; Copyright © 2020 Christopher Baines <mail@cbaines.net> +;;; +;;; This file is part of the guix-build-coordinator. +;;; +;;; The Guix Build Coordinator is free software; you can redistribute +;;; it and/or modify it under the terms of the GNU General Public +;;; License as published by the Free Software Foundation; either +;;; version 3 of the License, or (at your option) any later version. +;;; +;;; The Guix Build Coordinator is distributed in the hope that it will +;;; be useful, but WITHOUT ANY WARRANTY; without even the implied +;;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +;;; See the GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with the guix-data-service. If not, see +;;; <http://www.gnu.org/licenses/>. + +(define-module (guix-build-coordinator metrics) + #:use-module (ice-9 match) + #:use-module (guix-build-coordinator datastore) + #:export (metrics)) + +(define namespace + "guix_build_coordinator") + +(define (format-metric namespace metric labels-and-values value) + (simple-format + #f + "~A_~A~A ~A" + namespace + metric + (if (null? labels-and-values) + "" + (string-append + "{" + (string-join (map + (match-lambda + ((label . value) + (simple-format + #f + "~A=\"~A\"" + label value))) + labels-and-values) + ",") + "}")) + value)) + +(define (metrics datastore) + (string-join + (append (list + (format-metric + namespace + "builds_total" + '() + (datastore-count-builds datastore))) + (map (match-lambda + ((agent-id . count) + (format-metric + namespace + "allocated_builds_total" + `((agent_id . ,agent-id)) + count))) + (datastore-count-allocated-builds datastore)) + (map (match-lambda + (((agent-id result) . count) + (format-metric + namespace + "build_results_total" + `((agent_id . ,agent-id) + (result . ,result)) + count))) + (datastore-count-build-results datastore)) + (map (match-lambda + (((agent-id reason) . count) + (format-metric + namespace + "setup_failures_total" + `((agent_id . ,agent-id) + (reason . ,reason)) + count))) + (datastore-count-setup-failures datastore)) + (map (match-lambda + ((agent-id . count) + (format-metric + namespace + "build_allocation_plan_total" + `((agent_id . ,agent-id)) + count))) + (datastore-count-build-allocation-plan-entries datastore))) + "\n")) |