From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SFNcMOiaxWMReAEAbAwnHQ (envelope-from ) for ; Mon, 16 Jan 2023 19:43:52 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id YHlVMOiaxWMz2gAAauVa8A (envelope-from ) for ; Mon, 16 Jan 2023 19:43:52 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 630F42CEC5 for ; Mon, 16 Jan 2023 19:43:52 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHUSG-0000CG-T5; Mon, 16 Jan 2023 13:43:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHUS9-0000Af-Av for guix-patches@gnu.org; Mon, 16 Jan 2023 13:43:30 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHURi-00020L-7x for guix-patches@gnu.org; Mon, 16 Jan 2023 13:43:27 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pHURi-0006Gq-42 for guix-patches@gnu.org; Mon, 16 Jan 2023 13:43:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60788] [PATCH] services: Add vnstat-service-type. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 16 Jan 2023 18:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60788 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Bruno Victal Cc: 60788@debbugs.gnu.org Received: via spool by 60788-submit@debbugs.gnu.org id=B60788.167389454324035 (code B ref 60788); Mon, 16 Jan 2023 18:43:02 +0000 Received: (at 60788) by debbugs.gnu.org; 16 Jan 2023 18:42:23 +0000 Received: from localhost ([127.0.0.1]:34874 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pHUR4-0006Fb-PF for submit@debbugs.gnu.org; Mon, 16 Jan 2023 13:42:23 -0500 Received: from mail-qt1-f179.google.com ([209.85.160.179]:42827) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pHUQu-0006F5-Oa for 60788@debbugs.gnu.org; Mon, 16 Jan 2023 13:42:21 -0500 Received: by mail-qt1-f179.google.com with SMTP id fd15so15377517qtb.9 for <60788@debbugs.gnu.org>; Mon, 16 Jan 2023 10:42:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=/kAavj0d7GuDH0kcUED/DhPZyFP1VIE6opHNzZADVjs=; b=SXiB/n8upzY9zNMlB5AWYviru0OBAMYMFcPvAlxNKSAh730mPO6fQjvrWYc3dwlVmm aw1vx+9Xdyf5eM/6LCQN8D0n8crnj9liFK+NfVbL2k08iL89wbrUzgx29sfotWrLWZfO AowtDpblAkxBFuDyR38SuMjwWWWUo4gFl5J88WeHJrv8dUFcRIzidluUdJ7FXIGuqlsj OgeKakvsOZ584nEM0EZqCtrCQdtO9bpNtzixzpUhnUUy5DVLhbguxPx/cZCsCGmIsAr/ A+PTw+g0efRvCzZqCzx1JIXl67Z+BEpw/we40SuxrfmewB5idaW9LlRRBDLzfgLBjuEn cPGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/kAavj0d7GuDH0kcUED/DhPZyFP1VIE6opHNzZADVjs=; b=Mdf0luwYQvDOmpfPF5UIq0kjwkRSELfcy/4t1gnKjVFznwKyqqbQ4oC06myiWWZ+3s WZQhxvCuPoiJeOn9dCDMQuV+cr8P3kekIVcmvEC3BDG0yEXw1SiaB/ls3JX6wiP8cXFz C792MQHXykKHUp3t3ucQQjkvZnf1VAyfl6EfSMOmbfU5uI3oXWyQR+0hUgkAQGNL0N8M Go97GvtRGl8cMNhl8xDZOBMtij2UUHcNsBkoRKEOpqkc+JL0U2uCHNd2dBetQcG2n2l3 soNQa/uoDZl2iUehIaE0tV1BI/+S7tXRodTtDf4G3DHXO78VkSzb+jr9nIv6HFFwfM5h W5Wg== X-Gm-Message-State: AFqh2koI+OziSaCHOAp32lBbOnJCPCrtseM6pazUWkGQlk9MuTlIWBde Btoi0sWZSyKZo6gdczww3tdpsFzrdL+WjxZn X-Google-Smtp-Source: AMrXdXttyS1f2gNbhY15dQuYCIQp6mDrLLNR7lpNfqIGIX0vtg1graLa7xCBSP8UXgn1C16r2kL4aA== X-Received: by 2002:a05:622a:1e1b:b0:3b4:a6af:a2f2 with SMTP id br27-20020a05622a1e1b00b003b4a6afa2f2mr123685qtb.34.1673894526782; Mon, 16 Jan 2023 10:42:06 -0800 (PST) Received: from hurd (dsl-10-130-209.b2b2c.ca. [72.10.130.209]) by smtp.gmail.com with ESMTPSA id o5-20020a05620a2a0500b006f9e103260dsm18947235qkp.91.2023.01.16.10.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 10:42:06 -0800 (PST) From: Maxim Cournoyer References: <95b646eb6b23dec213cba43b6e4e7ddc4a601d0f.1673640404.git.mirai@makinata.eu> Date: Mon, 16 Jan 2023 13:42:05 -0500 In-Reply-To: <95b646eb6b23dec213cba43b6e4e7ddc4a601d0f.1673640404.git.mirai@makinata.eu> (Bruno Victal's message of "Fri, 13 Jan 2023 20:07:36 +0000") Message-ID: <87o7qy48zm.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="SXiB/n8u"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1673894632; a=rsa-sha256; cv=none; b=oKzeD7OP2peMOpn/IQC1QE+5GDNKIailwz+VfFbIx5UjKMT3j2FhWohISRZYZnrMlsVAsp W0qO7mO5dUk0/GBoWSRlR3BOQWLtUiRZHJ5MFdK8wAyWCtr6DYxGxAkrFl+ffeCwW+XgKT nelaoH4sK1ODfJ67+73XZIjXPQkQE1yx8b0H6SQ+CaVbi0AVslRZsKa45RWDRidlS+ZvjI 9G6TbKLbsjbR5SbPF7I4shTyAlmoZlQGakRfv6CplSCbIBW0wLCeZfCM2g/EsCKeoTgAqC t2ByUteY2D/syg5AXLc6sYxGQbIqtSAPxMnL7ERBkJoEQArLs4TwNPfbLcbreA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673894632; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=IU+1CRTsQv4gbFg3jhy9M5T/pIjACAD91+tAzIWorx4=; b=U6hwlsaHIT+Pbi09ehhZYCutFHzhml4Scg72s5oclRqGCvxZ01qBzbNmJ+IGNvE/COWoOe +wrKY0gHSD3TiExQF1wW+6zB4cjo4m1JQ88Y0rUrRAVRWU20P/Yy7AU5StombNvgFXMXMC 38HIq8h6M0uUQCj+ZPQB48Kcn/xqCB+W6iKPRElXMdG/R3otd8EYJwfOi6Waoh9VUE2c5G bP3TecPe9pvy8umGkJnSnRVLlY7ZM5zEaf9MXqA8GeSB3Ypp2Yrl1foTVrHB7VEMruiCGJ vB86mPPGiu4N0gAaoArY18iyzD+xFejBhki1BFhx+bwrLj7hRuYPGRVLaVfInw== X-Migadu-Queue-Id: 630F42CEC5 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gmail.com header.s=20210112 header.b="SXiB/n8u"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) X-Migadu-Spam-Score: -1.93 X-Spam-Score: -1.93 X-TUID: 4HTQILgObrXs Hello! Bruno Victal writes: [...] > @@ -45,6 +48,10 @@ (define-module (gnu services monitoring) > prometheus-node-exporter-web-listen-address > prometheus-node-exporter-service-type > + vnstat-configuration > + vnstat-configuration? > + vnstat-service-type > + Normally, all the accessors are exported, otherwise there's no means to introspect a vnstat-configuration, which may be useful at the REPL. [...] > + > +;;; > +;;; vnstat daemon > +;;; > + > +(define* (camelfy-field-name field-name #:key (dromedary? #f)) > + (match (string-split (symbol->string field-name) #\-) > + ((head tail ...) > + (string-join (cons (if dromedary? head (string-upcase head 0 1)) > + (map string-capitalize tail)) "")))) I'd name this pascal-case-field-name, and drop the apparently unused dromerady? argument (fun, though :-)). If we need it, we could introduce a 2nd camel-case-field-name. > +(define (dock-field-name field-name) > + "Drop rightmost '?' character" > + (let ((str (symbol->string field-name))) > + (if (string-suffix? "?" str) > + (string->symbol (string-drop-right str 1)) > + field-name))) I'm not sure about the meaning of 'dock' in this procedure name. Perhaps 'strip-trailing-?-character' would be better? > +(define (vnstat-serialize-string field-name value) > + #~(format #f "~a ~s~%" > + #$(camelfy-field-name field-name) > + #$value)) > + > +(define vnstat-serialize-integer vnstat-serialize-string) > + > +(define (vnstat-serialize-boolean field-name value) > + #~(format #f "~a ~a~%" > + #$(camelfy-field-name (dock-field-name field-name)) > + #$(if value 1 0))) > + > +(define (vnstat-serialize-alist field-name value) > + (generic-serialize-alist string-append > + (lambda (iface val) > + (vnstat-serialize-integer > + (format #f "MaxBW~a" iface) val)) > + value)) > + > +(define-maybe string (prefix vnstat-)) > +(define-maybe integer (prefix vnstat-)) > +(define-maybe boolean (prefix vnstat-)) > +(define-maybe alist (prefix vnstat-)) > + > +;; Documentation strings from vnstat.conf manpage adapted to texinfo. > +;; vnstat checkout: v2.10, commit b3408af1c609aa6265d296cab7bfe59a61d7cf70 > +(define-configuration vnstat-configuration > + (package > + (file-like vnstat) > + "The vnstat package." > + empty-serializer) > + > + (database-dir > + (string "/var/lib/vnstat") > + "\ > +Specifies the directory where the database is to be stored. > +A full path must be given and a leading '/' isn't required.") > + > + (5-minute-hours > + (maybe-integer 48) > + "\ > +Data retention duration for the 5 minute resolution entries. The configuration > +defines for how many past hours entries will be stored. Set to @code{-1} for > +unlimited entries or to @code{0} to disable the data collection of this > +resolution.") > + > + (64bit-interface-counters > + (maybe-integer -2) > + "\ > +Select interface counter handling. Set to @code{1} for defining that all interfaces > +use 64-bit counters on the kernel side and @code{0} for defining 32-bit counter. Set > +to @code{-1} for using the old style logic used in earlier versions where counter > +values within 32-bits are assumed to be 32-bit and anything larger is assumed to > +be a 64-bit counter. This may produce false results if a 64-bit counter is > +reset within the 32-bits. Set to @code{-2} for using automatic detection based on > +available kernel datastructures.") Please reflow these paragraphs so they fit under the 80 characters width limit. Perhaps drop the \ escape, as it doesn't provide much and looks a bit worst, in my opinion. Each sentence should be separated by two spaces (that's a Texinfo convention). This comment applies to all similar documentation texts. > + (always-add-new-interfaces? > + (maybe-boolean #t) > + "\ > +Enable or disable automatic creation of new database entries for interfaces not > +currently in the database even if the database file already exists when the > +daemon is started. New database entries will also get created for new interfaces > +seen while the daemon is running. Pseudo interfaces lo, lo0 and sit0 are always > +excluded from getting added.") The lo, lo0 and sit0 could use a @samp{} or decorator. [...] > +(define (vnstat-serialize-configuration config) > + (mixed-text-file > + "vnstat.conf" > + (serialize-configuration config vnstat-configuration-fields))) > + > +(define (vnstat-shepherd-service config) > + (let ((config-file (vnstat-serialize-configuration config))) > + (match-record config (package pid-file) > + (shepherd-service > + (documentation "Run vnstatd.") > + (requirement `(networking)) > + (provision '(vnstatd)) > + (start #~(make-forkexec-constructor > + (list #$(file-append package "/sbin/vnstatd") > + "--daemon" > + "--config" #$config-file) > + #:pid-file #$pid-file)) > + (stop #~(make-kill-destructor)) > + (actions > + (list (shepherd-configuration-action config-file) I don't understand what (shepherd-configuration-action config-file) corresponds to? > + (shepherd-action > + (name 'reload) > + (documentation "Reload vnstatd.") > + (procedure > + #~(lambda (pid) > + (if pid > + (begin > + (kill pid SIGHUP) > + (format #t > + "Issued SIGHUP to vnstatd (PID ~a)." > + pid)) > + (format #t "vnstatd is not running."))))))))))) > +(define (vnstat-account-service config) > + (match-record config (daemon-group daemon-user) > + (if (every maybe-value-set? (list daemon-group daemon-user)) > + (list > + (user-group > + (name daemon-group) > + (system? #t)) > + (user-account > + (name daemon-user) > + (group daemon-group) > + (system? #t) > + (home-directory "/var/empty") > + (shell (file-append shadow "/sbin/nologin")))) > + '()))) > + > +(define vnstat-service-type > + (service-type > + (name 'vnstat) > + (description "vnStat network-traffic monitor service.") > + (extensions > + (list (service-extension shepherd-root-service-type > + (compose list vnstat-shepherd-service)) > + (service-extension account-service-type > + vnstat-account-service))) > + (default-value (vnstat-configuration)))) The rest LGTM (a system test would be nice, but since the Shepherd service definition is straightforward, it could come later, when the need arise). That appears carefully crafted, thank you! Could you send a v2 with my above comments addressed, keeping me in CC? -- Thanks, Maxim