Spaces:
Sleeping
Sleeping
Update streamlit_dashboard.py
Browse files- streamlit_dashboard.py +32 -24
streamlit_dashboard.py
CHANGED
@@ -139,57 +139,65 @@ def save_system_health(mongo_status, chroma_status, api_status, llm_status):
|
|
139 |
|
140 |
def plot_status(df_service, title, container):
|
141 |
"""
|
142 |
-
Plots the health status of a single service over time
|
|
|
143 |
"""
|
144 |
if df_service.empty:
|
145 |
container.info(f"No data available for {title}.")
|
146 |
return
|
147 |
|
148 |
-
# Ensure data is sorted by Time for correct line/step plotting
|
149 |
-
df_service = df_service.sort_values('Time')
|
|
|
|
|
|
|
|
|
150 |
|
151 |
fig = px.line(
|
152 |
df_service,
|
153 |
x="Time",
|
154 |
y="StatusNumeric",
|
155 |
-
color="ReadableStatus",
|
156 |
title=title,
|
157 |
-
color_discrete_map={
|
158 |
"LIVE": "green",
|
159 |
"DISCONNECTED": "red"
|
160 |
},
|
161 |
-
labels={"StatusNumeric": "Status"},
|
162 |
-
line_shape=
|
163 |
-
markers=True
|
164 |
)
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
fig.update_layout(
|
172 |
yaxis=dict(
|
173 |
tickmode="array",
|
174 |
tickvals=[0, 1],
|
175 |
ticktext=["DISCONNECTED", "LIVE"],
|
176 |
-
range=[-0.
|
177 |
-
zeroline=False,
|
178 |
),
|
179 |
xaxis_title="Time",
|
180 |
-
yaxis_title="Status",
|
181 |
-
#
|
182 |
-
|
183 |
-
|
184 |
-
datetime.now() - timedelta(hours=3, minutes=5), # Add a little buffer
|
185 |
-
datetime.now() + timedelta(minutes=5) # Add a little buffer
|
186 |
],
|
187 |
-
showlegend=False,
|
188 |
-
margin=dict(l=
|
189 |
)
|
190 |
|
191 |
-
container.plotly_chart(fig, use_container_width=True)
|
192 |
-
|
193 |
|
194 |
def main():
|
195 |
st_autorefresh(interval=10_000, key="health_watch")
|
|
|
139 |
|
140 |
def plot_status(df_service, title, container):
|
141 |
"""
|
142 |
+
Plots the health status of a single service over time.
|
143 |
+
Uses a step chart if there are 2+ points, otherwise just a marker for single points.
|
144 |
"""
|
145 |
if df_service.empty:
|
146 |
container.info(f"No data available for {title}.")
|
147 |
return
|
148 |
|
149 |
+
# Ensure data is sorted by Time for correct line/step plotting and reset index
|
150 |
+
df_service = df_service.sort_values('Time').reset_index(drop=True)
|
151 |
+
|
152 |
+
# Determine line_shape based on number of data points to avoid artifacts with single points
|
153 |
+
# 'linear' for a single point with markers=True results in just the marker being shown.
|
154 |
+
effective_line_shape = 'hv' if len(df_service) >= 2 else 'linear'
|
155 |
|
156 |
fig = px.line(
|
157 |
df_service,
|
158 |
x="Time",
|
159 |
y="StatusNumeric",
|
160 |
+
color="ReadableStatus", # Color lines/markers by "LIVE" or "DISCONNECTED"
|
161 |
title=title,
|
162 |
+
color_discrete_map={ # Ensure "LIVE" is green and "DISCONNECTED" is red
|
163 |
"LIVE": "green",
|
164 |
"DISCONNECTED": "red"
|
165 |
},
|
166 |
+
labels={"StatusNumeric": "Status", "ReadableStatus": "Legend"}, # Adjust legend title if shown
|
167 |
+
line_shape=effective_line_shape,
|
168 |
+
markers=True # Always show markers at data points
|
169 |
)
|
170 |
|
171 |
+
# Adjust marker and line properties based on the number of points
|
172 |
+
if len(df_service) == 1:
|
173 |
+
fig.update_traces(
|
174 |
+
marker_size=12,
|
175 |
+
line_width=0 # Ensure no line is drawn for a single point, only marker
|
176 |
+
)
|
177 |
+
else: # len(df_service) > 1
|
178 |
+
fig.update_traces(
|
179 |
+
marker_size=8,
|
180 |
+
line_width=3 # Width for the step line
|
181 |
+
)
|
182 |
|
183 |
fig.update_layout(
|
184 |
yaxis=dict(
|
185 |
tickmode="array",
|
186 |
tickvals=[0, 1],
|
187 |
ticktext=["DISCONNECTED", "LIVE"],
|
188 |
+
range=[-0.2, 1.2], # Add some padding to y-axis
|
189 |
+
zeroline=False, # Zeroline often not needed with these custom ticks
|
190 |
),
|
191 |
xaxis_title="Time",
|
192 |
+
yaxis_title="Status",
|
193 |
+
xaxis_range=[ # Ensure consistent 3-hour window across all charts
|
194 |
+
datetime.now() - timedelta(hours=3, minutes=5), # 5 min buffer past
|
195 |
+
datetime.now() + timedelta(minutes=5) # 5 min buffer future
|
|
|
|
|
196 |
],
|
197 |
+
showlegend=False, # Legend is redundant given the chart titles and y-axis
|
198 |
+
margin=dict(l=40, r=20, t=60, b=40) # Adjust margins for titles/labels
|
199 |
)
|
200 |
|
|
|
|
|
201 |
|
202 |
def main():
|
203 |
st_autorefresh(interval=10_000, key="health_watch")
|