Mentions légales du service

Skip to content
Snippets Groups Projects
Commit e7de8a20 authored by JONGLEZ Baptiste's avatar JONGLEZ Baptiste
Browse files

Regenerate ReST README

parent 82bed9ed
No related branches found
No related tags found
1 merge request!7Improve SSL user experience on Grid'5000
...@@ -88,9 +88,10 @@ conform with the Grid5000 API models (with an ’s’!) ...@@ -88,9 +88,10 @@ conform with the Grid5000 API models (with an ’s’!)
password: MYPASSWORD password: MYPASSWORD
' > ~/.python-grid5000.yaml ' > ~/.python-grid5000.yaml
- When accessing the API from a Grid’5000 frontend, providing the username and - When accessing the API from a Grid’5000 frontend, providing the username
password is optionnal. Nevertheless you’ll need to deal with SSL verification and password is optionnal. Authentication should work out-of-the-box; if
by specifying the path to the certificate to use: it fails, try updating python-grid5000, or specify the path to the
certificate to use:
:: ::
...@@ -614,51 +615,7 @@ connected to other testbeds for experiments involving wide area layer2 networks. ...@@ -614,51 +615,7 @@ connected to other testbeds for experiments involving wide area layer2 networks.
5.8 Metrics API 5.8 Metrics API
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
5.8.1 Get the timeseries corresponding to a job 5.8.1 Get some timeseries (and plot them)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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)
5.8.2 Get some timeseries (and plot them)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For this example you’ll need ``matplotlib``, ``seaborn`` and ``pandas``. For this example you’ll need ``matplotlib``, ``seaborn`` and ``pandas``.
...@@ -675,45 +632,40 @@ For this example you’ll need ``matplotlib``, ``seaborn`` and ``pandas``. ...@@ -675,45 +632,40 @@ For this example you’ll need ``matplotlib``, ``seaborn`` and ``pandas``.
import seaborn as sns import seaborn as sns
import time import time
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.INFO)
conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml")
gk = Grid5000.from_yaml(conf_file) gk = Grid5000.from_yaml(conf_file)
metrics = gk.sites["lyon"].metrics metrics = gk.sites["lyon"].clusters["nova"].metrics
print("--- available metrics") print("--- available metrics")
print(metrics.list()) print(metrics)
print("---- power metric")
print(metrics["power"])
print("----- a timeserie") print("----- a timeserie")
now = time.time() now = time.time()
# NOTE that you can pass a job_id here
kwargs = { kwargs = {
"only": "nova-1,nova-2,nova-3", "nodes": "nova-1,nova-2,nova-3",
"resolution": 1, "metrics": "wattmetre_power_watt",
"from": int(now - 600), "start_time": int(now - 600),
"to": int(now)
} }
timeseries = metrics["power"].timeseries.list(**kwargs) metrics = gk.sites["lyon"].metrics.list(**kwargs)
# let's visualize this # let's visualize this
df = pd.DataFrame() df = pd.DataFrame()
for timeserie in timeseries: for metric in metrics:
print(timeserie) timestamp = metric.timestamp
timestamp = timeserie.timestamps value = metric.value
value = timeserie.values device_id = metric.device_id
measurement = timeserie.uid
df = pd.concat([df, pd.DataFrame({ df = pd.concat([df, pd.DataFrame({
"timestamp": timestamp, "timestamp": [timestamp],
"value": value, "value": [value],
"measurement": [measurement]*len(timestamp) "device_id": [device_id]
})]) })])
sns.relplot(data=df, sns.relplot(data=df,
x="timestamp", x="timestamp",
y="value", y="value",
hue="measurement", hue="device_id",
kind="line") kind="line")
plt.show() plt.show()
......
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