Skip to content

Commit 95a000b

Browse files
committed
Update readme and add a single sql file for new installations
1 parent df4cc5d commit 95a000b

File tree

9 files changed

+154
-14
lines changed

9 files changed

+154
-14
lines changed

README.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# SBOanalytics
2-
Web site log analytics on a budget.
2+
Web site and server analytics on a budget.
33

44
**Background and motivation**
55

6-
Running web sites on a budget is not too hard (especially for Apache, PHP, Mysql people like us) but monitoring web site activity is not so easy
7-
(and obviously we do not want to spend any money for it).
6+
Running web sites on a budget is not too hard (especially for Apache, PHP, Mysql people like us)
7+
but monitoring web site and server activity is not so easy (and obviously we do not want to spend any money for it).
88

99
This tool is suitable for people running their own web sites on their own VMs, droplets etc. You must be able to run operating system commands on your server
10-
to run the log processing component and you should know how to deploy PHP apps.
10+
to run the log processing component and you should know how to deploy PHP apps.
11+
You can monitor web site and operating system metrics with minimal effort.
1112

1213
## Components
1314

1415
### Log processor
15-
You need to run the log processor, https://github.com/SBOsoft/SBOLogProcessor, to collect web server access logs.
16-
It will monitor your access logs, generate metrics and optionally save logs to its database (for now only mysql is supported).
16+
You need to run the log processor, https://github.com/SBOsoft/SBOLogProcessor,
17+
to collect web server access logs, web site metrics and operating system metrics.
18+
It will monitor your access logs, generate metrics and optionally save logs to a database (for now only mysql is supported).
1719

1820
### SBOanalytics (this application), the frontend
1921
Use this application to view metrics and logs collected by the log processor. Data generated by the log processor will be saved in a mysql database.
@@ -45,18 +47,28 @@ To set up the containers, change into the containers folder and run `docker-comp
4547

4648
### Production deployments
4749

48-
- Go to https://github.com/SBOsoft/SBOanalytics/releases and download a release package, i.e SBOanalytics-xxxx.xx.xx.xxx.zip.
49-
- Copy the zip file into a new folder and unzip it
50-
- Review the .htaccess file in the package. The .htaccess file contains multiple SetEnv directives which are commented out by default.
50+
1. Go to https://github.com/SBOsoft/SBOanalytics/releases and download a release package, i.e SBOanalytics-xxxx.xx.xx.xxx.zip.
51+
2. Copy the zip file into a new folder and unzip it
52+
3. Review the .htaccess file in the package. The .htaccess file contains multiple SetEnv directives which are commented out by default.
5153
Environment variables are used for application configuration. You can either set them in the .htaccess file or in your VirtualHost configuration.
5254
Setting them up in VirtualHost configuration will allow for easier updates. If you set them in the .htaccess file then during upgrades
5355
you will need to migrate your changes to the .htaccess file manually.
54-
- Just placing the folder to a path under your php enabled virtual host will work
55-
- To upgrade, download a release package, extract into a new folder and replace your existing deployment folder with the new one after
56+
4. Just placing the folder to a path under a php enabled virtual host will work
57+
5. To upgrade, download a release package, extract into a new folder and replace your existing deployment folder with the new one after
5658
migrating the changes in your existing .htacess file. Do NOT replace the new .htaccess with your existing .htaccess file as there maybe changes
5759
required for the new version to function properly.
5860

61+
#### Database setup for new installations
62+
1. Review db/db-for-new-installations.sql file in the package. (Ignore db/upgrades folder for new installations)
63+
2. Create a new database for SBOanalytics (or use an existing database, all tables have sbo_ prefix)
64+
3. Run db/db-for-new-installations.sql
5965

66+
#### Database updates for upgrades
67+
- To apply database updates, review the files in db/upgrades/ folder in the release package. Run .sql files with names after your old version.
68+
For example if your old version was 2025.07.25.0001 you need to run all files with names after 20250725*.sql in db/upgrades folder.
69+
You MUST run sql files in alphabetical order.
70+
71+
#### .htaccess and environment variables
6072
Please review webapp/DocumentRoot/.htaccess before deployments and upgrades. You can define the required environment variables in VirtualHost settings,
6173
e.g /etc/apache2/sites-enabled/yoursite.conf, and leave .htaccess as is.
6274
If you set environment variables in the .htaccess file then you will need to manually apply your changes during upgrades.
@@ -74,7 +86,8 @@ defined by SBO_AUTH_SINGLE_USER and SBO_AUTH_SINGLE_PWD environment variables.
7486
- SBO_DB_PASSWORD mysql password
7587
- SBO_AUTH_SINGLE_USER username for SBO_AUTH_TYPE single
7688
- SBO_AUTH_SINGLE_PWD password for SBO_AUTH_TYPE single
89+
- SBO_ADMIN_SECRET secret required for accessing the settings page
7790

78-
Always review https://github.com/SBOsoft/SBOanalytics/blob/main/webapp/DocumentRoot/.htaccess for latest updates to configuration options.
79-
The above list may not be exhaustive.
91+
Always review https://github.com/SBOsoft/SBOanalytics/blob/main/webapp/DocumentRoot/.htaccess for latest updates to configuration options
92+
and additional information.
8093

containers/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ services:
3131
volumes:
3232
- ./mysql/my.cnf:/etc/mysql/my.cnf # Persistent storage for MySQL data
3333
- ./mysql_data:/var/lib/mysql # Persistent storage for MySQL data
34-
- ../db/:/docker-entrypoint-initdb.d #init scripts
34+
- ../db/upgrades/:/docker-entrypoint-initdb.d #init scripts
3535
#restart: no # change to always or unless-stopped for non-dev envs
3636
networks:
3737
- sboanalytics-network

db/db-for-new-installations.sql

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
--Run the following if you didn't already create a database
3+
4+
CREATE DATABASE sboanalytics
5+
CHARACTER SET utf8mb4
6+
COLLATE utf8mb4_unicode_ci;
7+
8+
USE sboanalytics;
9+
*/
10+
11+
12+
CREATE TABLE sbo_domains (
13+
domain_id INT AUTO_INCREMENT,
14+
domain_name VARCHAR(255) NOT NULL,
15+
description VARCHAR(255) null,
16+
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
17+
PRIMARY KEY (domain_name),
18+
UNIQUE KEY sbo_domains_id (domain_id)
19+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
20+
21+
22+
CREATE TABLE sbo_users (
23+
user_id INT AUTO_INCREMENT,
24+
email VARCHAR(255) NOT NULL,
25+
password_hash VARCHAR(255) NOT NULL,
26+
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
27+
PRIMARY KEY (email),
28+
UNIQUE KEY sbo_users_id (user_id)
29+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
30+
31+
32+
CREATE TABLE sbo_log_files (
33+
file_id int not null AUTO_INCREMENT,
34+
domain_id int not null,
35+
host_name VARCHAR(100) NOT NULL,
36+
file_path VARCHAR(500) NOT NULL,
37+
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
38+
PRIMARY KEY (domain_id, host_name, file_path),
39+
UNIQUE KEY sbo_log_files_file_id (file_id)
40+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
41+
42+
43+
CREATE TABLE sbo_metrics (
44+
domain_id int not null,
45+
metric_type int not null,
46+
key_value varchar(100) not null,
47+
time_window bigint not null,
48+
metric_value bigint not null,
49+
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
50+
PRIMARY KEY (domain_id, metric_type, time_window, key_value),
51+
KEY sbo_metrics_time (domain_id, time_window, metric_type, key_value, metric_value)
52+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
53+
54+
55+
56+
CREATE TABLE sbo_rawlogs (
57+
domain_id int not null,
58+
host_id int not null,
59+
request_ts datetime not null,
60+
client_ip varbinary(16) default null,
61+
remote_user varchar(100) not null,
62+
http_method varchar(20) not null,
63+
path3 varchar(100) not null,
64+
request_uri varchar(100) not null,
65+
http_status int not null,
66+
bytes_sent int not null,
67+
referer varchar(100) default null,
68+
is_malicious tinyint not null default 0,
69+
ua_string varchar(100) default null,
70+
ua_os varchar(20) default null,
71+
ua_family varchar(20) default null,
72+
ua_device_type varchar(20) default null,
73+
ua_is_human varchar(20) default null,
74+
ua_intent varchar(20) default null,
75+
76+
KEY sbo_rawlogs_method (domain_id, request_ts, http_method),
77+
KEY sbo_rawlogs_status (domain_id, request_ts, http_status),
78+
KEY sbo_rawlogs_referer (domain_id, request_ts, referer),
79+
KEY sbo_rawlogs_ua_os (domain_id, request_ts, ua_os),
80+
KEY sbo_rawlogs_ua_family (domain_id, request_ts, ua_family),
81+
KEY sbo_rawlogs_ua_device_type (domain_id, request_ts, ua_device_type),
82+
KEY sbo_rawlogs_ua_is_human (domain_id, request_ts, ua_is_human),
83+
KEY sbo_rawlogs_ua_intent (domain_id, request_ts, ua_intent),
84+
KEY sbo_rawlogs_client_ip (domain_id, request_ts, client_ip),
85+
KEY sbo_rawlogs_path3 (domain_id, request_ts, path3)
86+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
87+
88+
89+
ALTER TABLE sbo_domains ADD COLUMN timeWindowSizeMinutes int not null default 10;
90+
91+
92+
93+
94+
CREATE TABLE sbo_os_metrics(
95+
host_id int not null,
96+
metrics_ts datetime not null,
97+
up_duration_minutes int not null default 0,
98+
users int not null default 0,
99+
load_average1 double not null default 0,
100+
load_average5 double not null default 0,
101+
load_average15 double not null default 0,
102+
103+
swap_use bigint not null default 0,
104+
cache_use bigint not null default 0,
105+
memory_use bigint not null default 0,
106+
memory_free bigint not null default 0,
107+
108+
PRIMARY KEY sbo_rawlogs_method (host_id, metrics_ts)
109+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
110+
111+
112+
CREATE TABLE sbo_hosts(
113+
host_id int not null AUTO_INCREMENT,
114+
host_name VARCHAR(255) NOT NULL,
115+
description VARCHAR(255) null,
116+
created DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
117+
PRIMARY KEY (host_id),
118+
UNIQUE KEY sbo_hosts_name (host_name)
119+
) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
120+
121+
122+
ALTER TABLE sbo_os_metrics ADD COLUMN memory_available bigint not null default 0;
123+
124+
/* end of 2025.08.10 up to this point */
File renamed without changes.
File renamed without changes.
File renamed without changes.

webapp/DocumentRoot/.htaccess

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ RewriteCond %{REQUEST_URI} /version.txt$
4848
RewriteRule version.txt - [R=404,L]
4949

5050

51+
#return 404 for all .sql files
52+
RewriteRule \.sql$ - [R=404,NC,L]
53+
5154
#You can set environment variables here or in virtual host config
5255

5356
#Authentication type. REQUIRED. Supported values: none, single (more to be added later)

0 commit comments

Comments
 (0)