From fcccf3b9dbf7ed07d29c3536f9422cfb9b67c055 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Tue, 24 Nov 2020 16:28:03 +0100 Subject: [PATCH] db: update init scripts due to removed stats tables in MySQL While at it, improve name to distinguish from influxdb. Signed-off-by: Adrian Schmutzler --- ffmap/db/{init_db.py => init_mysql.py} | 1 - ffmap/db/routers.py | 164 ------------------------- ffmap/db/stats.py | 69 ----------- 3 files changed, 234 deletions(-) rename ffmap/db/{init_db.py => init_mysql.py} (84%) delete mode 100755 ffmap/db/stats.py diff --git a/ffmap/db/init_db.py b/ffmap/db/init_mysql.py similarity index 84% rename from ffmap/db/init_db.py rename to ffmap/db/init_mysql.py index b049a2a..599864f 100755 --- a/ffmap/db/init_db.py +++ b/ffmap/db/init_mysql.py @@ -2,6 +2,5 @@ import routers import hoods -import stats import gws import users diff --git a/ffmap/db/routers.py b/ffmap/db/routers.py index 20774e8..e15223e 100755 --- a/ffmap/db/routers.py +++ b/ffmap/db/routers.py @@ -32,24 +32,6 @@ mysql.execute(""" ADD PRIMARY KEY (`mac`) """) -mysql.execute(""" - CREATE TABLE `netifs` ( - `id` smallint(6) UNSIGNED NOT NULL, - `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `netifs` - ADD PRIMARY KEY (`id`), - ADD UNIQUE KEY `name` (`name`) -""") - -mysql.execute(""" - ALTER TABLE `netifs` - MODIFY `id` smallint(6) UNSIGNED NOT NULL AUTO_INCREMENT -""") - mysql.execute(""" CREATE TABLE `router` ( `id` mediumint(8) UNSIGNED NOT NULL, @@ -209,152 +191,6 @@ mysql.execute(""" ADD KEY `mac` (`mac`) """) -mysql.execute(""" - CREATE TABLE `router_stats` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `sys_proctot` smallint(6) NOT NULL, - `sys_procrun` smallint(6) NOT NULL, - `sys_memcache` int(11) NOT NULL, - `sys_membuff` int(11) NOT NULL, - `sys_memfree` int(11) NOT NULL, - `loadavg` float NOT NULL, - `clients` smallint(6) NOT NULL, - `clients_eth` smallint(6) DEFAULT NULL, - `clients_w2` smallint(6) DEFAULT NULL, - `clients_w5` smallint(6) DEFAULT NULL, - `airtime_w2` float DEFAULT NULL, - `airtime_w5` float DEFAULT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats` - ADD PRIMARY KEY (`time`,`router`), - ADD KEY `router` (`router`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_gw` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `mac` bigint(20) UNSIGNED NOT NULL, - `quality` float NOT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_gw` - ADD PRIMARY KEY (`time`,`router`,`mac`), - ADD KEY `router` (`router`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_neighbor` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `mac` bigint(20) UNSIGNED NOT NULL, - `quality` float NOT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_neighbor` - ADD PRIMARY KEY (`time`,`router`,`mac`), - ADD KEY `router` (`router`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_netif` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `netif` smallint(6) UNSIGNED NOT NULL, - `rx` int(10) UNSIGNED NOT NULL, - `tx` int(10) UNSIGNED NOT NULL, - `deletebit` tinyint(1) NOT NULL DEFAULT '0' - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_netif` - ADD PRIMARY KEY (`time`,`router`,`netif`), - ADD KEY `router` (`router`), - ADD KEY `deletebit` (`deletebit`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_old` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `sys_proctot` smallint(6) NOT NULL, - `sys_procrun` smallint(6) NOT NULL, - `sys_memcache` int(11) NOT NULL, - `sys_membuff` int(11) NOT NULL, - `sys_memfree` int(11) NOT NULL, - `loadavg` float NOT NULL, - `clients` smallint(6) NOT NULL, - `clients_eth` smallint(6) DEFAULT NULL, - `clients_w2` smallint(6) DEFAULT NULL, - `clients_w5` smallint(6) DEFAULT NULL, - `airtime_w2` float DEFAULT NULL, - `airtime_w5` float DEFAULT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_old` - ADD PRIMARY KEY (`time`,`router`), - ADD KEY `router` (`router`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_old_gw` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `mac` bigint(20) UNSIGNED NOT NULL, - `quality` float NOT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_old_gw` - ADD PRIMARY KEY (`time`,`router`,`mac`), - ADD KEY `router` (`router`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_old_neighbor` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `mac` bigint(20) UNSIGNED NOT NULL, - `quality` float NOT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_old_neighbor` - ADD PRIMARY KEY (`time`,`router`,`mac`), - ADD KEY `router` (`router`) -""") - -mysql.execute(""" - CREATE TABLE `router_stats_old_netif` ( - `time` int(11) NOT NULL, - `router` mediumint(8) UNSIGNED NOT NULL, - `netif` smallint(6) UNSIGNED NOT NULL, - `rx` int(10) UNSIGNED NOT NULL, - `tx` int(10) UNSIGNED NOT NULL, - `deletebit` tinyint(1) NOT NULL DEFAULT '0' - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `router_stats_old_netif` - ADD PRIMARY KEY (`time`,`router`,`netif`), - ADD KEY `router` (`router`), - ADD KEY `deletebit` (`deletebit`) -""") - mysql.commit() mysql.close() diff --git a/ffmap/db/stats.py b/ffmap/db/stats.py deleted file mode 100755 index f1112e3..0000000 --- a/ffmap/db/stats.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python3 - -import os -import sys -sys.path.insert(0, os.path.abspath(os.path.dirname(__file__) + '/' + '../..')) - -from ffmap.mysqltools import FreifunkMySQL - -mysql = FreifunkMySQL() - -mysql.execute(""" - CREATE TABLE `stats_global` ( - `time` int(11) NOT NULL, - `clients` mediumint(9) NOT NULL, - `online` smallint(6) NOT NULL, - `offline` smallint(6) NOT NULL, - `unknown` smallint(6) NOT NULL, - `orphaned` smallint(6) NOT NULL, - `rx` int(10) UNSIGNED DEFAULT NULL, - `tx` int(10) UNSIGNED DEFAULT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `stats_global` - ADD PRIMARY KEY (`time`) -""") - -mysql.execute(""" - CREATE TABLE `stats_gw` ( - `time` int(11) NOT NULL, - `mac` bigint(20) UNSIGNED NOT NULL, - `clients` mediumint(9) NOT NULL, - `online` smallint(6) NOT NULL, - `offline` smallint(6) NOT NULL, - `unknown` smallint(6) NOT NULL, - `orphaned` smallint(6) NOT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `stats_gw` - ADD PRIMARY KEY (`time`,`mac`), - ADD KEY `mac` (`mac`) -""") - -mysql.execute(""" - CREATE TABLE `stats_hood` ( - `time` int(11) NOT NULL, - `hood` smallint(5) UNSIGNED NOT NULL, - `clients` mediumint(9) NOT NULL, - `online` smallint(6) NOT NULL, - `offline` smallint(6) NOT NULL, - `unknown` smallint(6) NOT NULL, - `orphaned` smallint(6) NOT NULL, - `rx` int(10) UNSIGNED DEFAULT NULL, - `tx` int(10) UNSIGNED DEFAULT NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci -""") - -mysql.execute(""" - ALTER TABLE `stats_hood` - ADD PRIMARY KEY (`time`,`hood`), - ADD KEY `hood` (`hood`) -""") - -mysql.commit() - -mysql.close()