From 85348130231d2e73d6ca79963cf1976a35efdecb Mon Sep 17 00:00:00 2001 From: Paul Millar Date: Fri, 7 Jan 2022 15:55:32 +0100 Subject: [PATCH] pnfsmanager: add support for resetting gauge and counter statistics Motivation: PnfsManager provides statistics (both gauge and counter based) covering how long certain operations take. These statistics are initially zero and currently cannot be reset. Sometimes it's useful to reset the statistics, particularly if there's anticipated activity of interest. Modification: Add admin commands to support resetting the gauge and counters. Result: PnfsManager now has two commands to support resetting the gauge and counter statistics available through the 'info' command. Target: master Requires-notes: yes Requires-book: no Request: 7.2 Request: 7.1 Request: 7.0 Request: 6.2 Patch: https://rb.dcache.org/r/13361/ Acked-by: Lea Morschel --- .../namespace/ChimeraNameSpaceProvider.java | 17 +++++++- .../namespace/PnfsManagerV3.java | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/ChimeraNameSpaceProvider.java b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/ChimeraNameSpaceProvider.java index 8a9c661216f..ab3bd5ff206 100644 --- a/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/ChimeraNameSpaceProvider.java +++ b/modules/dcache-chimera/src/main/java/org/dcache/chimera/namespace/ChimeraNameSpaceProvider.java @@ -53,8 +53,10 @@ import diskCacheV111.util.PnfsId; import diskCacheV111.util.RetentionPolicy; import diskCacheV111.vehicles.StorageInfo; +import dmg.cells.nucleus.CellCommandListener; import dmg.cells.nucleus.CellInfo; import dmg.cells.nucleus.CellInfoProvider; +import dmg.util.command.Command; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -71,6 +73,7 @@ import java.util.Optional; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import java.util.regex.Pattern; @@ -116,7 +119,7 @@ import org.springframework.beans.factory.annotation.Required; public class ChimeraNameSpaceProvider - implements NameSpaceProvider, CellInfoProvider { + implements NameSpaceProvider, CellInfoProvider, CellCommandListener { private static final int SYMLINK_MODE = 0777; @@ -855,6 +858,18 @@ public void getInfo(PrintWriter pw) { pw.println(_counters); } + + @Command(name = "reset chimera stats", hint="reset chimera statistics", description = "Reset" + + " the counters and gauge statistics describing the interaction with Chimera.") + public class ResetStatsCommand implements Callable { + @Override + public String call() { + _gauges.reset(); + _counters.reset(); + return ""; + } + } + @Override public Collection find(Subject subject, PnfsId pnfsId) throws CacheException { try { diff --git a/modules/dcache/src/main/java/diskCacheV111/namespace/PnfsManagerV3.java b/modules/dcache/src/main/java/diskCacheV111/namespace/PnfsManagerV3.java index a8c25177e2e..fc37287048f 100644 --- a/modules/dcache/src/main/java/diskCacheV111/namespace/PnfsManagerV3.java +++ b/modules/dcache/src/main/java/diskCacheV111/namespace/PnfsManagerV3.java @@ -535,6 +535,46 @@ public void getInfo(PrintWriter pw) { pw.println(_foldedCounters.toString()); } + @Command(name = "reset stats", hint="reset statistics", + description = "Reset the counters and gauge statistics describing PnfsManager. These" + + " statistics are shown as part of the 'info' command output.") + public class ResetStatsCommand implements Callable { + + @Option(name="target", usage="Which statistics to reset:\n" + + "\n" + + "\"calls\" is the cell message call gauges, labelled 'PnfsManagerV3'.\n" + + "\n" + + "\"folds\" is the message folding counts, labelled 'PnfsManagerV3.Folded'.\n" + + "\n" + + "\"all\" resets everything.\n" + + "\n" + + "If this option is not specified then \"all\" is assumed.", + values={"calls", "folds", "all"}) + private String target; + + @Override + public String call() throws CommandException { + if (target == null) { + target = "all"; + } + switch (target) { + case "all": + _gauges.reset(); + _foldedCounters.reset(); + break; + case "calls": + _gauges.reset(); + break; + case "folds": + _foldedCounters.reset(); + break; + default: + throw new CommandException("Unknown target \"" + target + "\"."); + } + return ""; + } + } + @Command(name = "pnfsidof", hint = "find the Pnfs-Id of a file", description = "Print the Pnfs-Id of a file given by its absolute path.")