发布网友 发布时间:2022-04-24 01:14
共3个回答
懂视网 时间:2022-05-06 23:22
关于关系表的设计归根结底有两个方面。 窄表:log_ytt mysql show create table log_ytt; +-------------+--------------------------------------------------------------------------------------------------------------------------------------------
关于关系表的设计归根结底有两个方面。接下来,我们要检索所有IDS的平均时间。 有以下两种方式: mysql> select sec_to_time(avg(timestampdiff(second,a.times,b.times))) as 'running' -> from -> (select ids,min(log_time) as times from log_ytt where 1 group by ids ) as a, -> (select ids,max(log_time) as times from log_ytt where 1 group by ids) as b where a.ids = b.ids; +---------------+ | running | +---------------+ | 05:27:08.8333 | +---------------+ 1 row in set (0.00 sec)
第二,虽然对表进行了最少的访问,但是也有一次GROUP BY 操作。也没办法,表设计如此。 mysql> SELECT SEC_TO_TIME(AVG(times)) AS 'Running' FROM -> ( -> SELECT TIMESTAMPDIFF(SECOND,MIN(log_time),MAX(log_time)) AS times FROM log_ytt GROUP BY ids -> ) AS T; +---------------+ | Running | +---------------+ | 05:27:08.8333 | +---------------+ 1 row in set (0.00 sec)
宽表:log_ytt_horizontal. mysql> show create table log_ytt_horizontal; +------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | log_ytt_horizontal | CREATE TABLE `log_ytt_horizontal` ( `ids` bigint(20) NOT NULL, `start_time` datetime DEFAULT NULL, `end_time` datetime DEFAULT NULL, PRIMARY KEY (`ids`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
表记录数: mysql> select * from log_ytt_horizontal; +------------+---------------------+---------------------+ | ids | start_time | end_time | +------------+---------------------+---------------------+ | 5130000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:34 | | 5220000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:45 | | 5310000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:33 | | 5400000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:53 | | 5490000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:55 | | 5580000001 | 2014-05-20 21:56:42 | 2014-05-21 03:20:24 | | 5670000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:58 | | 5760000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:07 | | 5850000001 | 2014-05-20 21:56:42 | 2014-05-21 03:20:18 | | 5940000001 | 2014-05-20 21:56:42 | 2014-05-21 03:20:00 | | 6030000001 | 2014-05-20 21:56:42 | 2014-05-21 03:20:00 | | 6120000001 | 2014-05-20 21:56:42 | 2014-05-21 03:20:09 | | 6210000001 | 2014-05-20 21:56:42 | 2014-05-21 03:25:45 | | 6300000001 | 2014-05-20 21:56:42 | 2014-05-21 03:28:13 | | 6390000001 | 2014-05-20 21:56:42 | 2014-05-21 03:25:37 | | 80000001 | 2014-05-20 21:56:42 | 2014-05-21 03:25:05 | | 6570000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:34 | | 6660000001 | 2014-05-20 21:56:42 | 2014-05-21 03:28:07 | | 6750000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:17 | | 6840000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:17 | | 6930000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:59 | | 7020000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:32 | | 7110000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:46 | | 7200000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:45 | | 7290000001 | 2014-05-20 21:56:42 | 2014-05-21 03:20:02 | | 7380000001 | 2014-05-20 21:56:42 | 2014-05-21 03:19:48 | | 7470000001 | 2014-05-20 21:56:42 | 2014-05-21 03:26:14 | | 7560000001 | 2014-05-20 21:56:42 | 2014-05-21 03:27:45 | | 7650000001 | 2014-05-20 21:56:42 | 2014-05-21 03:28:37 | | 7740000001 | 2014-05-20 21:56:42 | 2014-05-21 03:28:26 | +------------+---------------------+---------------------+ 30 rows in set (0.00 sec)
如果对这种稍微冗余一些的表来进行查询,那么对表的访问以及CPU的资源占用都达到了最低。 mysql> select sec_to_time(avg(timestampdiff(second,start_time,end_time))) as 'Running' from log_ytt_horizontal; +---------------+ | Running | +---------------+ | 05:27:08.8333 | +---------------+ 1 row in set (0.00 sec)
热心网友 时间:2022-05-06 20:30
日志分2种,
一种是存DB的,在db里存各种操作记录,访问记录等等,是存在许多表里的记录。
另一种是存文件的,记录的是服务器输出的log信息。
看你有统计数据的需求应该去分析DB里的日志表,而不是去分析日志文件。你把需求理解错了
热心网友 时间:2022-05-06 21:48
Java提供了很多很好的日志记录和分析工具, 如Jakarta、log4j。
Jakarta Commons Logging (JCL)提供的是一个日志(Log)接口(interface),同时兼顾轻量级和不依赖于具体的日志实现工具。它提供给中间件/日志工具开发者一个简单的日志操作抽象,允许程序开发人员使用不同的具体日志实现工具。了解包里情况。