-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
412 lines (350 loc) · 13.3 KB
/
start.ps1
File metadata and controls
412 lines (350 loc) · 13.3 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# Simple Menu - Unified Startup Script
# Handles all deployment options in one script
param(
[Parameter(Mandatory=$false)]
[ValidateSet("basic", "prometheus", "elk", "unified", "menu")]
[string]$Mode = "menu"
)
# Colors and formatting
$Colors = @{
Header = "Cyan"
Success = "Green"
Warning = "Yellow"
Error = "Red"
Info = "Blue"
Accent = "Magenta"
}
function Write-Header {
param([string]$Text)
Write-Host "=" * 60 -ForegroundColor $Colors.Header
Write-Host " $Text" -ForegroundColor $Colors.Header
Write-Host "=" * 60 -ForegroundColor $Colors.Header
Write-Host ""
}
function Write-Success {
param([string]$Text)
Write-Host "✓ $Text" -ForegroundColor $Colors.Success
}
function Write-Warning {
param([string]$Text)
Write-Host "⚠️ $Text" -ForegroundColor $Colors.Warning
}
function Write-Error {
param([string]$Text)
Write-Host "✗ $Text" -ForegroundColor $Colors.Error
}
function Write-Info {
param([string]$Text)
Write-Host "ℹ️ $Text" -ForegroundColor $Colors.Info
}
function Write-Accent {
param([string]$Text)
Write-Host "$Text" -ForegroundColor $Colors.Accent
}
function Test-Docker {
try {
$dockerInfo = docker info 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Success "Docker is running"
return $true
}
} catch {
# Ignore errors
}
Write-Error "Docker is not running or not installed"
Write-Info "Please start Docker Desktop or install it from: https://www.docker.com/products/docker-desktop"
return $false
}
function Get-SystemInfo {
$memory = [math]::Round((Get-WmiObject -Class Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 1)
$cpuCores = (Get-WmiObject -Class Win32_Processor).NumberOfCores
$os = (Get-WmiObject -Class Win32_OperatingSystem).Caption
return @{
Memory = $memory
CpuCores = $cpuCores
OS = $os
}
}
function Show-SystemInfo {
$sysInfo = Get-SystemInfo
Write-Info "System Information:"
Write-Host " • OS: $($sysInfo.OS)" -ForegroundColor White
Write-Host " • Memory: $($sysInfo.Memory) GB" -ForegroundColor White
Write-Host " • CPU Cores: $($sysInfo.CpuCores)" -ForegroundColor White
Write-Host ""
}
function Show-Menu {
Write-Header "Simple Menu - Unified Startup"
Show-SystemInfo
Write-Accent "Available Options:"
Write-Host ""
Write-Host "1. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "Basic Setup" -ForegroundColor White
Write-Host " └─ Just the Simple Menu application" -ForegroundColor Gray
Write-Host " └─ Resource usage: ~200MB RAM" -ForegroundColor Gray
Write-Host ""
Write-Host "2. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "Prometheus + Grafana Monitoring (Recommended)" -ForegroundColor White
Write-Host " └─ System metrics, performance monitoring, dashboards" -ForegroundColor Gray
Write-Host " └─ Resource usage: ~512MB RAM" -ForegroundColor Gray
Write-Host ""
Write-Host "3. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "ELK Stack Monitoring" -ForegroundColor White
Write-Host " └─ Log analysis, debugging, full-text search" -ForegroundColor Gray
Write-Host " └─ Resource usage: ~2GB RAM" -ForegroundColor Gray
Write-Host ""
Write-Host "4. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "Unified Monitoring (Recommended)" -ForegroundColor White
Write-Host " └─ Both Prometheus+Grafana AND ELK Stack" -ForegroundColor Gray
Write-Host " └─ Resource usage: ~3GB RAM" -ForegroundColor Gray
Write-Host ""
Write-Host "5. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "Stop All Services" -ForegroundColor White
Write-Host " └─ Stop and clean up all running containers" -ForegroundColor Gray
Write-Host ""
Write-Host "6. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "View Service Status" -ForegroundColor White
Write-Host " └─ Check running containers and their status" -ForegroundColor Gray
Write-Host ""
Write-Host "7. " -NoNewline -ForegroundColor $Colors.Accent
Write-Host "Exit" -ForegroundColor White
Write-Host ""
}
function Get-UserChoice {
do {
$choice = Read-Host "Select an option (1-7)"
if ($choice -match '^[1-7]$') {
return [int]$choice
}
Write-Warning "Please enter a number between 1 and 7"
} while ($true)
}
function Start-BasicSetup {
Write-Header "Starting Basic Simple Menu"
Write-Info "Starting Simple Menu application..."
docker-compose up -d
if ($LASTEXITCODE -eq 0) {
Start-Sleep -Seconds 5
Write-Success "Simple Menu started successfully!"
Write-Host ""
Write-Accent "📱 Access Point:"
Write-Host " • Simple Menu: http://localhost:3000" -ForegroundColor White
Write-Host ""
} else {
Write-Error "Failed to start Simple Menu"
}
}
function Start-PrometheusSetup {
Write-Header "Starting Simple Menu with Prometheus + Grafana"
$sysInfo = Get-SystemInfo
if ($sysInfo.Memory -lt 1) {
Write-Warning "Low memory detected ($($sysInfo.Memory)GB). This might affect performance."
$continue = Read-Host "Continue anyway? (y/N)"
if ($continue -ne "y" -and $continue -ne "Y") {
return
}
}
Write-Info "Starting Simple Menu application..."
docker-compose up -d
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to start Simple Menu application"
return
}
Write-Info "Waiting for main application to start..."
Start-Sleep -Seconds 10
Write-Info "Starting Prometheus + Grafana monitoring..."
docker-compose -f docker\docker-compose.monitoring-simple.yml up -d
if ($LASTEXITCODE -eq 0) {
Write-Info "Waiting for monitoring services to be ready..."
Start-Sleep -Seconds 30
Write-Success "Simple Menu with Prometheus + Grafana started successfully!"
Write-Host ""
Write-Accent "📊 Access Points:"
Write-Host " • Simple Menu: http://localhost:3000" -ForegroundColor White
Write-Host " • Grafana: http://localhost:3001 (admin/admin123)" -ForegroundColor White
Write-Host " • Prometheus: http://localhost:9090" -ForegroundColor White
Write-Host " • Node Exporter: http://localhost:9100" -ForegroundColor White
Write-Host " • cAdvisor: http://localhost:8080" -ForegroundColor White
Write-Host ""
} else {
Write-Error "Failed to start monitoring services"
}
}
function Start-ELKSetup {
Write-Header "Starting Simple Menu with ELK Stack"
$sysInfo = Get-SystemInfo
if ($sysInfo.Memory -lt 4) {
Write-Warning "ELK Stack requires at least 4GB RAM. You have $($sysInfo.Memory)GB"
$continue = Read-Host "Continue anyway? (y/N)"
if ($continue -ne "y" -and $continue -ne "Y") {
Write-Info "Consider using Prometheus + Grafana monitoring instead (option 2)"
return
}
}
Write-Info "Starting Simple Menu application..."
docker-compose up -d
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to start Simple Menu application"
return
}
Write-Info "Waiting for main application to start..."
Start-Sleep -Seconds 10
Write-Info "Starting ELK Stack monitoring (this may take a few minutes)..."
docker-compose -f docker\docker-compose.elk-simple.yml up -d
if ($LASTEXITCODE -eq 0) {
Write-Info "Waiting for ELK services to be ready (this can take 2-3 minutes)..."
Start-Sleep -Seconds 90
Write-Success "Simple Menu with ELK Stack started successfully!"
Write-Host ""
Write-Accent "📊 Access Points:"
Write-Host " • Simple Menu: http://localhost:3000" -ForegroundColor White
Write-Host " • Kibana: http://localhost:5601" -ForegroundColor White
Write-Host " • Elasticsearch: http://localhost:9200" -ForegroundColor White
Write-Host ""
Write-Warning "Note: ELK Stack uses significant resources. Monitor system performance."
} else {
Write-Error "Failed to start ELK services"
}
}
function Start-UnifiedSetup {
Write-Header "Starting Simple Menu with Unified Monitoring"
$sysInfo = Get-SystemInfo
if ($sysInfo.Memory -lt 6) {
Write-Warning "Unified monitoring stack requires at least 6GB RAM. You have $($sysInfo.Memory)GB"
if ($sysInfo.Memory -lt 4) {
Write-Error "System has insufficient memory. Minimum 4GB required."
return
}
$continue = Read-Host "Continue with reduced performance? (y/N)"
if ($continue -ne "y" -and $continue -ne "Y") {
Write-Info "Consider using Prometheus + Grafana monitoring instead (option 2)"
return
}
}
Write-Info "Starting unified monitoring stack (this will take several minutes)..."
Write-Info "This includes: Simple Menu + Prometheus + Grafana + ELK Stack"
docker-compose -f docker\docker-compose.unified.yml up -d
if ($LASTEXITCODE -eq 0) {
Write-Info "Waiting for all services to be ready (this can take 3-5 minutes)..."
Start-Sleep -Seconds 180
Write-Success "Simple Menu with Unified Monitoring started successfully!"
Write-Host ""
Write-Accent "🚀 Application:"
Write-Host " • Simple Menu: http://localhost:4200" -ForegroundColor White
Write-Host " • Backend API: http://localhost:3000" -ForegroundColor White
Write-Host ""
Write-Accent "📊 Metrics & Visualization:"
Write-Host " • Grafana: http://localhost:3001 (admin/admin123)" -ForegroundColor White
Write-Host " • Prometheus: http://localhost:9090" -ForegroundColor White
Write-Host " • Node Exporter: http://localhost:9100" -ForegroundColor White
Write-Host " • cAdvisor: http://localhost:8080" -ForegroundColor White
Write-Host ""
Write-Accent "🔍 Logs & Search:"
Write-Host " • Kibana: http://localhost:5601" -ForegroundColor White
Write-Host " • Elasticsearch: http://localhost:9200" -ForegroundColor White
Write-Host " • Logstash: http://localhost:9600" -ForegroundColor White
Write-Host ""
Write-Warning "Note: Unified stack uses significant resources (~3GB RAM). Monitor system performance."
} else {
Write-Error "Failed to start unified monitoring services"
}
}
function Stop-AllServices {
Write-Header "Stopping All Services"
Write-Info "Stopping unified monitoring services..."
docker-compose -f docker\docker-compose.unified.yml down 2>$null
Write-Info "Stopping individual monitoring services..."
docker-compose -f docker\docker-compose.monitoring-simple.yml down 2>$null
docker-compose -f docker\docker-compose.elk-simple.yml down 2>$null
docker-compose -f docker\docker-compose.monitoring.yml down 2>$null
docker-compose -f docker\docker-compose.elk.yml down 2>$null
Write-Info "Stopping Simple Menu application..."
docker-compose down
Write-Info "Cleaning up unused containers and networks..."
docker system prune -f >$null 2>&1
Write-Success "All services stopped successfully!"
}
function Show-ServiceStatus {
Write-Header "Service Status"
Write-Info "Running containers:"
$containers = docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>$null
if ($containers) {
Write-Host $containers -ForegroundColor White
} else {
Write-Warning "No containers are currently running"
}
Write-Host ""
Write-Info "Docker system information:"
docker system df 2>$null | ForEach-Object {
if ($_ -match "^(TYPE|Images|Containers|Local Volumes)") {
Write-Host $_ -ForegroundColor White
}
}
}
function Wait-ForKeyPress {
Write-Host ""
Write-Host "Press any key to continue..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Write-Host ""
}
# Main execution
if (-not (Test-Docker)) {
exit 1
}
# Handle command line parameters
switch ($Mode) {
"basic" {
Start-BasicSetup
exit 0
}
"prometheus" {
Start-PrometheusSetup
exit 0
}
"elk" {
Start-ELKSetup
exit 0
}
"unified" {
Start-UnifiedSetup
exit 0
}
"menu" {
# Continue to interactive menu
}
}
# Interactive menu
do {
Show-Menu
$choice = Get-UserChoice
switch ($choice) {
1 {
Start-BasicSetup
Wait-ForKeyPress
}
2 {
Start-PrometheusSetup
Wait-ForKeyPress
}
3 {
Start-ELKSetup
Wait-ForKeyPress
}
4 {
Start-UnifiedSetup
Wait-ForKeyPress
}
5 {
Stop-AllServices
Wait-ForKeyPress
}
6 {
Show-ServiceStatus
Wait-ForKeyPress
}
7 {
Write-Host "Goodbye! 👋" -ForegroundColor $Colors.Success
exit 0
}
}
} while ($true)