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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
import pickle
|
| 5 |
+
from statsmodels.tsa.arima.model import ARIMA
|
| 6 |
+
import os
|
| 7 |
+
from datetime import datetime, timedelta
|
| 8 |
+
|
| 9 |
+
# Page configuration with custom theme
|
| 10 |
+
st.set_page_config(
|
| 11 |
+
page_title="ERROR Log Analytics Dashboard",
|
| 12 |
+
layout="wide",
|
| 13 |
+
initial_sidebar_state="expanded"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# Custom CSS to enhance the UI
|
| 17 |
+
st.markdown("""
|
| 18 |
+
<style>
|
| 19 |
+
.main-header {
|
| 20 |
+
font-size: 2.5rem;
|
| 21 |
+
font-weight: 700;
|
| 22 |
+
color: #1E3A8A;
|
| 23 |
+
margin-bottom: 1rem;
|
| 24 |
+
}
|
| 25 |
+
.sub-header {
|
| 26 |
+
font-size: 1.5rem;
|
| 27 |
+
font-weight: 600;
|
| 28 |
+
color: #2563EB;
|
| 29 |
+
margin-top: 2rem;
|
| 30 |
+
}
|
| 31 |
+
.card {
|
| 32 |
+
background-color: #F8FAFC;
|
| 33 |
+
border-radius: 0.5rem;
|
| 34 |
+
padding: 1.5rem;
|
| 35 |
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
| 36 |
+
margin-bottom: 1rem;
|
| 37 |
+
}
|
| 38 |
+
.success-msg {
|
| 39 |
+
background-color: #DCFCE7;
|
| 40 |
+
color: #166534;
|
| 41 |
+
padding: 0.75rem;
|
| 42 |
+
border-radius: 0.375rem;
|
| 43 |
+
border-left: 4px solid #16A34A;
|
| 44 |
+
margin: 1rem 0;
|
| 45 |
+
}
|
| 46 |
+
.stButton>button {
|
| 47 |
+
background-color: #2563EB;
|
| 48 |
+
color: white;
|
| 49 |
+
border: none;
|
| 50 |
+
border-radius: 0.375rem;
|
| 51 |
+
padding: 0.5rem 1rem;
|
| 52 |
+
}
|
| 53 |
+
.metrics-container {
|
| 54 |
+
display: flex;
|
| 55 |
+
justify-content: space-between;
|
| 56 |
+
}
|
| 57 |
+
.metric-card {
|
| 58 |
+
background-color: #F0F9FF;
|
| 59 |
+
border-radius: 0.5rem;
|
| 60 |
+
padding: 1rem;
|
| 61 |
+
text-align: center;
|
| 62 |
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
| 63 |
+
width: 32%;
|
| 64 |
+
}
|
| 65 |
+
</style>
|
| 66 |
+
""", unsafe_allow_html=True)
|
| 67 |
+
|
| 68 |
+
# Sidebar for controls and information
|
| 69 |
+
with st.sidebar:
|
| 70 |
+
st.image("https://www.svgrepo.com/show/374111/log.svg", width=100)
|
| 71 |
+
st.markdown("## ERROR Log Analytics")
|
| 72 |
+
st.markdown("---")
|
| 73 |
+
st.markdown("### Model Configuration")
|
| 74 |
+
|
| 75 |
+
# File selection (keeping default path but making it look configurable)
|
| 76 |
+
file_path = st.text_input("Log file path", value="augmented_logs.csv")
|
| 77 |
+
|
| 78 |
+
# ARIMA parameters
|
| 79 |
+
st.markdown("### ARIMA Parameters")
|
| 80 |
+
p = st.slider("Auto-regression (p)", min_value=0, max_value=5, value=1)
|
| 81 |
+
d = st.slider("Differencing (d)", min_value=0, max_value=2, value=1)
|
| 82 |
+
q = st.slider("Moving Average (q)", min_value=0, max_value=5, value=1)
|
| 83 |
+
|
| 84 |
+
# Forecast range
|
| 85 |
+
st.markdown("### Forecast Settings")
|
| 86 |
+
forecast_days = st.slider("Forecast Horizon (days)", min_value=1, max_value=30, value=7)
|
| 87 |
+
|
| 88 |
+
st.markdown("---")
|
| 89 |
+
st.markdown("*This dashboard analyzes ERROR logs and forecasts future error rates using ARIMA modeling.*")
|
| 90 |
+
|
| 91 |
+
# Main content
|
| 92 |
+
st.markdown('<div class="main-header">📊 ERROR Log Analysis & Forecasting</div>', unsafe_allow_html=True)
|
| 93 |
+
|
| 94 |
+
if not os.path.exists(file_path):
|
| 95 |
+
st.error(f"❌ File not found: {file_path}")
|
| 96 |
+
else:
|
| 97 |
+
try:
|
| 98 |
+
# Main app container
|
| 99 |
+
with st.container():
|
| 100 |
+
# Load and prep data
|
| 101 |
+
df = pd.read_csv(file_path)
|
| 102 |
+
df['timestamp'] = pd.to_datetime(df['timestamp'])
|
| 103 |
+
df['date'] = df['timestamp'].dt.date
|
| 104 |
+
|
| 105 |
+
# Group by date and count ERRORs
|
| 106 |
+
daily_errors = df[df['log_level'] == 'ERROR'].groupby('date').size()
|
| 107 |
+
daily_errors_ts = daily_errors.asfreq('D').fillna(0)
|
| 108 |
+
|
| 109 |
+
# Display key metrics
|
| 110 |
+
st.markdown('<div class="sub-header">Key Metrics</div>', unsafe_allow_html=True)
|
| 111 |
+
|
| 112 |
+
col1, col2, col3 = st.columns(3)
|
| 113 |
+
with col1:
|
| 114 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 115 |
+
st.metric("Total ERRORs", f"{int(daily_errors_ts.sum())}")
|
| 116 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 117 |
+
|
| 118 |
+
with col2:
|
| 119 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 120 |
+
st.metric("Average Daily ERRORs", f"{daily_errors_ts.mean():.2f}")
|
| 121 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 122 |
+
|
| 123 |
+
with col3:
|
| 124 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 125 |
+
if len(daily_errors_ts) >= 7:
|
| 126 |
+
last_week = daily_errors_ts[-7:].mean()
|
| 127 |
+
previous_week = daily_errors_ts[-14:-7].mean()
|
| 128 |
+
delta = ((last_week - previous_week) / previous_week * 100) if previous_week > 0 else 0
|
| 129 |
+
st.metric("7-Day Trend", f"{last_week:.2f}", f"{delta:.1f}%")
|
| 130 |
+
else:
|
| 131 |
+
st.metric("7-Day Trend", "Insufficient data")
|
| 132 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 133 |
+
|
| 134 |
+
# Historical data visualization
|
| 135 |
+
st.markdown('<div class="sub-header">Historical ERROR Trends</div>', unsafe_allow_html=True)
|
| 136 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 137 |
+
|
| 138 |
+
chart_tab1, chart_tab2 = st.tabs(["Line Chart", "Bar Chart"])
|
| 139 |
+
|
| 140 |
+
with chart_tab1:
|
| 141 |
+
st.line_chart(daily_errors_ts)
|
| 142 |
+
|
| 143 |
+
with chart_tab2:
|
| 144 |
+
st.bar_chart(daily_errors_ts)
|
| 145 |
+
|
| 146 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 147 |
+
|
| 148 |
+
# Model training
|
| 149 |
+
st.markdown('<div class="sub-header">ARIMA Model Training</div>', unsafe_allow_html=True)
|
| 150 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 151 |
+
|
| 152 |
+
try:
|
| 153 |
+
with st.spinner("Training ARIMA model..."):
|
| 154 |
+
# Use the parameters from sidebar
|
| 155 |
+
model = ARIMA(daily_errors_ts, order=(p, d, q))
|
| 156 |
+
model_fit = model.fit()
|
| 157 |
+
|
| 158 |
+
# Save model
|
| 159 |
+
with open("arima_model.pkl", "wb") as f:
|
| 160 |
+
pickle.dump(model_fit, f)
|
| 161 |
+
|
| 162 |
+
st.markdown('<div class="success-msg">✅ ARIMA model trained and saved successfully!</div>',
|
| 163 |
+
unsafe_allow_html=True)
|
| 164 |
+
|
| 165 |
+
# Display model summary in expander
|
| 166 |
+
with st.expander("View Model Details"):
|
| 167 |
+
st.code(str(model_fit.summary()))
|
| 168 |
+
|
| 169 |
+
except Exception as arima_error:
|
| 170 |
+
st.error(f"⚠️ ARIMA training failed: {arima_error}")
|
| 171 |
+
|
| 172 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 173 |
+
|
| 174 |
+
# Forecast visualization
|
| 175 |
+
st.markdown('<div class="sub-header">ERROR Forecast Analysis</div>', unsafe_allow_html=True)
|
| 176 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 177 |
+
|
| 178 |
+
forecast = model_fit.forecast(steps=forecast_days)
|
| 179 |
+
forecast_dates = pd.date_range(start=daily_errors_ts.index[-1] + pd.Timedelta(days=1),
|
| 180 |
+
periods=forecast_days)
|
| 181 |
+
|
| 182 |
+
# Create forecast dataframe for additional analysis
|
| 183 |
+
forecast_df = pd.DataFrame({
|
| 184 |
+
'date': forecast_dates,
|
| 185 |
+
'forecast': forecast.values,
|
| 186 |
+
# Use a fixed standard deviation estimate instead of se_mean
|
| 187 |
+
'lower_ci': forecast.values - 2 * forecast.values.std() if len(forecast) > 1 else forecast.values,
|
| 188 |
+
'upper_ci': forecast.values + 2 * forecast.values.std() if len(forecast) > 1 else forecast.values * 1.2
|
| 189 |
+
})
|
| 190 |
+
|
| 191 |
+
# Round negative values to 0 for logical consistency
|
| 192 |
+
forecast_df['lower_ci'] = forecast_df['lower_ci'].clip(lower=0)
|
| 193 |
+
forecast_df['forecast'] = forecast_df['forecast'].clip(lower=0)
|
| 194 |
+
|
| 195 |
+
# Enhanced plotly visualization
|
| 196 |
+
fig = go.Figure()
|
| 197 |
+
|
| 198 |
+
# Historical data
|
| 199 |
+
fig.add_trace(go.Scatter(
|
| 200 |
+
x=daily_errors_ts.index,
|
| 201 |
+
y=daily_errors_ts.values,
|
| 202 |
+
mode='lines+markers',
|
| 203 |
+
name='Historical ERRORs',
|
| 204 |
+
line=dict(color='#3B82F6', width=2)
|
| 205 |
+
))
|
| 206 |
+
|
| 207 |
+
# Forecast
|
| 208 |
+
fig.add_trace(go.Scatter(
|
| 209 |
+
x=forecast_df['date'],
|
| 210 |
+
y=forecast_df['forecast'],
|
| 211 |
+
mode='lines+markers',
|
| 212 |
+
name='Forecasted ERRORs',
|
| 213 |
+
line=dict(color='#EF4444', width=2, dash='dash')
|
| 214 |
+
))
|
| 215 |
+
|
| 216 |
+
# Confidence interval
|
| 217 |
+
fig.add_trace(go.Scatter(
|
| 218 |
+
x=forecast_df['date'].tolist() + forecast_df['date'].tolist()[::-1],
|
| 219 |
+
y=forecast_df['upper_ci'].tolist() + forecast_df['lower_ci'].tolist()[::-1],
|
| 220 |
+
fill='toself',
|
| 221 |
+
fillcolor='rgba(239, 68, 68, 0.1)',
|
| 222 |
+
line=dict(color='rgba(0,0,0,0)'),
|
| 223 |
+
hoverinfo='skip',
|
| 224 |
+
showlegend=False
|
| 225 |
+
))
|
| 226 |
+
|
| 227 |
+
fig.update_layout(
|
| 228 |
+
title='ERROR Log Forecast with Confidence Intervals',
|
| 229 |
+
xaxis_title='Date',
|
| 230 |
+
yaxis_title='ERROR Count',
|
| 231 |
+
hovermode='x unified',
|
| 232 |
+
legend=dict(x=0.01, y=0.99),
|
| 233 |
+
template='plotly_white',
|
| 234 |
+
height=500
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 238 |
+
|
| 239 |
+
# Forecast data table
|
| 240 |
+
with st.expander("View Forecast Data"):
|
| 241 |
+
forecast_df['date'] = forecast_df['date'].dt.date
|
| 242 |
+
forecast_df['forecast'] = forecast_df['forecast'].round(2)
|
| 243 |
+
forecast_df['lower_ci'] = forecast_df['lower_ci'].round(2)
|
| 244 |
+
forecast_df['upper_ci'] = forecast_df['upper_ci'].round(2)
|
| 245 |
+
st.dataframe(forecast_df)
|
| 246 |
+
|
| 247 |
+
# Download forecast as CSV
|
| 248 |
+
csv = forecast_df.to_csv(index=False)
|
| 249 |
+
st.download_button(
|
| 250 |
+
label="Download Forecast CSV",
|
| 251 |
+
data=csv,
|
| 252 |
+
file_name=f"error_forecast_{datetime.now().strftime('%Y%m%d')}.csv",
|
| 253 |
+
mime="text/csv"
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 257 |
+
|
| 258 |
+
except Exception as e:
|
| 259 |
+
st.error(f"❌ Error processing data: {e}")
|
arima_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1269c97cffe4793884e24c1cdffc658054fa350abde48f72515af9c8ed261d6c
|
| 3 |
+
size 66470
|
augmented_logs.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|