Support setting and displaying timezone with the core metrics plugin

This commit is contained in:
Nate Coraor
2025-05-06 11:45:51 -04:00
parent 79638b883a
commit decf037cd3
2 changed files with 68 additions and 43 deletions
+47 -38
View File
@@ -27,24 +27,38 @@ If no configuration is specified, the default is to load only the ``core`` plugi
Available Job Metrics Plugins
-----------------------------
The list of metrics plugins implemented in the code can be found at ``lib/galaxy/job_metrics/instrumenters``.
The list of metrics plugins implemented in the code can be found at ``lib/galaxy/job_metrics/instrumenters``. A list of
available plugins and example configurations follows.
core
~~~~
The core plugin captures the number of cores allocated to the job (``$GALAXY_SLOTS``), the start and end time of job (in
seconds since epoch) and computes the runtime in seconds.
It has no options.
.. code-block:: yaml
- type: core
timezone: UTC
The core plugin captures the number of cores allocated to the job (``$GALAXY_SLOTS``), the start and end time of job (in
seconds since epoch) and computes the runtime in seconds.
The optional ``timezone`` option (default: ``null``) controls how times are displayed in the UI. If unset, times are
displayed in server local time. Note that not all values respect daylight savings time; for example, ``US/Eastern``,
``America/New_York``, and ``EST5EDT`` do, whereas ``EST`` does not. Possible values are determined by the server time
zone library and can be listed with the following command:
.. code-block:: shell
python3 -c 'import zoneinfo; list(map(print, sorted(zoneinfo.available_timezones())))'
cpuinfo
~~~~~~~
.. code-block:: yaml
- type: cpuinfo
verbose: false
The cpuinfo plugin captures the processor count on the system that that job ran on (note that this may differ from the
number of CPUs actually allocated to the job).
@@ -53,54 +67,43 @@ The optional ``verbose`` option (default: ``false``) captures details (likely fa
The cpuinfo plugin works on Linux only.
.. code-block:: yaml
- type: cpuinfo
verbose: false
meminfo
~~~~~~~
.. code-block:: yaml
- type: meminfo
The meminfo plugin captures the memory information on the system that the job ran on (note that this may differ from the
amount of memory actually allocated to the job).
It has no options.
.. code-block:: yaml
- type: meminfo
hostname
~~~~~~~~
The hostname plugin captures the output of ``hostname`` on the system that the job ran on.
It has no options.
.. code-block:: yaml
- type: hostname
uname
~~~~~
The uname plugin captures the output of ``uname -a`` on the system that the job ran on.
The hostname plugin captures the output of ``hostname`` on the system that the job ran on.
It has no options.
uname
~~~~~
.. code-block:: yaml
- type: uname
The uname plugin captures the output of ``uname -a`` on the system that the job ran on.
It has no options.
env
~~~
The env plugin captures environment variables set in the job's executing environment.
By default, it captures **all** environment variables, which is likely excessive but may be useful for debugging. The
optional ``variables`` option can be set to a list of variables to capture (if set). For legacy purposes, this can also
be a comma-separated string of variable names.
.. code-block:: yaml
- type: env
@@ -109,9 +112,24 @@ be a comma-separated string of variable names.
- SLURM_CPUS_ON_NODE
- SLURM_JOBID
The env plugin captures environment variables set in the job's executing environment.
By default, it captures **all** environment variables, which is likely excessive but may be useful for debugging. The
optional ``variables`` option can be set to a list of variables to capture (if set). For legacy purposes, this can also
be a comma-separated string of variable names.
cgroup
~~~~~~
.. code-block:: yaml
- type: cgroup
verbose: false
version: 2
params:
- cpu.stat
- memory.peak
The cgroup plugin captures values set by `Linux Control Groups (cgroups)
<https://docs.kernel.org/admin-guide/cgroup-v2.html>`_. This is most useful if your jobs run in unique per-job Cgroups
(as Slurm does `if so configured <https://slurm.schedmd.com/cgroups.html>`_).
@@ -132,15 +150,6 @@ comma-separated string of cgroup parameter names.
The cgroup plugin works on Linux only.
.. code-block:: yaml
- type: cgroup
verbose: false
version: 2
params:
- cpu.stat
- memory.peak
Overriding the Global Job Metrics Configuration
-----------------------------------------------
+21 -5
View File
@@ -1,12 +1,14 @@
"""The module describes the ``core`` job metrics plugin."""
import datetime
import json
import logging
import time
import zoneinfo
from typing import (
Any,
Dict,
List,
Optional,
)
from . import InstrumentPlugin
@@ -29,6 +31,16 @@ CONTAINER_TYPE = "container_type"
class CorePluginFormatter(JobMetricFormatter):
def __init__(self, timezone: Optional[str]):
self.tz = None
self.strftime_format = "%Y-%m-%d %H:%M:%S"
self.__init_tz(timezone)
def __init_tz(self, timezone: Optional[str]):
if timezone:
self.tz = zoneinfo.ZoneInfo(timezone)
self.strftime_format = "%Y-%m-%d %H:%M:%S %Z (%z)"
def format(self, key: str, value: Any) -> FormattedMetric:
if key == CONTAINER_ID:
return FormattedMetric("Container ID", value)
@@ -42,9 +54,9 @@ class CorePluginFormatter(JobMetricFormatter):
elif key == RUNTIME_SECONDS_KEY:
return FormattedMetric("Job Runtime (Wall Clock)", seconds_to_str(value))
else:
# TODO: Use localized version of this from galaxy.ini
title = "Job Start Time" if key == START_EPOCH_KEY else "Job End Time"
return FormattedMetric(title, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(value)))
dt = datetime.datetime.fromtimestamp(value, tz=self.tz)
return FormattedMetric(title, dt.strftime(self.strftime_format))
class CorePlugin(InstrumentPlugin):
@@ -53,11 +65,15 @@ class CorePlugin(InstrumentPlugin):
"""
plugin_type = "core"
formatter = CorePluginFormatter()
formatter = None
default_safety = Safety.SAFE
def __init__(self, **kwargs):
pass
self.__init_formatter(kwargs.get("timezone"))
def __init_formatter(self, timezone: Optional[str]):
if CorePlugin.formatter is None:
CorePlugin.formatter = CorePluginFormatter(timezone)
def pre_execute_instrument(self, job_directory: str) -> List[str]:
commands = []