|
Bogdan Timofte
authored
3 months ago
|
1
|
# autoSMART Installation and Setup Guide
|
|
|
2
|
|
|
|
3
|
## 🚀 Quick Start
|
|
|
4
|
|
|
|
5
|
### Prerequisites Checklist
|
|
|
6
|
|
|
|
7
|
#### System Requirements
|
|
|
8
|
- ✅ **Operating System**: Linux (Ubuntu 20.04+, CentOS 8+, Proxmox VE 7+)
|
|
|
9
|
- ✅ **Perl**: Version 5.20+ with CPAN access
|
|
|
10
|
- ✅ **PostgreSQL**: Version 13+ with JSONB support
|
|
|
11
|
- ✅ **Hardware Access**: sudo/root access for SMART data collection
|
|
|
12
|
- ✅ **Network**: Access to OpenAI API (optional, for AI predictions)
|
|
|
13
|
|
|
|
14
|
#### Test Database Available
|
|
|
15
|
```
|
|
|
16
|
Host: 192.168.2.102
|
|
|
17
|
Database: autosmart
|
|
|
18
|
User: postgres
|
|
|
19
|
Password: (no password)
|
|
|
20
|
Port: 5432
|
|
|
21
|
```
|
|
|
22
|
|
|
|
23
|
## 🔧 Installation Steps
|
|
|
24
|
|
|
|
25
|
### 1. System Dependencies
|
|
|
26
|
|
|
|
27
|
#### Ubuntu/Debian
|
|
|
28
|
```bash
|
|
|
29
|
# Update system packages
|
|
|
30
|
sudo apt update && sudo apt upgrade -y
|
|
|
31
|
|
|
|
32
|
# Install system dependencies
|
|
|
33
|
sudo apt install -y perl postgresql-client smartmontools git curl
|
|
|
34
|
|
|
|
35
|
# Install PostgreSQL server (if not using remote database)
|
|
|
36
|
sudo apt install -y postgresql postgresql-contrib
|
|
|
37
|
|
|
|
38
|
# Install Perl development tools
|
|
|
39
|
sudo apt install -y build-essential cpanminus libdbi-perl
|
|
|
40
|
```
|
|
|
41
|
|
|
|
42
|
#### CentOS/RHEL/Rocky Linux
|
|
|
43
|
```bash
|
|
|
44
|
# Update system packages
|
|
|
45
|
sudo dnf update -y
|
|
|
46
|
|
|
|
47
|
# Install system dependencies
|
|
|
48
|
sudo dnf install -y perl postgresql smartmontools git curl
|
|
|
49
|
|
|
|
50
|
# Install development tools
|
|
|
51
|
sudo dnf groupinstall -y "Development Tools"
|
|
|
52
|
sudo dnf install -y perl-App-cpanminus perl-DBI
|
|
|
53
|
```
|
|
|
54
|
|
|
|
55
|
#### Proxmox VE
|
|
|
56
|
```bash
|
|
|
57
|
# Proxmox already includes most dependencies
|
|
|
58
|
apt update
|
|
|
59
|
apt install -y cpanminus libdbi-perl libdbd-pg-perl libjson-xs-perl
|
|
|
60
|
```
|
|
|
61
|
|
|
|
62
|
### 2. Perl Modules Installation
|
|
|
63
|
|
|
|
64
|
#### Required Modules
|
|
|
65
|
```bash
|
|
|
66
|
# Core database connectivity
|
|
|
67
|
sudo cpanm DBI DBD::Pg
|
|
|
68
|
|
|
|
69
|
# JSON processing
|
|
|
70
|
sudo cpanm JSON::XS
|
|
|
71
|
|
|
|
72
|
# Configuration and utilities
|
|
|
73
|
sudo cpanm Config::Simple File::Slurp Time::HiRes Digest::SHA
|
|
|
74
|
|
|
|
75
|
# HTTP clients for API integration
|
|
|
76
|
sudo cpanm LWP::UserAgent HTTP::Request::Common
|
|
|
77
|
|
|
|
78
|
# Optional: Testing modules
|
|
|
79
|
sudo cpanm Test::More Test::Exception Data::Dumper
|
|
|
80
|
```
|
|
|
81
|
|
|
|
82
|
#### Verify Perl Module Installation
|
|
|
83
|
```bash
|
|
|
84
|
perl -e "
|
|
|
85
|
use DBI;
|
|
|
86
|
use JSON::XS;
|
|
|
87
|
use Config::Simple;
|
|
|
88
|
use Digest::SHA;
|
|
|
89
|
use LWP::UserAgent;
|
|
|
90
|
print \"All required Perl modules installed successfully!\n\";
|
|
|
91
|
"
|
|
|
92
|
```
|
|
|
93
|
|
|
|
94
|
### 3. Database Setup
|
|
|
95
|
|
|
|
96
|
#### Option A: Use Test Database (Recommended for Development)
|
|
|
97
|
```bash
|
|
|
98
|
# Test connection to existing database
|
|
|
99
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "SELECT version();"
|
|
|
100
|
|
|
|
101
|
# If successful, skip to step 4 - Project Installation
|
|
|
102
|
```
|
|
|
103
|
|
|
|
104
|
#### Option B: Local PostgreSQL Installation
|
|
|
105
|
```bash
|
|
|
106
|
# Install PostgreSQL
|
|
|
107
|
sudo apt install -y postgresql postgresql-contrib
|
|
|
108
|
|
|
|
109
|
# Start and enable PostgreSQL
|
|
|
110
|
sudo systemctl start postgresql
|
|
|
111
|
sudo systemctl enable postgresql
|
|
|
112
|
|
|
|
113
|
# Create database and user
|
|
|
114
|
sudo -u postgres psql << EOF
|
|
|
115
|
CREATE DATABASE autosmart;
|
|
|
116
|
CREATE USER autosmart WITH PASSWORD 'smartpassword';
|
|
|
117
|
GRANT ALL PRIVILEGES ON DATABASE autosmart TO autosmart;
|
|
|
118
|
ALTER USER autosmart CREATEDB;
|
|
|
119
|
\q
|
|
|
120
|
EOF
|
|
|
121
|
```
|
|
|
122
|
|
|
|
123
|
#### Option C: Remote PostgreSQL Setup
|
|
|
124
|
```bash
|
|
|
125
|
# Connect to your PostgreSQL server
|
|
|
126
|
psql -h your-db-host -U postgres
|
|
|
127
|
|
|
|
128
|
# Create database and configure
|
|
|
129
|
CREATE DATABASE autosmart;
|
|
|
130
|
CREATE USER autosmart WITH PASSWORD 'your-secure-password';
|
|
|
131
|
GRANT ALL PRIVILEGES ON DATABASE autosmart TO autosmart;
|
|
|
132
|
```
|
|
|
133
|
|
|
|
134
|
### 4. Project Installation
|
|
|
135
|
|
|
|
136
|
#### Download and Setup
|
|
|
137
|
```bash
|
|
|
138
|
# Create installation directory
|
|
|
139
|
sudo mkdir -p /etc/pve/autoSMART
|
|
|
140
|
cd /etc/pve/autoSMART
|
|
|
141
|
|
|
|
142
|
# Clone or copy project files (adjust as needed)
|
|
|
143
|
# git clone https://github.com/your-repo/autoSMART.git .
|
|
|
144
|
# OR copy from development workspace:
|
|
|
145
|
cp -r /Users/bogdan/Documents/workspace/autoSMART/* .
|
|
|
146
|
|
|
|
147
|
# Set proper ownership and permissions
|
|
|
148
|
sudo chown -R root:root .
|
|
|
149
|
chmod +x scripts/*.pl
|
|
|
150
|
chmod 600 config/cluster.conf
|
|
|
151
|
```
|
|
|
152
|
|
|
|
153
|
#### Directory Structure Verification
|
|
|
154
|
```bash
|
|
|
155
|
tree /etc/pve/autoSMART
|
|
|
156
|
# Should show:
|
|
|
157
|
# ├── config/
|
|
|
158
|
# ├── docs/
|
|
|
159
|
# ├── lib/
|
|
|
160
|
# ├── scripts/
|
|
|
161
|
# ├── sql/
|
|
|
162
|
# └── README.md
|
|
|
163
|
```
|
|
|
164
|
|
|
|
165
|
### 5. Database Deployment
|
|
|
166
|
|
|
|
167
|
autoSMART uses PostgreSQL for storing SMART data, configurations, and analysis results. You can deploy the database schema from your development machine using the included deployment scripts.
|
|
|
168
|
|
|
|
169
|
#### Prerequisites for Database Deployment
|
|
|
170
|
- ✅ **psql** client installed on development machine (macOS/Linux)
|
|
|
171
|
- ✅ **Network access** to target PostgreSQL server
|
|
|
172
|
- ✅ **Database credentials** with schema creation privileges
|
|
|
173
|
- ✅ **Target database** already created and accessible
|
|
|
174
|
|
|
|
175
|
#### Database Deployment with deploy.sh
|
|
|
176
|
|
|
|
177
|
The `deploy.sh` script can install the database schema remotely using psql from your development machine:
|
|
|
178
|
|
|
|
179
|
```bash
|
|
|
180
|
# Show help and available options
|
|
|
181
|
./deploy.sh
|
|
|
182
|
|
|
|
183
|
# Deploy database schema to remote PostgreSQL server
|
|
|
184
|
./deploy.sh install database --db-host 192.168.2.102 --db-user postgres --db-name autosmart
|
|
|
185
|
|
|
|
186
|
# Deploy with custom credentials
|
|
|
187
|
./deploy.sh install database \
|
|
|
188
|
--db-host your-postgres-server.local \
|
|
|
189
|
--db-user autosmart \
|
|
|
190
|
--db-pass your-password \
|
|
|
191
|
--db-name autosmart_prod
|
|
|
192
|
```
|
|
|
193
|
|
|
|
194
|
#### Manual Database Installation from Development Machine
|
|
|
195
|
|
|
|
196
|
If you prefer manual control over the database installation:
|
|
|
197
|
|
|
|
198
|
```bash
|
|
|
199
|
# 1. Ensure psql is available on your development machine
|
|
|
200
|
# macOS:
|
|
|
201
|
brew install postgresql
|
|
|
202
|
|
|
|
203
|
# Ubuntu/Debian:
|
|
|
204
|
sudo apt install postgresql-client
|
|
|
205
|
|
|
|
206
|
# 2. Test connection to target database
|
|
|
207
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "SELECT version();"
|
|
|
208
|
|
|
|
209
|
# 3. Install the complete schema
|
|
|
210
|
psql -h 192.168.2.102 -U postgres -d autosmart -f sql/schema.sql
|
|
|
211
|
|
|
|
212
|
# 4. Verify schema installation
|
|
|
213
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
214
|
SELECT
|
|
|
215
|
schemaname,
|
|
|
216
|
tablename,
|
|
|
217
|
tableowner
|
|
|
218
|
FROM pg_tables
|
|
|
219
|
WHERE schemaname = 'public'
|
|
|
220
|
ORDER BY tablename;
|
|
|
221
|
"
|
|
|
222
|
|
|
|
223
|
# 5. Check database functions and triggers
|
|
|
224
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
225
|
SELECT
|
|
|
226
|
proname as function_name,
|
|
|
227
|
pg_get_function_result(oid) as return_type
|
|
|
228
|
FROM pg_proc
|
|
|
229
|
WHERE pronamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')
|
|
|
230
|
ORDER BY proname;
|
|
|
231
|
"
|
|
|
232
|
```
|
|
|
233
|
|
|
|
234
|
#### Database Schema Components
|
|
|
235
|
|
|
|
236
|
The autoSMART database schema includes:
|
|
|
237
|
|
|
|
238
|
**Core Tables:**
|
|
|
239
|
- `hdd_inventory` - Physical drive tracking and migration history
|
|
|
240
|
- `smart_readings` - Raw SMART data collection (differential storage)
|
|
|
241
|
- `smart_thresholds` - Drive-specific alert thresholds
|
|
|
242
|
- `predictions` - AI-generated failure predictions
|
|
|
243
|
- `alert_history` - System alerts and notifications
|
|
|
244
|
- `system_config` - Cluster-wide configuration settings
|
|
|
245
|
|
|
|
246
|
**Analytical Views:**
|
|
|
247
|
- `smart_readings_reconstructed` - Full SMART data reconstruction from differential storage
|
|
|
248
|
- `latest_smart_readings` - Most recent SMART values per drive
|
|
|
249
|
- `drive_health_summary` - Drive health status and trend analysis
|
|
|
250
|
|
|
|
251
|
**Functions and Triggers:**
|
|
|
252
|
- `differential_storage_trigger()` - Automatic differential storage on SMART updates
|
|
|
253
|
- `update_drive_health()` - Health score calculation
|
|
|
254
|
- `cleanup_old_readings()` - Data retention management
|
|
|
255
|
|
|
|
256
|
#### Database Verification Commands
|
|
|
257
|
|
|
|
258
|
```bash
|
|
|
259
|
# Verify all components are installed
|
|
|
260
|
psql -h 192.168.2.102 -U postgres -d autosmart << EOF
|
|
|
261
|
|
|
|
262
|
-- Check table count and sizes
|
|
|
263
|
SELECT
|
|
|
264
|
schemaname,
|
|
|
265
|
tablename,
|
|
|
266
|
pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) as size
|
|
|
267
|
FROM pg_tables
|
|
|
268
|
WHERE schemaname = 'public';
|
|
|
269
|
|
|
|
270
|
-- Check views
|
|
|
271
|
SELECT
|
|
|
272
|
schemaname,
|
|
|
273
|
viewname,
|
|
|
274
|
definition
|
|
|
275
|
FROM pg_views
|
|
|
276
|
WHERE schemaname = 'public';
|
|
|
277
|
|
|
|
278
|
-- Test differential storage function
|
|
|
279
|
SELECT differential_storage_trigger() as function_test;
|
|
|
280
|
|
|
|
281
|
-- Verify database is ready
|
|
|
282
|
SELECT 'autoSMART database ready!' as status;
|
|
|
283
|
|
|
|
284
|
EOF
|
|
|
285
|
```
|
|
|
286
|
|
|
|
287
|
#### Troubleshooting Database Installation
|
|
|
288
|
|
|
|
289
|
**Connection Issues:**
|
|
|
290
|
```bash
|
|
|
291
|
# Test basic connectivity
|
|
|
292
|
ping 192.168.2.102
|
|
|
293
|
|
|
|
294
|
# Test PostgreSQL port
|
|
|
295
|
telnet 192.168.2.102 5432
|
|
|
296
|
|
|
|
297
|
# Test authentication
|
|
|
298
|
psql -h 192.168.2.102 -U postgres -d postgres -c "SELECT current_user;"
|
|
|
299
|
```
|
|
|
300
|
|
|
|
301
|
**Schema Installation Issues:**
|
|
|
302
|
```bash
|
|
|
303
|
# Check for existing schema conflicts
|
|
|
304
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
305
|
SELECT table_name FROM information_schema.tables
|
|
|
306
|
WHERE table_schema = 'public' AND table_name LIKE '%smart%';
|
|
|
307
|
"
|
|
|
308
|
|
|
|
309
|
# Force clean installation (⚠️ DESTRUCTIVE)
|
|
|
310
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
311
|
DROP SCHEMA public CASCADE;
|
|
|
312
|
CREATE SCHEMA public;
|
|
|
313
|
GRANT ALL ON SCHEMA public TO postgres;
|
|
|
314
|
GRANT ALL ON SCHEMA public TO public;
|
|
|
315
|
"
|
|
|
316
|
|
|
|
317
|
# Reinstall schema
|
|
|
318
|
psql -h 192.168.2.102 -U postgres -d autosmart -f sql/schema.sql
|
|
|
319
|
```
|
|
|
320
|
|
|
|
321
|
### 6. Database Schema Installation (Legacy Method)
|
|
|
322
|
|
|
|
323
|
#### Using Test Database (192.168.2.102)
|
|
|
324
|
```bash
|
|
|
325
|
# Install the complete schema
|
|
|
326
|
cd /etc/pve/autoSMART
|
|
|
327
|
psql -h 192.168.2.102 -U postgres -d autosmart -f sql/schema.sql
|
|
|
328
|
|
|
|
329
|
# Verify installation
|
|
|
330
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
331
|
SELECT table_name FROM information_schema.tables
|
|
|
332
|
WHERE table_schema = 'public'
|
|
|
333
|
ORDER BY table_name;
|
|
|
334
|
"
|
|
|
335
|
```
|
|
|
336
|
|
|
|
337
|
#### Expected Tables
|
|
|
338
|
- ✅ hdd_inventory
|
|
|
339
|
- ✅ hdd_migrations
|
|
|
340
|
- ✅ smart_readings
|
|
|
341
|
- ✅ predictions
|
|
|
342
|
- ✅ smart_thresholds
|
|
|
343
|
- ✅ alert_history
|
|
|
344
|
- ✅ system_config
|
|
|
345
|
|
|
|
346
|
#### Expected Views
|
|
|
347
|
- ✅ smart_readings_reconstructed
|
|
|
348
|
- ✅ latest_smart_readings
|
|
|
349
|
- ✅ drive_health_summary
|
|
|
350
|
|
|
|
351
|
### 7. Configuration
|
|
|
352
|
|
|
|
353
|
#### Cluster Configuration
|
|
|
354
|
```bash
|
|
|
355
|
# Edit cluster-wide settings
|
|
|
356
|
nano /etc/pve/autoSMART/config/cluster.conf
|
|
|
357
|
```
|
|
|
358
|
|
|
|
359
|
```ini
|
|
|
360
|
[database]
|
|
|
361
|
host = 192.168.2.102
|
|
|
362
|
port = 5432
|
|
|
363
|
name = autosmart
|
|
|
364
|
user = postgres
|
|
|
365
|
password =
|
|
|
366
|
|
|
|
367
|
[collection]
|
|
|
368
|
interval = 1800
|
|
|
369
|
timeout = 60
|
|
|
370
|
madagascar_inventory_path = /opt/madagascar/inventory.json
|
|
|
371
|
|
|
|
372
|
[ai_predictions]
|
|
|
373
|
enabled = true
|
|
|
374
|
openai_api_key = your-openai-api-key-here
|
|
|
375
|
openai_model = gpt-4
|
|
|
376
|
prediction_interval = 86400
|
|
|
377
|
|
|
|
378
|
[alerts]
|
|
|
379
|
enabled = true
|
|
|
380
|
email_notifications = true
|
|
|
381
|
slack_webhook = https://hooks.slack.com/your-webhook
|
|
|
382
|
```
|
|
|
383
|
|
|
|
384
|
#### Local Node Configuration
|
|
|
385
|
```bash
|
|
|
386
|
# Copy default configuration
|
|
|
387
|
cp config/defaults/autosmart /etc/default/autosmart
|
|
|
388
|
|
|
|
389
|
# Edit local settings
|
|
|
390
|
nano /etc/default/autosmart
|
|
|
391
|
```
|
|
|
392
|
|
|
|
393
|
```bash
|
|
|
394
|
# autoSMART local configuration
|
|
|
395
|
AUTOSMART_DEBUG=2
|
|
|
396
|
AUTOSMART_NODE_ID=$(hostname)
|
|
|
397
|
AUTOSMART_CLUSTER_CONFIG="/etc/pve/autoSMART/config/cluster.conf"
|
|
|
398
|
|
|
|
399
|
# Local database override (if needed)
|
|
|
400
|
# AUTOSMART_DB_HOST=192.168.2.102
|
|
|
401
|
# AUTOSMART_DB_USER=postgres
|
|
|
402
|
# AUTOSMART_DB_PASS=
|
|
|
403
|
|
|
|
404
|
# OpenAI API configuration
|
|
|
405
|
OPENAI_API_KEY=your-api-key-here
|
|
|
406
|
|
|
|
407
|
# Collection settings
|
|
|
408
|
SMART_COLLECTION_ENABLED=true
|
|
|
409
|
MIGRATION_DETECTION_ENABLED=true
|
|
|
410
|
DIFFERENTIAL_STORAGE_ENABLED=true
|
|
|
411
|
```
|
|
|
412
|
|
|
|
413
|
### 8. Testing Installation
|
|
|
414
|
|
|
|
415
|
#### Database Connectivity Test
|
|
|
416
|
```bash
|
|
|
417
|
cd /etc/pve/autoSMART
|
|
|
418
|
perl -e "
|
|
|
419
|
use lib 'lib';
|
|
|
420
|
use DBI;
|
|
|
421
|
|
|
|
422
|
my \$dsn = 'DBI:Pg:dbname=autosmart;host=192.168.2.102;port=5432';
|
|
|
423
|
my \$dbh = DBI->connect(\$dsn, 'postgres', '', {RaiseError => 1});
|
|
|
424
|
|
|
|
425
|
print \"✅ Database connection successful!\n\";
|
|
|
426
|
|
|
|
427
|
# Test schema
|
|
|
428
|
my \$sth = \$dbh->prepare('SELECT COUNT(*) FROM hdd_inventory');
|
|
|
429
|
\$sth->execute();
|
|
|
430
|
my (\$count) = \$sth->fetchrow_array();
|
|
|
431
|
|
|
|
432
|
print \"✅ Schema installed - hdd_inventory table accessible\n\";
|
|
|
433
|
\$dbh->disconnect();
|
|
|
434
|
"
|
|
|
435
|
```
|
|
|
436
|
|
|
|
437
|
#### SMART Data Collection Test
|
|
|
438
|
```bash
|
|
|
439
|
# Test SMART data access
|
|
|
440
|
sudo smartctl -a /dev/sda | head -20
|
|
|
441
|
|
|
|
442
|
# Test collection script (dry-run mode)
|
|
|
443
|
cd /etc/pve/autoSMART/scripts
|
|
|
444
|
sudo perl collect-smart-data.pl --test --dry-run
|
|
|
445
|
```
|
|
|
446
|
|
|
|
447
|
#### Differential Storage Test
|
|
|
448
|
```bash
|
|
|
449
|
# Run comprehensive storage test
|
|
|
450
|
cd /etc/pve/autoSMART/scripts
|
|
|
451
|
perl test-differential-storage.pl
|
|
|
452
|
```
|
|
|
453
|
|
|
|
454
|
Expected output:
|
|
|
455
|
```
|
|
|
456
|
=== autoSMART Differential Storage Test ===
|
|
|
457
|
✓ Connected to database
|
|
|
458
|
✓ Created test HDD (ID: 1)
|
|
|
459
|
✓ Inserted baseline reading (ID: 1)
|
|
|
460
|
✓ Identical reading test - Should store: NO (Type: baseline)
|
|
|
461
|
✓ Temperature change reading - Should store: YES (Type: differential, ID: 2)
|
|
|
462
|
✓ Critical change reading - Should store: YES (Type: full, ID: 3)
|
|
|
463
|
--- Storage Statistics ---
|
|
|
464
|
baseline : 1 readings, avg size: 245 bytes
|
|
|
465
|
differential : 1 readings, avg size: 89 bytes
|
|
|
466
|
full : 1 readings, avg size: 245 bytes
|
|
|
467
|
Total: 3 readings, estimated size: 579 bytes
|
|
|
468
|
=== Test Complete ===
|
|
|
469
|
```
|
|
|
470
|
|
|
|
471
|
### 9. Service Configuration (Optional)
|
|
|
472
|
|
|
|
473
|
#### SystemD Service Files
|
|
|
474
|
|
|
|
475
|
Create `/etc/systemd/system/autosmart-collector.service`:
|
|
|
476
|
```ini
|
|
|
477
|
[Unit]
|
|
|
478
|
Description=autoSMART Data Collector
|
|
|
479
|
After=network.target postgresql.service
|
|
|
480
|
|
|
|
481
|
[Service]
|
|
|
482
|
Type=simple
|
|
|
483
|
User=root
|
|
|
484
|
WorkingDirectory=/etc/pve/autoSMART
|
|
|
485
|
ExecStart=/usr/bin/perl scripts/collect-smart-data.pl --daemon
|
|
|
486
|
Restart=always
|
|
|
487
|
RestartSec=30
|
|
|
488
|
|
|
|
489
|
[Install]
|
|
|
490
|
WantedBy=multi-user.target
|
|
|
491
|
```
|
|
|
492
|
|
|
|
493
|
Create `/etc/systemd/system/autosmart-analyzer.service`:
|
|
|
494
|
```ini
|
|
|
495
|
[Unit]
|
|
|
496
|
Description=autoSMART AI Analyzer
|
|
|
497
|
After=network.target postgresql.service autosmart-collector.service
|
|
|
498
|
|
|
|
499
|
[Service]
|
|
|
500
|
Type=simple
|
|
|
501
|
User=root
|
|
|
502
|
WorkingDirectory=/etc/pve/autoSMART
|
|
|
503
|
ExecStart=/usr/bin/perl scripts/analyze-smart-data.pl --daemon
|
|
|
504
|
Restart=always
|
|
|
505
|
RestartSec=60
|
|
|
506
|
|
|
|
507
|
[Install]
|
|
|
508
|
WantedBy=multi-user.target
|
|
|
509
|
```
|
|
|
510
|
|
|
|
511
|
#### Enable Services
|
|
|
512
|
```bash
|
|
|
513
|
# Reload systemd configuration
|
|
|
514
|
sudo systemctl daemon-reload
|
|
|
515
|
|
|
|
516
|
# Enable and start services
|
|
|
517
|
sudo systemctl enable autosmart-collector
|
|
|
518
|
sudo systemctl start autosmart-collector
|
|
|
519
|
|
|
|
520
|
sudo systemctl enable autosmart-analyzer
|
|
|
521
|
sudo systemctl start autosmart-analyzer
|
|
|
522
|
|
|
|
523
|
# Check service status
|
|
|
524
|
sudo systemctl status autosmart-collector
|
|
|
525
|
sudo systemctl status autosmart-analyzer
|
|
|
526
|
```
|
|
|
527
|
|
|
|
528
|
### 10. Verification and Monitoring
|
|
|
529
|
|
|
|
530
|
#### Log Files
|
|
|
531
|
```bash
|
|
|
532
|
# View collection logs
|
|
|
533
|
sudo journalctl -u autosmart-collector -f
|
|
|
534
|
|
|
|
535
|
# View analysis logs
|
|
|
536
|
sudo journalctl -u autosmart-analyzer -f
|
|
|
537
|
|
|
|
538
|
# Check syslog for SMART events
|
|
|
539
|
sudo tail -f /var/log/syslog | grep -i smart
|
|
|
540
|
```
|
|
|
541
|
|
|
|
542
|
#### Database Monitoring
|
|
|
543
|
```bash
|
|
|
544
|
# Monitor data collection
|
|
|
545
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
546
|
SELECT
|
|
|
547
|
COUNT(*) as total_readings,
|
|
|
548
|
MAX(timestamp) as latest_reading,
|
|
|
549
|
COUNT(DISTINCT hdd_id) as active_drives
|
|
|
550
|
FROM smart_readings
|
|
|
551
|
WHERE timestamp > NOW() - INTERVAL '24 hours';
|
|
|
552
|
"
|
|
|
553
|
|
|
|
554
|
# Monitor storage efficiency
|
|
|
555
|
psql -h 192.168.2.102 -U postgres -d autosmart -c "
|
|
|
556
|
SELECT
|
|
|
557
|
reading_type,
|
|
|
558
|
COUNT(*) as count,
|
|
|
559
|
COUNT(*) * 100.0 / SUM(COUNT(*)) OVER() as percentage
|
|
|
560
|
FROM smart_readings
|
|
|
561
|
WHERE timestamp > NOW() - INTERVAL '24 hours'
|
|
|
562
|
GROUP BY reading_type;
|
|
|
563
|
"
|
|
|
564
|
```
|
|
|
565
|
|
|
|
566
|
## 🎯 Post-Installation Steps
|
|
|
567
|
|
|
|
568
|
### 1. Madagascar Integration
|
|
|
569
|
```bash
|
|
|
570
|
# Ensure Madagascar inventory is accessible
|
|
|
571
|
ls -la /opt/madagascar/inventory.json
|
|
|
572
|
|
|
|
573
|
# Test Madagascar data parsing
|
|
|
574
|
cd /etc/pve/autoSMART/scripts
|
|
|
575
|
perl -e "
|
|
|
576
|
use JSON::XS;
|
|
|
577
|
my \$data = decode_json(qx(cat /opt/madagascar/inventory.json));
|
|
|
578
|
print 'Madagascar drives found: ' . scalar(\@{\$data->{drives}}) . \"\n\";
|
|
|
579
|
"
|
|
|
580
|
```
|
|
|
581
|
|
|
|
582
|
### 2. OpenAI API Setup (Optional)
|
|
|
583
|
```bash
|
|
|
584
|
# Test OpenAI API access
|
|
|
585
|
curl -H "Authorization: Bearer your-api-key" \
|
|
|
586
|
-H "Content-Type: application/json" \
|
|
|
587
|
-d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "Hello"}]}' \
|
|
|
588
|
https://api.openai.com/v1/chat/completions
|
|
|
589
|
```
|
|
|
590
|
|
|
|
591
|
### 3. Alert Configuration
|
|
|
592
|
```bash
|
|
|
593
|
# Test email notifications (if configured)
|
|
|
594
|
echo "Test autoSMART alert" | mail -s "autoSMART Test" admin@yourcompany.com
|
|
|
595
|
|
|
|
596
|
# Test Slack webhook (if configured)
|
|
|
597
|
curl -X POST -H 'Content-type: application/json' \
|
|
|
598
|
--data '{"text":"autoSMART installation test"}' \
|
|
|
599
|
YOUR_SLACK_WEBHOOK_URL
|
|
|
600
|
```
|
|
|
601
|
|
|
|
602
|
## 🔍 Troubleshooting
|
|
|
603
|
|
|
|
604
|
### Common Issues
|
|
|
605
|
|
|
|
606
|
#### Database Connection Failed
|
|
|
607
|
```bash
|
|
|
608
|
# Check PostgreSQL service
|
|
|
609
|
sudo systemctl status postgresql
|
|
|
610
|
|
|
|
611
|
# Test network connectivity
|
|
|
612
|
telnet 192.168.2.102 5432
|
|
|
613
|
|
|
|
614
|
# Check firewall
|
|
|
615
|
sudo ufw status
|
|
|
616
|
sudo iptables -L | grep 5432
|
|
|
617
|
```
|
|
|
618
|
|
|
|
619
|
#### Permission Denied for SMART Data
|
|
|
620
|
```bash
|
|
|
621
|
# Check smartctl permissions
|
|
|
622
|
ls -la /usr/sbin/smartctl
|
|
|
623
|
|
|
|
624
|
# Test with sudo
|
|
|
625
|
sudo smartctl -a /dev/sda
|
|
|
626
|
|
|
|
627
|
# Add user to disk group (if running as non-root)
|
|
|
628
|
sudo usermod -a -G disk $USER
|
|
|
629
|
```
|
|
|
630
|
|
|
|
631
|
#### Perl Module Issues
|
|
|
632
|
```bash
|
|
|
633
|
# Check module installation
|
|
|
634
|
perl -MDBI -e 'print "DBI version: $DBI::VERSION\n"'
|
|
|
635
|
perl -MJSON::XS -e 'print "JSON::XS installed OK\n"'
|
|
|
636
|
|
|
|
637
|
# Reinstall problematic modules
|
|
|
638
|
sudo cpanm --force --reinstall DBD::Pg
|
|
|
639
|
```
|
|
|
640
|
|
|
|
641
|
### Log Analysis
|
|
|
642
|
```bash
|
|
|
643
|
# Enable debug logging
|
|
|
644
|
export AUTOSMART_DEBUG=3
|
|
|
645
|
|
|
|
646
|
# Run collection manually for debugging
|
|
|
647
|
cd /etc/pve/autoSMART/scripts
|
|
|
648
|
sudo perl collect-smart-data.pl --verbose --test
|
|
|
649
|
```
|
|
|
650
|
|
|
|
651
|
## 📚 Next Steps
|
|
|
652
|
|
|
|
653
|
1. **Customize Configuration**: Adjust thresholds and intervals for your environment
|
|
|
654
|
2. **Set Up Monitoring**: Configure alerts and dashboards
|
|
|
655
|
3. **Schedule Regular Backups**: Database and configuration files
|
|
|
656
|
4. **Plan for Scaling**: Consider performance optimization for large deployments
|
|
|
657
|
5. **Implement AI Predictions**: Configure OpenAI integration for failure prediction
|
|
|
658
|
|
|
|
659
|
For more detailed information, see:
|
|
|
660
|
- [DEVELOPMENT.md](DEVELOPMENT.md) - Development and customization guide
|
|
|
661
|
- [API.md](API.md) - OpenAI API integration details
|
|
|
662
|
- [DIFFERENTIAL_STORAGE.md](DIFFERENTIAL_STORAGE.md) - Storage optimization details
|
|
|
663
|
- [MIGRATION_DETECTION.md](MIGRATION_DETECTION.md) - HDD tracking system details
|
|
|
664
|
|
|
|
665
|
## 🆘 Getting Help
|
|
|
666
|
|
|
|
667
|
If you encounter issues during installation:
|
|
|
668
|
|
|
|
669
|
1. **Check logs**: `journalctl -u autosmart-collector -n 50`
|
|
|
670
|
2. **Verify database**: Test database connectivity and schema
|
|
|
671
|
3. **Test components**: Run individual scripts manually with debug output
|
|
|
672
|
4. **Review configuration**: Ensure all paths and credentials are correct
|
|
|
673
|
5. **Check dependencies**: Verify all system and Perl dependencies are installed
|
|
|
674
|
|
|
|
675
|
The autoSMART system is designed to be robust and self-healing, but proper installation and configuration are essential for optimal performance.
|