-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitoring.py
More file actions
107 lines (91 loc) · 2.65 KB
/
monitoring.py
File metadata and controls
107 lines (91 loc) · 2.65 KB
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
import dash
from dash import html, dcc
import plotly.graph_objects as go
import pandas as pd
from dash.dependencies import Output, Input
from predictions import predict
class Predictions:
def __init__(self):
self.has_predictions = False
self.predictions = None
def predict(self, data):
self.has_predictions = True
self.predictions = predict(data)
def get_predictions(self):
if not self.has_predictions:
return None
return self.predictions
p = Predictions()
external_stylesheets = [
{
"href": "https://fonts.googleapis.com/css2?"
"family=Lato:wght@400;700&display=swap",
"rel": "stylesheet",
},
]
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.title = "AIOPs - Monitoring"
app.layout = html.Div(
[
html.Div(
[
html.P(children="〽️", className="header-emoji"),
html.H1(children="AIOPs", className="header-title"),
html.P(
children="My Monitoring Application.",
className="header-description",
),
],
className="header",
),
html.Div(
[
dcc.Interval(id="interval", interval=1 * 1000, n_intervals=0),
dcc.Graph(id="graph", style={"height": "700px"}),
],
className="graph",
),
],
)
@app.callback([Output("graph", "figure")], [Input("interval", "n_intervals")])
def update_graph(n):
df = pd.read_csv("data/agent.log", sep=" ", names=["ds", "y"])
df["ds"] = pd.to_datetime(df["ds"], unit="s")
fig = go.Figure()
if n % 60 == 10:
p.predict(df)
if p.has_predictions:
preds = p.get_predictions()
if preds is not None:
fig.add_trace(
go.Scatter(
x=preds["ds"],
y=preds["yhat_lower"],
fill=None,
mode="lines",
line={"width": 0},
)
)
fig.add_trace(
go.Scatter(
x=preds["ds"],
y=preds["yhat_upper"],
fill="tonexty",
mode="lines",
line={"width": 0},
)
)
fig.add_trace(
go.Scatter(
x=df["ds"],
y=df["y"],
fill=None,
mode="lines",
name="data",
line_color="indigo",
)
)
fig.update_traces(showlegend=False)
return [fig]
if __name__ == "__main__":
app.run_server(debug=True)