;;; Guix Build Coordinator ;;; ;;; Copyright © 2020 Christopher Baines ;;; ;;; 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 ;;; . (define-module (guix-build-coordinator metrics) #:use-module (ice-9 match) #:use-module (guix-build-coordinator datastore) #:export (metrics)) (define namespace "guixbuildcoordinator") (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"))