Commit eb04c58b authored by ZHOU Shihang's avatar ZHOU Shihang
Browse files

feat: update readme

parents
/main.html
/venv/
MIT License
Copyright (c) 2021 ZHOU Shihang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# joremon-summary-visualisation
Python module for plotting job summmaries aggregation from `Elias`
By default, all jobs are selected into the plot. Logical and filters are applicable; time range (in millisecond) filter is applicable.
### Usage Example
`from connectionES import add_time_range_filter, get_basic_query, add_single_filter`
`from summary import plot_summary`
`q = get_basic_query()`
`q = add_single_filter(q, "tags.batch", '2')`
`q = add_time_range_filter(q, 1623229442, 1624266242)`
`plot_summary(q)`
\ No newline at end of file
from elasticsearch import Elasticsearch
def get_basic_query():
return {
"query": {
"bool": {
"filter": []
}
}
}
def get_summary(query, full_endpoint):
es = Elasticsearch(
[full_endpoint],
verify_certs=False
)
page_size = 10
query = es.search(index="lsst-batch-summary", body=query, scroll='5m', size=page_size)
results = list(map(lambda x: x["_source"], query['hits']['hits']))
total = query['hits']['total']["value"]
print(total)
scroll_id = query['_scroll_id']
for i in range(0, int(total / page_size) + 1):
query_scroll = es.scroll(scroll_id=scroll_id, scroll='5m')['hits']['hits']
data = list(map(lambda x: x["_source"], query_scroll))
results += data
return results
def add_single_filter(q, field, value):
q["query"]["bool"]["filter"].append({"term": {str(field): value}})
return q
def add_time_range_filter(q, start, end):
q["query"]["bool"]["filter"].append({"range": {"Timestamp": {"gte": start, "lte": end, "format": "epoch_millis"}}})
return q
import sys
import summary
import connectionES
if __name__ == "__main__":
if len(sys.argv) < 2:
print("missing end point arg")
exit(1)
q = connectionES.get_basic_query()
# q = connectionES.add_single_filter(q, "tags.batch", '2')
# q = connectionES.add_time_range_filter(q, 1623229442, 1624266242)
summary.plot_summary(q, sys.argv[1])
import datetime
import numpy as np
from bokeh.models import NumeralTickFormatter
from bokeh.plotting import figure
def plot_histo(data, item_name):
if item_name == "JobPeakCPUPercent":
datapoints = list(map(lambda x: x / 100, data))
else:
datapoints = data
hist, edges = np.histogram(datapoints, density=False, bins="auto")
p = figure(title="resource consumption statistics of " + item_name, tools='', background_fill_color="#fafafa")
mean = np.mean(datapoints)
# var = round(np.var(datapoints), 2)
if item_name == "JobPeakCPUPercent":
axis_unit = "100 %"
maximum = str(round(edges[-1] * 100, 2)) + "%"
mean_display = str(round(mean * 100, 2)) + "%"
elif item_name == "JobCPUTime" or item_name == "JobClockTime":
axis_unit = "00:00:00"
maximum = str(datetime.timedelta(seconds=round(edges[-1])))
mean_display = str(datetime.timedelta(seconds=round(mean)))
else:
axis_unit = "0.000 b"
maximum = humanbytes(edges[-1])
mean_display = humanbytes(mean)
p.xaxis.formatter = NumeralTickFormatter(format=axis_unit)
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="navy", line_color="white", alpha=0.5)
p.xaxis.axis_label = item_name + ', max : ' + maximum + ", mean: " + mean_display # + ", var: " + str(var)
p.yaxis.axis_label = 'count'
p.grid.grid_line_color = "white"
return p
def humanbytes(B):
B = float(B)
KB = float(1024)
MB = float(KB ** 2) # 1,048,576
GB = float(KB ** 3) # 1,073,741,824
TB = float(KB ** 4) # 1,099,511,627,776
if B < KB:
return '{0} {1}'.format(B, 'Bytes' if 0 == B > 1 else 'Byte')
elif KB <= B < MB:
return '{0:.2f} KiB'.format(B / KB)
elif MB <= B < GB:
return '{0:.2f} MiB'.format(B / MB)
elif GB <= B < TB:
return '{0:.2f} GiB'.format(B / GB)
elif TB <= B:
return '{0:.2f} TiB'.format(B / TB)
elasticsearch~=7.9.1
elasticsearch_dsl>=7.0.0,<8.0.0
bokeh~=2.3.2
numpy~=1.20.3
\ No newline at end of file
from bokeh.layouts import gridplot
from bokeh.plotting import show
from plotBokeh import plot_histo
from connectionES import get_summary, add_time_range_filter, get_basic_query, add_single_filter
def plot_summary(search_query, full_endpoint):
results = get_summary(search_query, full_endpoint)
if len(results) > 0:
show(gridplot([
plot_histo(list(map(lambda x: x["JobPeakCPUPercent"], results)), "JobPeakCPUPercent"),
plot_histo(list(map(lambda x: x["JobCPUTime"], results)), "JobCPUTime"),
plot_histo(list(map(lambda x: x["JobClockTime"], results)), "JobClockTime"),
plot_histo(list(map(lambda x: x["JobPeakRSS"], results)), "JobPeakRSS"),
plot_histo(list(map(lambda x: x["JobPeakVMS"], results)), "JobPeakVMS"),
plot_histo(list(map(lambda x: x["JobRBytesFromDisk"], results)), "JobRBytesFromDisk"),
plot_histo(list(map(lambda x: x["JobWBytesToDisk"], results)), "JobWBytesToDisk"),
plot_histo(list(map(lambda x: x["JobRBytesTotal"], results)), "JobRBytesTotal"),
plot_histo(list(map(lambda x: x["JobWBytesTotal"], results)), "JobWBytesTotal")
], ncols=3, plot_width=630, plot_height=300, toolbar_location=None))
else:
print("no results")
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