-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromPlot.jl
More file actions
172 lines (154 loc) · 4.37 KB
/
Copy pathPromPlot.jl
File metadata and controls
172 lines (154 loc) · 4.37 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
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
using ArgParse
include("prometheus.jl")
if abspath(PROGRAM_FILE) != @__FILE__
return
end
include("plot_gui.jl")
include("plot_tui.jl")
include("grafana_dashboard.jl")
function main()
s = ArgParseSettings(exit_after_help=true, autofix_names=true)
add_arg_table(s,
"--promql",
Dict(
:help => "Prometheus PromQL Query (required)",
:default => nothing
),
"--gui",
Dict(
:help => "Plot in GUI - Required for 3D Mode",
:arg_type => Bool,
:default => false
),
"--tui",
Dict(
:help => "Plot in CLI/TUI",
:arg_type => Bool,
:default => true
),
"--limit",
Dict(
:help => "Maximum number of series to plot",
:arg_type => Int,
:default => 25
),
"--url",
Dict(
:help => "Prometheus URL",
:arg_type => String,
:default => "http://localhost:9090"
),
"--is3d",
Dict(
:help => "Start in 3D Plotting Mode",
:default => false
),
"--start",
Dict(
:help => "Query Start Date",
:arg_type => String,
:default => nothing
),
"--end",
Dict(
:help => "Query End Date",
:arg_type => String,
:default => nothing
),
"--step",
Dict(
:help => "Query Resolution",
:arg_type => String,
:default => "30s"
),
"--realtime",
Dict(
:help => "Enable realtime updates",
:arg_type => Bool,
:default => true
),
"--realtime-update",
Dict(
:help => "Realtime update interval",
:arg_type => String,
:default => "5s"
),
"--realtime-range",
Dict(
:help => "Realtime update range",
:arg_type => String,
:default => "1h"
),
"--dashboard",
Dict(
:help => "Grafana Dashboard JSON File Path",
:arg_type => String,
:default => nothing
)
)
args = parse_args(s; as_symbols=true)
if isnothing(args[:dashboard]) && (args[:promql] === nothing || isempty(args[:promql]))
ArgParse.show_help(s)
return
end
# TODO: Add support for multiple clients to query multiple clusters in one plot
p = PrometheusQueryClient(url=args[:url])
if !test_prometheus_connection(p)
println("Prometheus connection to $(args[:url]) failed, exiting...")
return
end
is_gui_plot = args[:gui]
is_tui_plot = args[:tui]
fig = nothing
if !isnothing(args[:dashboard])
fig = dashboard(
p,
args[:dashboard];
step=args[:step],
realtime=args[:realtime],
realtime_update=args[:realtime_update],
realtime_range=args[:realtime_range]
)
end
if isnothing(fig) && is_tui_plot && !is_gui_plot
init_terminal(
p;
query=args[:promql],
startdate=args[:start],
enddate=args[:end],
update_resolution=args[:step],
realtime=args[:realtime],
realtime_update=args[:realtime_update],
realtime_range=args[:realtime_range],
series_limit=args[:limit]
)
exit()
end
if is_gui_plot && isnothing(fig)
fig = init_window(
p;
query=args[:promql],
is3d=args[:is3d],
startdate=args[:start],
enddate=args[:end],
step=args[:step],
realtime=args[:realtime],
realtime_update=args[:realtime_update],
realtime_range=args[:realtime_range]
)
end
if !isnothing(fig)
display(fig)
close_window = Channel{Bool}(1)
on(events(fig).window_open) do window_open
if !window_open
println("Exiting plot...")
put!(close_window, true)
end
end
if take!(close_window)
exit()
end
end
end
main()