add lturping snippet

parent b44789a7
Pipeline #125684 passed with stage
in 2 minutes and 27 seconds
......@@ -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
......
......@@ -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``.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment