mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Start to add sqlite db - we'll probably use postgres, but I wanted something for testing.
This commit is contained in:
31
src/rust/Cargo.lock
generated
31
src/rust/Cargo.lock
generated
@@ -1332,6 +1332,7 @@ dependencies = [
|
||||
"lqos_bus",
|
||||
"serde",
|
||||
"serde_cbor",
|
||||
"sqlite",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@@ -2359,6 +2360,36 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dccf47db1b41fa1573ed27ccf5e08e3ca771cb994f776668c5ebda893b248fc"
|
||||
|
||||
[[package]]
|
||||
name = "sqlite"
|
||||
version = "0.30.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b1908664131c21a38e5b531344d52a196ec338af5bf44f7fa2c83d539e9561d"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"sqlite3-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite3-src"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1815a7a02c996eb8e5c64f61fcb6fd9b12e593ce265c512c5853b2513635691"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sqlite3-sys"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d47c99824fc55360ba00caf28de0b8a0458369b832e016a64c13af0ad9fbb9ee"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"sqlite3-src",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stable-pattern"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -11,3 +11,4 @@ log = "0"
|
||||
lqos_bus = { path = "../lqos_bus" }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_cbor = "0" # For RFC8949/7409 format C binary objects
|
||||
sqlite = "0.30.4"
|
||||
|
||||
59
src/rust/lqos_anonymous_stats_server/src/db.rs
Normal file
59
src/rust/lqos_anonymous_stats_server/src/db.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
use std::path::Path;
|
||||
const DBPATH: &str = "anonymous.sqlite";
|
||||
|
||||
const SETUP_QUERY: &str =
|
||||
"CREATE TABLE submissions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
date TEXT,
|
||||
node_id TEXT,
|
||||
ip_address TEXT,
|
||||
git_hash TEXT,
|
||||
using_xdp_bridge INTEGER,
|
||||
on_a_stick INTEGER,
|
||||
total_memory INTEGER,
|
||||
available_memory INTEGER,
|
||||
kernel_version TEXT,
|
||||
distro TEXT,
|
||||
usable_cores INTEGER,
|
||||
cpu_brand TEXT,
|
||||
cpu_vendor TEXT,
|
||||
cpu_frequency INTEGER,
|
||||
sqm TEXT,
|
||||
monitor_mode INTEGER,
|
||||
capacity_down INTEGER,
|
||||
capacity_up INTEGER,
|
||||
generated_pdn_down INTEGER,
|
||||
generated_pdn_up INTEGER,
|
||||
shaped_device_count INTEGER,
|
||||
net_json_len INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE nics (
|
||||
id INTEGER PRIMARY KEY,
|
||||
parent INTEGER,
|
||||
description TEXT,
|
||||
product TEXT,
|
||||
vendor TEXT,
|
||||
clock TEXT,
|
||||
capacity TEXT,
|
||||
FOREIGN KEY(parent)
|
||||
REFERENCES submissions (id)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE NO ACTION
|
||||
);
|
||||
";
|
||||
|
||||
pub fn create_if_not_exist() {
|
||||
let path = Path::new(DBPATH);
|
||||
if !path.exists() {
|
||||
if let Ok(cn) = sqlite::open(DBPATH) {
|
||||
let result = cn.execute(SETUP_QUERY);
|
||||
if let Err(e) = result {
|
||||
log::error!("{e:?}");
|
||||
panic!("Failed to create database");
|
||||
}
|
||||
} else {
|
||||
panic!("Unable to create database");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
mod stats_server;
|
||||
mod db;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
@@ -8,6 +9,8 @@ async fn main() -> anyhow::Result<()> {
|
||||
.filter_or(env_logger::DEFAULT_FILTER_ENV, "warn"),
|
||||
);
|
||||
|
||||
db::create_if_not_exist();
|
||||
|
||||
let _ = stats_server::gather_stats().await;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user