Mentions légales du service

Skip to content
Snippets Groups Projects
Verified Commit cd335507 authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

fix doc

parent 4b33015e
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
......@@ -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()
......@@ -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"]
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment