Skip to content

Commit 754cc4f

Browse files
Merge branch 'main' of gitlab.com:postgres-ai/postgres_ai
2 parents 3bdf14d + 60c210c commit 754cc4f

File tree

11 files changed

+1335
-10
lines changed

11 files changed

+1335
-10
lines changed

docker-compose.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ services:
2626
POSTGRES_DB: target_database
2727
POSTGRES_USER: postgres
2828
POSTGRES_PASSWORD: postgres
29-
command: ["postgres", "-c", "shared_preload_libraries=pg_stat_statements", "-c", "pg_stat_statements.track=all"]
29+
command:
30+
[
31+
"postgres",
32+
"-c",
33+
"shared_preload_libraries=pg_stat_statements",
34+
"-c",
35+
"pg_stat_statements.track=all",
36+
]
3037
ports:
3138
- "55432:5432"
3239
volumes:
@@ -57,18 +64,24 @@ services:
5764
- ./config/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
5865
- prometheus_data:/prometheus
5966
command:
60-
- '--config.file=/etc/prometheus/prometheus.yml'
61-
- '--storage.tsdb.path=/prometheus'
62-
- '--web.console.libraries=/etc/prometheus/console_libraries'
63-
- '--web.console.templates=/etc/prometheus/consoles'
64-
- '--storage.tsdb.retention.time=200h'
65-
- '--web.enable-lifecycle'
67+
- "--config.file=/etc/prometheus/prometheus.yml"
68+
- "--storage.tsdb.path=/prometheus"
69+
- "--web.console.libraries=/etc/prometheus/console_libraries"
70+
- "--web.console.templates=/etc/prometheus/consoles"
71+
- "--storage.tsdb.retention.time=200h"
72+
- "--web.enable-lifecycle"
6673

6774
# PGWatch Instance 1 - Monitoring service (Postgres sink)
6875
pgwatch-postgres:
6976
image: cybertecpostgresql/pgwatch:3
7077
container_name: pgwatch-postgres
71-
command: ["--sources=/etc/pgwatch/sources.yml", "--metrics=/etc/pgwatch/metrics.yml", "--sink=postgresql://pgwatch:pgwatchadmin@sink-postgres:5432/measurements", "--web-addr=:8080"]
78+
command:
79+
[
80+
"--sources=/etc/pgwatch/sources.yml",
81+
"--metrics=/etc/pgwatch/metrics.yml",
82+
"--sink=postgresql://pgwatch:pgwatchadmin@sink-postgres:5432/measurements",
83+
"--web-addr=:8080",
84+
]
7285
ports:
7386
- "58080:8080"
7487
depends_on:
@@ -83,7 +96,13 @@ services:
8396
pgwatch-prometheus:
8497
image: cybertecpostgresql/pgwatch:3
8598
container_name: pgwatch-prometheus
86-
command: ["--sources=/etc/pgwatch/sources.yml", "--metrics=/etc/pgwatch/metrics.yml", "--sink=prometheus://0.0.0.0:9091/pgwatch", "--web-addr=:8089"]
99+
command:
100+
[
101+
"--sources=/etc/pgwatch/sources.yml",
102+
"--metrics=/etc/pgwatch/metrics.yml",
103+
"--sink=prometheus://0.0.0.0:9091/pgwatch",
104+
"--web-addr=:8089",
105+
]
87106
ports:
88107
- "58089:8089"
89108
- "59091:9091"
@@ -101,7 +120,7 @@ services:
101120
container_name: grafana-with-datasources
102121
environment:
103122
GF_SECURITY_ADMIN_USER: monitor
104-
GF_SECURITY_ADMIN_PASSWORD: demo
123+
GF_SECURITY_ADMIN_PASSWORD: ${GF_SECURITY_ADMIN_PASSWORD:-demo}
105124
GF_INSTALL_PLUGINS: yesoreyeram-infinity-datasource
106125
ports:
107126
- "3000:3000"

terraform/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Terraform deployment modules
2+
3+
Infrastructure as Code modules for deploying postgres_ai monitoring to cloud providers.
4+
5+
## Available modules
6+
7+
### AWS (EC2)
8+
Single EC2 instance deployment with Docker Compose.
9+
10+
- **Path**: `aws/`
11+
- **Architecture**: Single EC2 instance with Docker Compose
12+
- **Best for**: Small to medium deployments (1-10 databases)
13+
- **Documentation**: [aws/README.md](aws/README.md)
14+
15+
### GCP (Coming soon)
16+
Deploy to Google Cloud Platform using Compute Engine or Cloud Run.
17+
18+
### Azure (Coming soon)
19+
Deploy to Microsoft Azure using Virtual Machines or Container Instances.
20+
21+
## Quick start
22+
23+
### AWS deployment
24+
25+
```bash
26+
cd terraform/aws
27+
28+
# Copy example variables
29+
cp terraform.tfvars.example terraform.tfvars
30+
31+
# Edit variables with your settings
32+
vim terraform.tfvars
33+
34+
# Initialize Terraform
35+
terraform init
36+
37+
# Review the plan
38+
terraform plan
39+
40+
# Deploy infrastructure (takes 5-10 minutes)
41+
terraform apply
42+
```
43+
44+
## Architecture overview
45+
46+
The AWS deployment creates:
47+
48+
1. **Compute**
49+
- Single EC2 instance (t3.medium default)
50+
- Ubuntu 22.04 LTS (Jammy) with Docker and Docker Compose
51+
- Systemd service for automatic startup
52+
53+
2. **Storage**
54+
- EBS volume for persistent data
55+
- Automated snapshots available via AWS Backup
56+
57+
3. **Networking**
58+
- VPC with public subnet
59+
- Security Group with restricted access
60+
- Optional Elastic IP for stable addressing
61+
62+
4. **Monitoring stack**
63+
- Runs docker-compose from cloned repository
64+
- Grafana accessible on port 3000
65+
66+
## Security considerations
67+
68+
- EC2 instance in public subnet (can be changed to private with bastion)
69+
- Security groups restrict access to SSH and Grafana only
70+
- All data encrypted at rest (EBS encryption)
71+
- Recommended: Use AWS Systems Manager Session Manager instead of SSH
72+
- Recommended: Restrict `allowed_cidr_blocks` to your office/VPN IP
73+
74+
## Instance types
75+
76+
Recommended instance types based on workload:
77+
78+
- **t3.medium**: 2 vCPU, 4 GiB RAM - suitable for 1-3 databases (default)
79+
- **t3.large**: 2 vCPU, 8 GiB RAM - suitable for 3-10 databases
80+
- **t3.xlarge**: 4 vCPU, 16 GiB RAM - suitable for 10+ databases
81+
82+
Additional options:
83+
- Use Spot Instances for non-critical workloads (subject to interruption)
84+
- Disable Elastic IP if stable address not required
85+
86+
## Support
87+
88+
For issues or questions:
89+
- Open an issue on GitLab
90+
- Contact PostgresAI support
91+
- Check documentation at https://postgres.ai
92+

terraform/aws/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Terraform files
2+
*.tfstate
3+
*.tfstate.*
4+
*.tfvars
5+
!terraform.tfvars.example
6+
.terraform/
7+
.terraform.lock.hcl
8+
crash.log
9+
override.tf
10+
override.tf.json
11+
*_override.tf
12+
*_override.tf.json
13+
tfplan
14+
plan.log
15+
16+
# OS files
17+
.DS_Store
18+
Thumbs.db
19+
20+
# IDE files
21+
.idea/
22+
.vscode/
23+
*.swp
24+
*.swo
25+
*~
26+
27+
# Backup files
28+
*.bak
29+
*.backup
30+
31+
# SSH keys
32+
*.pem
33+
*.key

terraform/aws/QUICKSTART.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Quick start
2+
3+
## Prerequisites
4+
5+
```bash
6+
# Create SSH key
7+
aws ec2 create-key-pair --key-name postgres-ai-key \
8+
--query 'KeyMaterial' --output text > ~/.ssh/postgres-ai-key.pem
9+
chmod 400 ~/.ssh/postgres-ai-key.pem
10+
11+
# Configure AWS credentials
12+
aws configure
13+
```
14+
15+
## Configure
16+
17+
```bash
18+
cd terraform/aws
19+
20+
# Copy example config
21+
cp terraform.tfvars.example terraform.tfvars
22+
vim terraform.tfvars
23+
```
24+
25+
Uncomment and set all required parameters:
26+
- `ssh_key_name` - your AWS SSH key name
27+
- `aws_region` - AWS region
28+
- `environment` - environment name
29+
- `instance_type` - EC2 instance type (e.g., t3.medium)
30+
- `data_volume_size` - data disk size in GiB
31+
- `data_volume_type` / `root_volume_type` - volume types (gp3, st1, sc1)
32+
- `allowed_ssh_cidr` / `allowed_cidr_blocks` - CIDR blocks for access
33+
- `use_elastic_ip` - allocate Elastic IP (true/false)
34+
- `grafana_password` - Grafana admin password
35+
- `postgres_ai_version` - git branch/tag (optional, defaults to "main")
36+
37+
## Add monitoring instances
38+
39+
Edit `terraform.tfvars` to add PostgreSQL instances to monitor:
40+
41+
```hcl
42+
monitoring_instances = [
43+
{
44+
name = "prod-db"
45+
conn_str = "postgresql://monitor:pass@db.example.com:5432/postgres"
46+
environment = "production"
47+
cluster = "main"
48+
node_name = "primary"
49+
}
50+
]
51+
```
52+
53+
## Deploy
54+
55+
```bash
56+
# Initialize and validate
57+
terraform init
58+
terraform validate
59+
60+
# Review changes
61+
terraform plan
62+
63+
# Deploy
64+
terraform apply
65+
66+
# Get access info
67+
terraform output grafana_url
68+
terraform output ssh_command
69+
```
70+
71+
## Access
72+
73+
```bash
74+
# Grafana dashboard
75+
open $(terraform output -raw grafana_url)
76+
# Login: monitor / <password from terraform.tfvars>
77+
78+
# SSH
79+
ssh -i ~/.ssh/postgres-ai-key.pem ubuntu@$(terraform output -raw external_ip)
80+
```
81+
82+
## Operations
83+
84+
```bash
85+
# View logs
86+
ssh ubuntu@IP "sudo cat /var/log/user-data.log"
87+
88+
# Restart services
89+
ssh ubuntu@IP "sudo systemctl restart postgres-ai"
90+
91+
# Destroy
92+
terraform destroy
93+
```
94+
95+
## Troubleshooting
96+
97+
```bash
98+
# Check installation log
99+
ssh ubuntu@IP "sudo cat /var/log/user-data.log"
100+
101+
# Check service status
102+
ssh ubuntu@IP "sudo systemctl status postgres-ai"
103+
104+
# Check containers
105+
ssh ubuntu@IP "sudo docker ps"
106+
```
107+
108+
## Security notes
109+
110+
Credentials (passwords, connection strings) are stored in `terraform.tfstate` in plain text. For one-off/dev deployments this is acceptable if you clean up after `terraform destroy`:
111+
112+
```bash
113+
terraform destroy
114+
rm -rf .terraform/ terraform.tfstate*
115+
```
116+
117+
For production deployments, consider:
118+
- Using environment variables: `export TF_VAR_grafana_password=...`
119+
- Remote state with encryption (S3 + encryption)
120+
- Configuring monitoring instances manually after deployment
121+

0 commit comments

Comments
 (0)