From cd33550740921d183d2bb4ad60fa9f798acffd74 Mon Sep 17 00:00:00 2001 From: msimonin <matthieu.simonin@inria.fr> Date: Mon, 10 Feb 2020 11:04:59 +0100 Subject: [PATCH] fix doc --- README.org | 59 +++++++++++++++++++++++++++++++++++ README.rst | 70 +++++++++++++++++++++++++++++++++++++++--- examples/timeseries.py | 4 +-- examples/vlan_set_2.py | 4 +-- 4 files changed, 129 insertions(+), 8 deletions(-) diff --git a/README.org b/README.org index 044b796..48c4b90 100644 --- a/README.org +++ b/README.org @@ -489,6 +489,65 @@ In [2]: # gk is your entry point site.vlans[vlanid].submit({"nodes": nodes}) #+END_SRC +** Metrics API +*** Get some timeseries (and plot them) + For this example you'll need ~matplotlib~, ~seaborn~ and ~pandas~. + + #+BEGIN_SRC python :exports code :tangle examples/timeseries.py + import logging + import os + + from grid5000 import Grid5000 + + import pandas as pd + import matplotlib.pyplot as plt + import seaborn as sns + import time + + logging.basicConfig(level=logging.DEBUG) + + conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") + gk = Grid5000.from_yaml(conf_file) + + metrics = gk.sites["lyon"].metrics + print("--- available metrics") + print(metrics.list()) + + print("---- power metric") + print(metrics["power"]) + + print("----- a timeserie") + now = time.time() + kwargs = { + "only": "nova-1,nova-2,nova-3", + "resolution": 1, + "from": int(now - 600), + "to": int(now) + } + timeseries = metrics["power"].timeseries.list(**kwargs) + + # let's visualize this + df = pd.DataFrame() + for timeserie in timeseries: + print(timeserie) + timestamp = timeserie.timestamps + value = timeserie.values + measurement = timeserie.uid + df = pd.concat([df, pd.DataFrame({ + "timestamp": timestamp, + "value": value, + "measurement": [measurement]*len(timestamp) + })]) + + sns.relplot(data=df, + x="timestamp", + y="value", + hue="measurement", + kind="line") + plt.show() + #+END_SRC + + ** More snippets *** Site of a cluster diff --git a/README.rst b/README.rst index d5f94f1..4cedc02 100644 --- a/README.rst +++ b/README.rst @@ -505,10 +505,72 @@ Before starting, the file ``$HOME/.python-grid5000.yaml`` will be loaded. # set in vlan site.vlans[vlanid].submit({"nodes": nodes}) -4.8 More snippets +4.8 Metrics API +~~~~~~~~~~~~~~~ + +4.8.1 Get some timeseries (and plot them) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +For this example you’ll need ``matplotlib``, ``seaborn`` and ``pandas``. + +.. code:: python + + import logging + import os + + from grid5000 import Grid5000 + + import pandas as pd + import matplotlib.pyplot as plt + import seaborn as sns + import time + + logging.basicConfig(level=logging.DEBUG) + + conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") + gk = Grid5000.from_yaml(conf_file) + + metrics = gk.sites["lyon"].metrics + print("--- available metrics") + print(metrics.list()) + + print("---- power metric") + print(metrics["power"]) + + print("----- a timeserie") + now = time.time() + kwargs = { + "only": "nova-1,nova-2,nova-3", + "resolution": 1, + "from": int(now - 600), + "to": int(now) + } + timeseries = metrics["power"].timeseries.list(**kwargs) + + # let's visualize this + df = pd.DataFrame() + for timeserie in timeseries: + print(timeserie) + timestamp = timeserie.timestamps + value = timeserie.values + measurement = timeserie.uid + df = pd.concat([df, pd.DataFrame({ + "timestamp": timestamp, + "value": value, + "measurement": [measurement]*len(timestamp) + })]) + + sns.relplot(data=df, + x="timestamp", + y="value", + hue="measurement", + kind="line") + plt.show() + +4.9 More snippets ~~~~~~~~~~~~~~~~~ -4.8.1 Site of a cluster +4.9.1 Site of a cluster ^^^^^^^^^^^^^^^^^^^^^^^ .. code:: python @@ -536,7 +598,7 @@ Before starting, the file ``$HOME/.python-grid5000.yaml`` will be loaded. clusters.remove(matching[0]) print("We found the following matches %s" % matches) -4.8.2 Get all job with a given name on all the sites +4.9.2 Get all job with a given name on all the sites ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code:: python @@ -577,7 +639,7 @@ Before starting, the file ``$HOME/.python-grid5000.yaml`` will be loaded. for job in jobs: job.delete() -4.8.3 Caching API responses +4.9.3 Caching API responses ^^^^^^^^^^^^^^^^^^^^^^^^^^^ The Grid’5000 reference API is static. In this situation to speed up the diff --git a/examples/timeseries.py b/examples/timeseries.py index 2f7c921..82a7ba0 100644 --- a/examples/timeseries.py +++ b/examples/timeseries.py @@ -28,9 +28,9 @@ kwargs = { "from": int(now - 600), "to": int(now) } +timeseries = metrics["power"].timeseries.list(**kwargs) # let's visualize this -timeseries = metrics["power"].timeseries.list(**kwargs) df = pd.DataFrame() for timeserie in timeseries: print(timeserie) @@ -48,4 +48,4 @@ sns.relplot(data=df, y="value", hue="measurement", kind="line") -plt.show() \ No newline at end of file +plt.show() diff --git a/examples/vlan_set_2.py b/examples/vlan_set_2.py index 00476f9..fa9b154 100644 --- a/examples/vlan_set_2.py +++ b/examples/vlan_set_2.py @@ -11,7 +11,7 @@ logging.basicConfig(level=logging.DEBUG) def _to_network_address(host, interface): """Translate a host to a network address e.g: - paravance-20.rennes.grid5000.fr -> paravance-20-eth2.rennes.grid5000.fr + paranoia-20.rennes.grid5000.fr -> paranoia-20-eth2.rennes.grid5000.fr """ splitted = host.split('.') splitted[0] = splitted[0] + "-" + interface @@ -26,7 +26,7 @@ site = gk.sites["rennes"] job = site.jobs.create({"name": "pyg5k", "command": "sleep 3600", - "resources": "{type='kavlan'}/vlan=1+{cluster='paravance'}nodes=1", + "resources": "{type='kavlan'}/vlan=1+{cluster='paranoia'}nodes=1", "types": ["deploy"] }) -- GitLab