From 7db6cb82a62498e526cfe97f355342458a8b5f96 Mon Sep 17 00:00:00 2001 From: msimonin <matthieu.simonin@inria.fr> Date: Thu, 5 Mar 2020 17:44:48 +0100 Subject: [PATCH] add lturping snippet --- README.org | 42 ++++++++++++++++++++++++++++++++++++++++++ README.rst | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 3c0b9e6..bffe4b4 100644 --- a/README.org +++ b/README.org @@ -490,6 +490,47 @@ In [2]: # gk is your entry point #+END_SRC ** Metrics API +*** Get the timeseries corresponding to a job + Credits to ~lturpin~. + #+BEGIN_SRC python :exports code :tangle examples/job_timeseries.py +import logging +import os + +from grid5000 import Grid5000 + + +logging.basicConfig(level=logging.DEBUG) + + +def get_job_consumption(job_id, gk, site): + metrics = gk.sites[site].metrics + job = gk.sites[site].jobs[job_id] + # nodes as list : "cluster-number.site.grid5000.fr" + nodes_dom = job.assigned_nodes + # nodes as list : "cluster-number" + nodes = map(lambda node_dom: node_dom.split('.')[0], nodes_dom) + # nodes as string : "cluster-number,cluster-number,..." + nodes_str = ','.join(nodes) + + start = job.started_at + end = job.stopped_at + kwargs = { + "only": nodes_str, + "resolution": 1, + "from": start, + "to": end + } + timeseries = metrics["power"].timeseries.list(**kwargs) + return timeseries + + +conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") +gk = Grid5000.from_yaml(conf_file) + +timeseries = get_job_consumption("1092446", gk, "lyon") +print(timeseries) + #+END_SRC + *** Get some timeseries (and plot them) For this example you'll need ~matplotlib~, ~seaborn~ and ~pandas~. @@ -548,6 +589,7 @@ In [2]: # gk is your entry point #+END_SRC + ** More snippets *** Site of a cluster diff --git a/README.rst b/README.rst index 011f87e..7e504fa 100644 --- a/README.rst +++ b/README.rst @@ -508,7 +508,51 @@ Before starting, the file ``$HOME/.python-grid5000.yaml`` will be loaded. 4.8 Metrics API ~~~~~~~~~~~~~~~ -4.8.1 Get some timeseries (and plot them) +4.8.1 Get the timeseries corresponding to a job +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Credits to ``lturpin``. + +.. code:: python + + import logging + import os + + from grid5000 import Grid5000 + + + logging.basicConfig(level=logging.DEBUG) + + + def get_job_consumption(job_id, gk, site): + metrics = gk.sites[site].metrics + job = gk.sites[site].jobs[job_id] + # nodes as list : "cluster-number.site.grid5000.fr" + nodes_dom = job.assigned_nodes + # nodes as list : "cluster-number" + nodes = map(lambda node_dom: node_dom.split('.')[0], nodes_dom) + # nodes as string : "cluster-number,cluster-number,..." + nodes_str = ','.join(nodes) + + start = job.started_at + end = job.stopped_at + kwargs = { + "only": nodes_str, + "resolution": 1, + "from": start, + "to": end + } + timeseries = metrics["power"].timeseries.list(**kwargs) + return timeseries + + + conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") + gk = Grid5000.from_yaml(conf_file) + + timeseries = get_job_consumption("1092446", gk, "lyon") + print(timeseries) + +4.8.2 Get some timeseries (and plot them) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For this example you’ll need ``matplotlib``, ``seaborn`` and ``pandas``. -- GitLab