-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash.py
252 lines (195 loc) · 10.5 KB
/
dash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#dash.py
from glob import glob
import numpy as np
import pandas as pd
import polars as pl
import pathlib2 as pl2
import streamlit as st
from plot import plot_bokeh
from bokeh.plotting import figure
from bokeh.palettes import Spectral8
from bokeh.models import ColumnDataSource, RangeTool,\
Range1d, HoverTool, Circle, LinearAxis
import plost
LOGDIR='log/clusteruse'
Ht=560 #PLOTHEIGHT
FILEPATTERN='202*.log'
'''
2023-06-06 00:05 jobs_running=376 jobs_queued=665 jobs_held=0
jobs_exiting=0 nodes_running=1308 nodes_offline=645 nodes_total=1368
nodes_running_percent=95.61% cpu_used=15906 cpu_total=33160
cpu_percent=47.97%
'''
cols =['time', 'jobs_running', 'jobs_queued', 'jobs_held', 'jobs_exiting',
'nodes_running', 'nodes_offline', 'nodes_total', 'nodes_running_percent',
'cpu_used', 'cpu_total', 'cpu_percent' ]
cols_int = ['jobs_running', 'jobs_queued', 'jobs_held', 'jobs_exiting',
'nodes_running', 'nodes_offline', 'nodes_total',
'cpu_used', 'cpu_total' ]
cols_float = [ 'nodes_running_percent', 'cpu_percent' ]
dtypes = {'jobs_running': 'int', 'jobs_queued': 'int',
'jobs_held': 'int', 'jobs_exiting': 'int',
'nodes_running': 'int', 'nodes_offline': 'int', 'nodes_total': 'int',
'nodes_running_percent': 'float',
'cpu_used': 'int', 'cpu_total': 'int', 'cpu_percent': 'float' }
icols =['jobs_running', 'jobs_queued', 'jobs_held', 'jobs_exiting',
'nodes_running', 'nodes_offline', 'nodes_total',
'cpu_used', 'cpu_total', ]
fcols=['nodes_running_percent',
'cpu_percent' ]
job_cols =['jobs_running', 'jobs_queued', 'jobs_held', 'jobs_exiting', ]
node_cols=['nodes_running', 'nodes_offline', 'nodes_total', 'nodes_running_percent',]
cpu_cols =['cpu_used', 'cpu_total', 'cpu_percent' ]
num_cols =['jobs_running', 'jobs_queued', 'jobs_held', 'jobs_exiting',
'nodes_running', 'nodes_offline', 'nodes_total', 'nodes_running_percent',
'cpu_used', 'cpu_total', 'cpu_percent' ]
def show_dash(st, dash):
def redraw():
pass
def sb_period(x):
if x=='1d': return '1 Day'
if x=='1w': return '1 Week'
if x=='1m': return '1 Month'
if x=='1y': return '1 Year'
return x
with dash:
period_d = { '1d': 2, '1w': 7, '1m':30, '1y':365, 'all': 0} #read at least 2 files
col1, col2 = st.columns([1, 2])
with col1:
st.selectbox("Period", period_d.keys(), key='graph_period',
index=0, format_func=sb_period, on_change=redraw())
with col2:
st.checkbox("Show node counts", key='graph_nodes')
col3, col4 = st.columns(2)
with col3:
placeholder_1 = st.empty()
with col4:
placeholder_2 = st.empty()
with st.spinner('Retrieving queue status'):
ps = pl2.Path(LOGDIR)
df = pl.DataFrame()
files = sorted(list(ps.glob(FILEPATTERN)))
s_files = files[ -period_d[st.session_state.graph_period]::]
for p in s_files:
try:
dfs = pl.read_csv(str(p),
has_header=False,
new_columns=cols,
try_parse_dates=True,
null_values = '' )
except:
print("ERROR reading csv file", p)
continue
df = df.vstack(dfs)
if len(df)==0:
st.warning('No logs found in subdirectory \"log" ')
return
else:
df=df.with_columns ( pl.col(cols[1::]).str.replace(r'\D+\=(\d*\.?\d*)', "$1"))
df=df.with_columns ( pl.col(cols[1::]).str.replace(r'[\%]', ""))
df=df.with_columns ( pl.col(cols[1::]).str.replace('', '00'))
df=df.with_columns(df.select( [
pl.col('time').cast(pl.Datetime),
pl.col(cols_int).cast(pl.Int32),
pl.col(cols_float).cast(pl.Float32) ]))
df.with_columns(dtime = df['time'].dt.strftime('%Y-%m-%d %H:%M'))
if st.session_state.graph_period == '1m': #
every = '1h'
elif st.session_state.graph_period == '1y':
every = '4h'
elif st.session_state.graph_period == 'all':
every = '24h'
else:
every = ''
if every != '':
# df = df.fill_null(0)
try:
df = df.with_columns(pl.col('time').set_sorted()).groupby_dynamic(
'time',
every=every,
check_sorted=False,
#period='2h' #<<< TBD
).agg(
pl.all().exclude(
'time','dtime').mean()
)
except pl.exceptions.ComputeError as p:
print("Polars exception", p)
placeholder_1.write("From: " + str(df['time'][0]))
placeholder_2.write("To: " + str(df['time'][-1]))
tooltips = [
("", "@y "),
#("Values","$cpu_percent"),
#('', ""),
#('', "$y2 "),
#("cpu>", "@cpu_percent"),
#('X2', "$y2")
]
formatters={
'@{y}' : 'printf' ,
'@{x}' : 'printf',
#'@{$cpu_percent}' : 'printf',
#'@{cpu_percent}' : 'printf df["cpu_percent"]',
#'@{nodes_running_percent}' : 'printf',
}
p = figure(
title='Lengau % Usage',
height=300,
x_axis_type="datetime",
x_axis_location="below",
x_axis_label='Time',
y_axis_label='cpu_percent',
x_range=Range1d(df['time'][0], df['time'][-1]),
)
cp = p.line(df['time'], df['cpu_percent'], color='red', legend_label='CPU %',)
np = p.line(df['time'], df['nodes_running_percent'], legend_label='Nodes %', color='green')
if st.session_state.graph_nodes:
p.extra_y_ranges['nodes'] = Range1d(df['nodes_running'].min(), df['nodes_running'].max())
nr = p.line(df['time'], df['nodes_running'], color="blue", y_range_name='nodes', legend_label='Nodes running')
no = p.line(df['time'], df['nodes_offline'], color="orange", y_range_name='nodes', legend_label='Nodes offline')
ax2 = LinearAxis(y_range_name="nodes", axis_label="Nodes running")
ax2.axis_label_text_color ="navy"
p.add_layout(ax2, 'right')
p.y_range=Range1d(0,100)
# if st.session_state.circles:
# cpc = p.circle_y(df['time'], df['cpu_percent'], color='red',legend_label="CPU")
# npc = p.circle_x(df['time'], df['nodes_running_percent'], color='blue', legend_label="Nodes")
if st.session_state.graph_nodes:
renderers = [ cp, np, nr, no]
else:
renderers = [ cp, np, ]
hover = HoverTool(#names=hovernames,
mode="vline",
tooltips = tooltips,
formatters=formatters,
renderers = renderers #[ cp, np, ],
)
p.add_tools(hover)
p.add_layout(p.legend[0], 'right')
st.bokeh_chart(p, use_container_width=True)
q = figure(
x_axis_type="datetime", x_axis_location="below",
x_range=Range1d(df['time'][0], df['time'][-1]),
title='Jobs',
x_axis_label='Time',
y_axis_label='Jobs',
height=300,
)
hover2 = HoverTool(
tooltips =tooltips,
formatters= formatters, #{
mode="vline",
)
hover2.renderers = []
colors = ['red', 'green', 'blue', 'orange']
for col in job_cols:
hr_render= q.line( df['time'],df[col],
color = colors[job_cols.index(col)],
legend_label=col)
hover2.renderers.append(hr_render)
q.add_tools(hover2)
q.add_layout(q.legend[0], 'right')
st.bokeh_chart(q, use_container_width=True)
with st.expander('Data (' + str(len(df)) + ' items)' ):
st.dataframe(df)
st.spinner("Done")