Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ To add new tests, crib exiting files in the `tests` directory.
# Deployment using docker image

Set the environment variables for the go image
* `PANOPTICON_DB_DRIVER` (eg, mysql or sqlite)
* `PANOPTICON_DB` (go mysql connection string or filename for sqlite)
* `PANOPTICON_DB_DRIVER` (eg, mysql, sqlite or postgres)
* `PANOPTICON_DB` (go mysql/postgres connection string or filename for sqlite)
* `PANOPTICON_PORT` (http port to expose panopticon on)

Set the environment variables for the python image
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.18

require (
github.com/go-sql-driver/mysql v1.6.0
github.com/lib/pq v1.10.9
github.com/mattn/go-sqlite3 v1.14.12
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
7 changes: 6 additions & 1 deletion homeserver_dendrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ type ReportStatsDendrite struct {

func createTableDendrite(db *sql.DB) error {
autoincrement := "AUTOINCREMENT"
primaryKeyType := "INTEGER"

if *dbDriver == "mysql" {
autoincrement = "AUTO_INCREMENT"
} else if *dbDriver == "postgres" {
autoincrement = ""
primaryKeyType = "SERIAL"
}
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS dendrite_stats(
id INTEGER NOT NULL PRIMARY KEY ` + autoincrement + ` ,
id ` + primaryKeyType + ` NOT NULL PRIMARY KEY ` + autoincrement + ` ,
homeserver VARCHAR(256),
local_timestamp BIGINT,
remote_timestamp BIGINT,
Expand Down
11 changes: 9 additions & 2 deletions homeserver_synapse.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ type ReportStatsSynapse struct {

func createTableSynapse(db *sql.DB) error {
autoincrement := "AUTOINCREMENT"
primaryKeyType := "INTEGER"
doubleType := "DOUBLE"

if *dbDriver == "mysql" {
autoincrement = "AUTO_INCREMENT"
} else if *dbDriver == "postgres" {
autoincrement = ""
primaryKeyType = "SERIAL"
doubleType = "DOUBLE PRECISION"
}
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS stats(
id INTEGER NOT NULL PRIMARY KEY ` + autoincrement + ` ,
id ` + primaryKeyType + ` NOT NULL PRIMARY KEY ` + autoincrement + ` ,
homeserver VARCHAR(256),
local_timestamp BIGINT,
remote_timestamp BIGINT,
Expand Down Expand Up @@ -65,7 +72,7 @@ func createTableSynapse(db *sql.DB) error {
r30v2_users_web BIGINT,
cpu_average BIGINT,
memory_rss BIGINT,
cache_factor DOUBLE,
cache_factor ` + doubleType + `,
event_cache_size BIGINT,
user_agent TEXT,
daily_user_type_native BIGINT,
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// panopticon collects statistics posted to it, and records them in a sqlite3 or mysql database.
// panopticon collects statistics posted to it, and records them in a sqlite3, mysql or postgres database.
package main

import (
Expand All @@ -32,6 +32,7 @@ import (

_ "github.com/go-sql-driver/mysql"
_ "github.com/mattn/go-sqlite3"
_ "github.com/lib/pq"
)

var (
Expand Down