本文共 4264 字,大约阅读时间需要 14 分钟。
支持三种功能:
指定Date和UID,将打印指定日期指定用户的share信息到stdout
指定Date但未指定UID,读取指定日期sharelog,统计数据并写入数据库
如果Date和UID均未指定,将监听文件变化,读取share并统计数据,每15秒写入数据库
slparser -c slparser.cfg -l log_dirslparser -c slparser.cfg -l log_dir2 -d 20160830slparser -c slparser.cfg -l log_dir3 -d 20160830 -u puid#-c指定slparser配置文件#-l指定日志目录#-d指定日期#-u指定PUID(即userId),userId为0时dump all, >0时仅输出指定userId的sharelogslparser.cfg配置文件slparserhttpd = {#指定IP和端口ip = "0.0.0.0";port = 8081;#每间隔15s写库flush_db_interval = 15;};#指定sharelog文件路径sharelog = {data_dir = "/data/sharelog";};#数据库配置,表为table.stats_xxxxpooldb = {host = "";port = 3306;username = "dbusername";password = "dbpassword";dbname = "";};slparser流程图![slparser_](https://yqfile.alicdn.com/4b395d772803277d45ad56e58758b34bafff8d81.png)bpool_local_stats_db数据库结构bpool_local_stats_db.txtDROP TABLE IF EXISTS `stats_pool_day`;CREATE TABLE `stats_pool_day` (`day` int(11) NOT NULL,`share_accept` bigint(20) NOT NULL DEFAULT '0',`share_reject` bigint(20) NOT NULL DEFAULT '0',`reject_rate` double NOT NULL DEFAULT '0',`score` decimal(35,25) NOT NULL DEFAULT '0.0000000000000000000000000',`earn` bigint(20) NOT NULL DEFAULT '0',`lucky` double NOT NULL DEFAULT '0',`created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,UNIQUE KEY `day` (`day`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;DROP TABLE IF EXISTS `stats_pool_hour`;CREATE TABLE `stats_pool_hour` (`hour` int(11) NOT NULL,`share_accept` bigint(20) NOT NULL DEFAULT '0',`share_reject` bigint(20) NOT NULL DEFAULT '0',`reject_rate` double NOT NULL DEFAULT '0',`score` decimal(35,25) NOT NULL DEFAULT '0.0000000000000000000000000',`earn` bigint(20) NOT NULL DEFAULT '0',`created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,UNIQUE KEY `hour` (`hour`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;DROP TABLE IF EXISTS `stats_users_day`;CREATE TABLE `stats_users_day` (`puid` int(11) NOT NULL,`day` int(11) NOT NULL,`share_accept` bigint(20) NOT NULL DEFAULT '0',`share_reject` bigint(20) NOT NULL DEFAULT '0',`reject_rate` double NOT NULL DEFAULT '0',`score` decimal(35,25) NOT NULL DEFAULT '0.0000000000000000000000000',`earn` bigint(20) NOT NULL DEFAULT '0',`created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,UNIQUE KEY `puid_day` (`puid`,`day`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;DROP TABLE IF EXISTS `stats_users_hour`;CREATE TABLE `stats_users_hour` (`puid` int(11) NOT NULL,`hour` int(11) NOT NULL,`share_accept` bigint(20) NOT NULL DEFAULT '0',`share_reject` bigint(20) NOT NULL DEFAULT '0',`reject_rate` double NOT NULL DEFAULT '0',`score` decimal(35,25) NOT NULL DEFAULT '0.0000000000000000000000000',`earn` bigint(20) NOT NULL DEFAULT '0',`created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,UNIQUE KEY `puid_hour` (`puid`,`hour`),KEY `hour` (`hour`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;DROP TABLE IF EXISTS `stats_workers_day`;CREATE TABLE `stats_workers_day` (`puid` int(11) NOT NULL,`worker_id` bigint(20) NOT NULL,`day` int(11) NOT NULL,`share_accept` bigint(20) NOT NULL DEFAULT '0',`share_reject` bigint(20) NOT NULL DEFAULT '0',`reject_rate` double NOT NULL DEFAULT '0',`score` decimal(35,25) NOT NULL DEFAULT '0.0000000000000000000000000',`earn` bigint(20) NOT NULL DEFAULT '0',`created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,UNIQUE KEY `puid_worker_id_day` (`puid`,`worker_id`,`day`),KEY `day` (`day`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;DROP TABLE IF EXISTS `stats_workers_hour`;CREATE TABLE `stats_workers_hour` (`puid` int(11) NOT NULL,`worker_id` bigint(20) NOT NULL,`hour` int(11) NOT NULL,`share_accept` bigint(20) NOT NULL DEFAULT '0',`share_reject` bigint(20) NOT NULL DEFAULT '0',`reject_rate` double NOT NULL DEFAULT '0',`score` decimal(35,25) NOT NULL DEFAULT '0.0000000000000000000000000',`earn` bigint(20) NOT NULL DEFAULT '0',`created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL,UNIQUE KEY `puid_worker_id_hour` (`puid`,`worker_id`,`hour`),KEY `hour` (`hour`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
转载地址:http://ihdha.baihongyu.com/