-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·200 lines (166 loc) · 6.4 KB
/
setup.sh
File metadata and controls
executable file
·200 lines (166 loc) · 6.4 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
#!/bin/bash
# pgSentinel Setup Script
# =======================
# Automated setup for pgSentinel monitoring system
set -e
# Colors
BLUE='\033[0;34m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${BLUE}"
cat << "EOF"
╔═══════════════════════════════════════════════════════════════════════════╗
║ pgSentinel Setup Script ║
║ Professional pgbalancer Monitoring ║
╚═══════════════════════════════════════════════════════════════════════════╝
EOF
echo -e "${NC}"
# Check prerequisites
echo -e "${BLUE}Checking prerequisites...${NC}"
# Check Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}✗ Docker not found. Please install Docker first.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Docker found${NC}"
# Check Docker Compose
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}✗ Docker Compose not found. Please install Docker Compose first.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Docker Compose found${NC}"
# Check Node.js (for local development)
if command -v node &> /dev/null; then
echo -e "${GREEN}✓ Node.js found ($(node --version))${NC}"
else
echo -e "${YELLOW}⚠ Node.js not found (optional for local development)${NC}"
fi
# Check Python (for local development)
if command -v python3 &> /dev/null; then
echo -e "${GREEN}✓ Python found ($(python3 --version))${NC}"
else
echo -e "${YELLOW}⚠ Python not found (optional for local development)${NC}"
fi
echo ""
# Create environment file
echo -e "${BLUE}Setting up environment...${NC}"
if [ ! -f .env ]; then
if [ -f env.template ]; then
cp env.template .env
echo -e "${GREEN}✓ Created .env from template${NC}"
echo -e "${YELLOW}⚠ Please edit .env and configure your settings${NC}"
else
echo -e "${YELLOW}⚠ No env.template found, skipping .env creation${NC}"
fi
else
echo -e "${GREEN}✓ .env file already exists${NC}"
fi
# Create directories
echo -e "${BLUE}Creating directories...${NC}"
mkdir -p monitoring/prometheus/rules
mkdir -p monitoring/grafana/dashboards
mkdir -p monitoring/grafana/datasources
mkdir -p monitoring/alertmanager
mkdir -p backend/logs
mkdir -p frontend/.next
echo -e "${GREEN}✓ Directories created${NC}"
echo ""
# Option selection
echo -e "${BLUE}Choose setup option:${NC}"
echo " 1) Docker deployment (recommended)"
echo " 2) Local development setup"
echo " 3) Both"
read -p "Enter choice (1-3): " choice
case $choice in
1)
echo -e "${BLUE}Setting up Docker deployment...${NC}"
# Build images
echo -e "${BLUE}Building Docker images...${NC}"
docker-compose build
# Start services
echo -e "${BLUE}Starting services...${NC}"
docker-compose up -d
# Wait for services
echo -e "${BLUE}Waiting for services to be ready...${NC}"
sleep 10
# Check health
echo -e "${BLUE}Checking service health...${NC}"
docker-compose ps
echo ""
echo -e "${GREEN}✓ Docker deployment complete!${NC}"
echo ""
echo -e "${BLUE}Access points:${NC}"
echo " Dashboard: http://localhost:3000"
echo " API Docs: http://localhost:8000/docs"
echo " Prometheus: http://localhost:9090"
echo " Grafana: http://localhost:3001 (admin/admin)"
;;
2)
echo -e "${BLUE}Setting up local development...${NC}"
# Backend setup
echo -e "${BLUE}Setting up backend...${NC}"
cd backend
if [ ! -d "venv" ]; then
python3 -m venv venv
echo -e "${GREEN}✓ Created Python virtual environment${NC}"
fi
source venv/bin/activate
pip install -r requirements.txt
echo -e "${GREEN}✓ Backend dependencies installed${NC}"
cd ..
# Frontend setup
echo -e "${BLUE}Setting up frontend...${NC}"
cd frontend
if [ ! -d "node_modules" ]; then
npm install
echo -e "${GREEN}✓ Frontend dependencies installed${NC}"
else
echo -e "${GREEN}✓ Frontend dependencies already installed${NC}"
fi
cd ..
echo ""
echo -e "${GREEN}✓ Local development setup complete!${NC}"
echo ""
echo -e "${BLUE}To start development servers:${NC}"
echo " Backend: cd backend && source venv/bin/activate && uvicorn main:app --reload"
echo " Frontend: cd frontend && npm run dev"
;;
3)
echo -e "${BLUE}Setting up both Docker and local development...${NC}"
# Docker
docker-compose build
docker-compose up -d
# Local
cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cd ..
cd frontend
npm install
cd ..
echo -e "${GREEN}✓ Complete setup finished!${NC}"
;;
*)
echo -e "${RED}Invalid choice${NC}"
exit 1
;;
esac
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${GREEN}✨ pgSentinel setup complete! ✨${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -e "${BLUE}Next steps:${NC}"
echo " 1. Edit .env and configure your PostgreSQL connection"
echo " 2. Ensure pg_stat_statements extension is enabled in PostgreSQL"
echo " 3. Access the dashboard at http://localhost:3000"
echo " 4. View API documentation at http://localhost:8000/docs"
echo ""
echo -e "${BLUE}For more information, see:${NC}"
echo " - README.md"
echo " - docs/QUICK_START.md"
echo " - docs/PG_STAT_INSIGHTS.md"
echo ""