ngrinder支持mysql完整版

思路

1、到官网下ngrinder的源码,我这里用的3.4.2的版本
2、安装mysql
3、创建数据结构
4、修改源码,打成war包
5、部署到环境上去

步骤

1、官网下载源码地址

https://github.com/naver/ngrinder/archive/ngrinder-3.4.2-20180830.zip
别的版本的地址:
https://github.com/naver/ngrinder/releases

2、安装mysql,这个就根据实际情况,自己找安装包吧

3、创建数据结构

我这里有整理好的,已测没有问题。在这之前用了源码里的H2数据库结构,结果少了很多字段,这段编译起来,也颇废时间。然后有找到定义数据库字段的代码,尤其是perfTest的字段和源码里H2的很不一样,没有去找原因,是因为作者没更新还是因为本来H2和mysql就不一样没有做深究。在这里分享一下:
在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
   
	<changeSet author="initialDB" id="2" dbms="mysql">
        <comment>DB initialization.</comment>
	    <sql>
			create table if not exists AGENT (
		        id bigint auto_increment unique,
		        approved char(1) not null,
		        hostName varchar(255),
		        ip varchar(255),
		        region varchar(255),
			    state varchar(20),
			    port int default 0,
			    system_stat varchar(1000),
			    version varchar(256) default '',
		        primary key (id)
		    );

		    create table if not exists NUSER (
		        id bigint auto_increment unique,
		        created_date timestamp,
		        last_modified_date timestamp,
		        authentication_provider_class varchar(255),
		        description varchar(255),
		        email varchar(255),
		        enabled char(1) not null,
		        is_external char(1),
		        mobile_phone varchar(255),
		        password varchar(255),
		        role_name varchar(255) not null,
		        timeZone varchar(255),
		        user_id varchar(255) not null unique,
		        user_language varchar(255),
		        user_name varchar(255),
		        created_user bigint,
		        last_modified_user bigint,
		        primary key (id)
		    );
		
		    create table if not exists PERF_TEST (
		        id bigint auto_increment unique,
		        created_date timestamp,
		        last_modified_date timestamp,
		        agent_count integer,
		        description longtext,
		        distribution_path varchar(255),
		        duration bigint,
		        errors bigint,
		        finish_time timestamp,
		        ignore_sample_count int,
			    ramp_up_init_count int,
			    ramp_up_init_sleep_time int,
		        last_progress_message longtext,
		        mean_test_time double,
		        peak_tps double,
		        port int,
			    ramp_up_step int,
			    ramp_up_increment_interval int,
		        processes int,
		        progress_message longtext,
		        run_count int,
		        scheduled_time timestamp,
		        script_name varchar(255),
		        script_revision bigint,
		        send_mail char(1),
		        start_time timestamp,
		        status varchar(255),
		        stop_request char(1),
		        tag_string varchar(255),
		        target_hosts varchar(255),
		        test_comment longtext,
		        test_error_cause varchar(255),
		        name varchar(255),
		        test_time_standard_deviation double,
		        tests bigint,
		        threads int,
		        threshold varchar(255),
		        tps double,
		        use_rampup char(1),
		        vuser_per_agent int,
		        created_user bigint,
		        last_modified_user bigint,
			    region varchar(255),
			    safe_distribution char(1) default 'F',
				agent_stat longtext,
				running_sample longtext,
			    monitor_stat longtext,
			    sampling_interval int default 1,
			    param varchar(256) default '',
			    ramp_up_type varchar(10) default 'PROCESS',
			    primary key (id)
		    );
			create table if not exists SHARED_USER (
			owner_id  bigint not null,
			follow_id bigint not null,
			primary key (owner_id, follow_id)
			);
		    create table if not exists PERF_TEST_TAG (
		        perf_test_id bigint not null,
		        tag_id bigint not null,
		        primary key (perf_test_id, tag_id)
		    );
		
		    create table if not exists TAG (
		        id bigint auto_increment unique,
		        created_date timestamp,
		        last_modified_date timestamp,
		        tagValue varchar(255),
		        created_user bigint,
		        last_modified_user bigint,
		        primary key (id)
		    );
		
		    create table if not exists system_monitor (
		        id bigint auto_increment unique,
		        collect_time bigint,
		        cpu_used_percentage double,
		        crtime varchar(255),
		        free_memory bigint,
		        idle_cpu_value double,
		        ip varchar(255),
		        monitor_key varchar(255),
		        load_avg_1 double,
		        load_avg_15 double,
		        load_avg_5 double,
		        message varchar(255),
		        port integer not null,
		        system varchar(255),
		        total_cpu_value double,
		        total_memory bigint,
		        primary key (id)
		    );
		
		    create index last_modified_user_index_NUSER on NUSER (last_modified_user);
		
		    create index created_user_index on NUSER (created_user);
		
		    alter table NUSER 
		        add constraint FK4730D19BAFCD683 
		        foreign key (created_user) 
		        references NUSER;
		
		    alter table NUSER 
		        add constraint FK4730D191B90BD59 
		        foreign key (last_modified_user) 
		        references NUSER;
		
		    create index last_modified_user_index_PERF_TEST on PERF_TEST (last_modified_user);
		
		    create index created_user_index_PERF_TEST on PERF_TEST (created_user);
		
		    create index scheduled_time_index on PERF_TEST (scheduled_time);
		
		    alter table PERF_TEST 
		        add constraint FKC3A7F428BAFCD683 
		        foreign key (created_user) 
		        references NUSER;
		
		    alter table PERF_TEST 
		        add constraint FKC3A7F4281B90BD59 
		        foreign key (last_modified_user) 
		        references NUSER;
		
		    alter table PERF_TEST_TAG 
		        add constraint FK8EE12E3AD3184A3 
		        foreign key (perf_test_id) 
		        references PERF_TEST;
		
		    alter table PERF_TEST_TAG 
		        add constraint FK8EE12E317FA08C4 
		        foreign key (tag_id) 
		        references TAG;
		
		    create index last_modified_user_index_TAG on TAG (last_modified_user);
		
		    create index created_user_index_TAG on TAG (created_user);
		
		    alter table TAG 
		        add constraint FK1437ABAFCD683 
		        foreign key (created_user) 
		        references NUSER;
		
		    alter table TAG 
		        add constraint FK1437A1B90BD59 
		        foreign key (last_modified_user) 
		        references NUSER;
		
		    create index monitor_key_index on system_monitor (monitor_key);
		
		    create index collect_time_index on system_monitor (collect_time);
		
		    create index ip_index on system_monitor (ip);
						   
    			
	    </sql>
    </changeSet>
</databaseChangeLog>

4、修改源码

1、源码根目录下修改pom文件,添加mysql驱动

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.31</version>
		</dependency>

2、源码中以下目录添加mysql项
在这里插入图片描述

	/**
	 * mysql
	 */
	mysql(com.mysql.jdbc.Driver.class,MySQLDialect.class,"jdbc:mysql://%s?characterEncoding=utf8"){
     	@Override
		protected void setupVariants(BasicDataSource dataSource,PropertiesWrapper databaseProperties){
     		dataSource.setUrl(String.format(getUrlTemplate(),databaseProperties.getProperty(DatabaseConfig.PROP_DATABASE_URL)));
     		dataSource.setUsername(databaseProperties.getProperty(DatabaseConfig.PROP_DATABASE_USERNAME));
     		dataSource.setPassword(databaseProperties.getProperty(DatabaseConfig.PROP_DATABASE_PASSWORD));
		 }

	 };

注意:这里太久没碰java了,踩了个坑,一个枚举后应该是逗号,如果直接写分号,它就认为枚举已结束,报错
在这里插入图片描述
3、配置数据库连接,按照以下路径找到database.conf修改
在这里插入图片描述

# H2 / cubrid can be set
database.type=mysql
#database.type=cubrid

# for cubrid. You should configure the following.
# database.url=localhost:33000:ngrinder
database.url=ip:3306/ngrinder

# for H2 remote connection, You should configure like followings.
# You can see how to run the H2 DB server by yourself in http://www.h2database.com/html/tutorial.html#using_server
# If this is not set, ngrinder will create the embedded DB.
# database.url=tcp://h2_server_ip:h2_server_port:ngrinder

# if you want to use HA mode in cubrid, you should enable following
# database.url_option=&althosts=secondary_ip:port

# you should provide id / password who has a enough permission to create tables in the given db.
database.username=
database.password=

4、打成war包,在根目录下执行

mvn clean install -Dmaven.test.skip

5、部署到环境中去

https://github.com/naver/ngrinder/wiki/Installation-Guide

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值