├── Makefile
├── README.md
├── assistthread.cpp
├── assistthread.h
├── bin
├── postgresql
│ ├── config.ini
│ ├── oneproxy-for-postgresql_win64-1.2.8.zip
│ └── oneproxy-for-postgresql_x64-1.2.zip
└── sqlserver
│ ├── config.ini
│ ├── oneproxy-for-sqlserver_win64-1.2.8.zip
│ └── oneproxy-for-sqlserver_x64-1.2.zip
├── build
└── superMonitor.pcap
├── clientthread.cpp
├── clientthread.h
├── commercial
├── freeimpl.cpp
├── freeimpl.h
├── strategyfactory.cpp
└── strategyfactory.h
├── conf
├── config.cpp
├── config.h
├── convertutf.c
├── convertutf.h
└── simpleini.h
├── config.ini
├── connection.h
├── connectmanager.cpp
├── connectmanager.h
├── define.h
├── document
├── 平民软件oneproxy-monitor使用手册.docx
└── 平民软件oneproxy-monitor使用手册.pdf
├── handlemanager.cpp
├── handlemanager.h
├── httpserver
├── http.cpp
├── http.h
├── httphtml.cpp
├── httphtml.h
├── httpparse.cpp
├── httpparse.h
├── httpresponse.cpp
├── httpresponse.h
├── httpserver.cpp
├── httpserver.h
├── machinestatus.cpp
└── machinestatus.h
├── iomultiplex
├── epoll.cpp
├── epoll.h
├── ioev.cpp
├── ioev.h
├── ioevent.cpp
├── ioevent.h
├── ioselect.cpp
└── ioselect.h
├── lib
├── libcrypto.a
├── libcryptopp.a
├── libgmp.a
├── libpacket.a
├── libpacket_x64.a
├── libssl.a
├── libtcmalloc_minimal.a
├── libwpcap.a
├── libwpcap_x64.a
└── win
│ ├── Gdi32.Lib
│ ├── libcrypto.a
│ ├── libgdi32.a
│ ├── libgmp.a
│ ├── libsqlite3_win64.a
│ └── libssl.a
├── main.cpp
├── managerbase.cpp
├── managerbase.h
├── monitor
├── capturedata.cpp
├── capturedata.h
├── monitor_define.h
├── monitormanager.cpp
├── monitormanager.h
├── monitortool.cpp
├── monitortool.h
├── parsedata.cpp
├── parsedata.h
├── supermonitor.cpp
└── supermonitor.h
├── networksocket.cpp
├── networksocket.h
├── oneproxyserver.cpp
├── oneproxyserver.h
├── pidmanager.h
├── protocol
├── connectionpool.cpp
├── connectionpool.h
├── fake
│ ├── fakeprotocol.cpp
│ └── fakeprotocol.h
├── protocolbase.cpp
├── protocolbase.h
├── protocoldynamiccls.h
├── protocolfactory.cpp
├── protocolfactory.h
├── protocolpacket.cpp
└── protocolpacket.h
├── sql
├── sql-tokenizer2.l
├── sqlparser.cpp
├── sqlparser.h
└── sqlparser_lex.cpp
├── stats
├── database
│ ├── createtable.sql
│ ├── db_define.h
│ ├── dbbase.cpp
│ ├── dbbase.h
│ ├── dbmanager.cpp
│ ├── dbmanager.h
│ ├── libsqlite3.a
│ ├── sqlite3.h
│ ├── sqlite3ext.h
│ ├── sqlitedb.cpp
│ ├── sqlitedb.h
│ └── tab
│ │ ├── sqlexectab.h
│ │ ├── sqltab.h
│ │ ├── sqltablereltab.h
│ │ ├── tabbase.h
│ │ ├── tabheader.h
│ │ ├── tabletab.h
│ │ ├── transinfotab.h
│ │ ├── transsqlreltab.h
│ │ ├── usersqlreltab.h
│ │ └── usertab.h
├── record.cpp
├── record.h
├── record_define.h
└── sqlite3.exe
├── tcpclient.cpp
├── tcpclient.h
├── tcpserver.cpp
├── tcpserver.h
├── test
├── testlogger.cpp
├── testlogger.h
├── testmain.cpp
├── testnetworksocket.cpp
├── testnetworksocket.h
├── teststringbuf.cpp
├── teststringbuf.h
├── testtcpclient.cpp
├── testtcpclient.h
├── testtcpserver.cpp
├── testtcpserver.h
├── testtool.cpp
└── testtool.h
├── unittest
├── collectoroutput.cpp
├── compileroutput.cpp
├── config.h
├── cpptest-assert.h
├── cpptest-collectoroutput.h
├── cpptest-compileroutput.h
├── cpptest-htmloutput.h
├── cpptest-output.h
├── cpptest-source.h
├── cpptest-suite.h
├── cpptest-textoutput.h
├── cpptest-time.h
├── cpptest.h
├── htmloutput.cpp
├── missing.cpp
├── missing.h
├── source.cpp
├── suite.cpp
├── textoutput.cpp
├── time.cpp
├── utils.cpp
├── utils.h
└── winconfig.h
└── util
├── hitcache.h
├── keepalive.cpp
├── keepalive.h
├── logger.cpp
├── logger.h
├── md5.cpp
├── md5.h
├── memmanager.cpp
├── memmanager.h
├── mutexlock.cpp
├── mutexlock.h
├── ping.cpp
├── ping.h
├── readwritelock.cpp
├── readwritelock.h
├── socketutil.cpp
├── socketutil.h
├── stringbuf.cpp
├── stringbuf.h
├── systemapi.cpp
├── systemapi.h
├── thread.cpp
├── thread.h
├── threadtask.h
├── tool.cpp
├── tool.h
├── uspinlock.cpp
├── uspinlock.h
├── vip.cpp
└── vip.h
/Makefile:
--------------------------------------------------------------------------------
1 | BUILD = build
2 | BUILD_TEST_BIN = utest
3 |
4 | ifeq ($(LANG),) #windows
5 | INSTALLDIR = install
6 | LDFLAGS = -static-libgcc -static-libstdc++ -L./lib -L./
7 | LIBS = ./lib/win/libsqlite3_win64.a ./lib/win/libssl.a ./lib/win/libcrypto.a ./lib/win/libgdi32.a -lwsock32 -lwinmm -lpacket -lwpcap -lws2_32 -lIPHLPAPI ./lib/win/libgmp.a
8 |
9 | INCLUDE = -IC:\openssl-1.0.2e\win64\include -ID:\winlib\winpcap\Include
10 | else #linux
11 | $(shell if [ ! -d $(BUILD)/$(BUILD_TEST_BIN) ]; then mkdir -p $(BUILD)/$(BUILD_TEST_BIN); fi;)
12 | INSTALLDIR = /usr/local/superoneproxy/
13 | LDFLAGS =
14 | OPENSSL = /usr/local/openssl
15 | LIBEV = /usr/local/libev
16 | LIBPCAP = /usr/local/libpcap
17 | # -lprofiler -lunwind ./lib/libtcmalloc_minimal.a
18 | LIBS = -pthread ./lib/libtcmalloc_minimal.a ./stats/database/libsqlite3.a ./lib/libgmp.a $(OPENSSL)/lib/libssl.a $(OPENSSL)/lib/libcrypto.a $(LIBEV)/lib/libev.a $(LIBPCAP)/lib/libpcap.a -ldl
19 | INCLUDE = -I$(OPENSSL)/include -I$(LIBEV)/include -I$(LIBPCAP)/include
20 | endif
21 |
22 | CXXFLAGS = -Wall -Wformat=0 -Wno-strict-aliasing -g
23 |
24 | APPSOURCEDIR = ./sql \
25 | ./util \
26 | ./conf \
27 | ./stats \
28 | ./stats/database/ \
29 | ./stats/database/tab \
30 | ./monitor \
31 | ./httpserver \
32 | ./iomultiplex \
33 | ./protocol \
34 | ./protocol/fake \
35 | ./protocol/sqlserver \
36 | ./protocol/postgresql \
37 | ./commercial
38 |
39 | TESTSOURCEDIR = ./test/ ./unittest/
40 |
41 | SOURCEDIR = $(TESTSOURCEDIR) $(APPSOURCEDIR)
42 |
43 | VPATH = ./
44 | VPATH += $(foreach tdir, $(SOURCEDIR), :$(tdir))
45 |
46 | DIR = -I./.
47 | DIR += $(foreach tdir, $(SOURCEDIR), -I$(tdir))
48 | DIR += $(INCLUDE)
49 |
50 | MAIN_SOURCES = main.cpp
51 |
52 | SOURCES = $(filter-out $(MAIN_SOURCES), $(wildcard *.cpp))
53 | SOURCES += $(foreach tdir, $(APPSOURCEDIR), $(filter-out $(MAIN_SOURCES), $(wildcard $(tdir)/*.cpp)))
54 | CSOURCES = $(foreach tdir, $(APPSOURCEDIR), $(filter-out $(MAIN_SOURCES), $(wildcard $(tdir)/*.c)))
55 |
56 | HEADERS = $(wildcard ./*.h)
57 | HEADERS += $(foreach tdir, $(APPSOURCEDIR), $(wildcard $(tdir)/*.h))
58 |
59 | ifeq ($(MAKECMDGOALS), test)
60 | SOURCES += $(wildcard test/*.cpp) $(wildcard unittest/*.cpp)
61 | HEADERS += $(wildcard test/*.h) $(wildcard unittest/*.h)
62 | CXXFLAGS += -Dprivate=public -Dprojected=public -g
63 | else
64 | SOURCES += $(MAIN_SOURCES)
65 | CXXFLAGS += -O2
66 | endif
67 | OBJS = $(patsubst %.cpp, $(BUILD)/%.o, $(notdir $(SOURCES)))
68 | COBJS = $(patsubst %.c, $(BUILD)/%.o, $(notdir $(CSOURCES)))
69 |
70 | ifeq ($(MAKECMDGOALS), test)
71 | ifeq ($(LANG),)
72 | TARGET = $(BUILD)/$(BUILD_TEST_BIN)/unittest_main.exe
73 | else
74 | TARGET = $(BUILD)/$(BUILD_TEST_BIN)/unittest_main
75 | endif
76 | else
77 | ifeq ($(LANG),)
78 | TARGET = $(BUILD)/oneproxy-for-sqlserver.exe
79 | else
80 | TARGET = $(BUILD)/oneproxy-for-sqlserver
81 | endif
82 | endif
83 |
84 | .PHONY: all
85 | all: $(TARGET)
86 |
87 | $(OBJS): $(BUILD)/%.o: %.cpp
88 | $(CXX) $(CXXFLAGS) -c $(DIR) $< -o $@
89 |
90 | $(COBJS): $(BUILD)/%.o: %.c
91 | $(CXX) $(CXXFLAGS) -c $(DIR) $< -o $@
92 |
93 | $(TARGET): $(OBJS) $(COBJS)
94 | $(CXX) $(LDFLAGS) -o $(TARGET) $(OBJS) $(COBJS) $(LIBS)
95 |
96 | .PHONY: test
97 | test: $(TARGET)
98 |
99 | install:
100 | -@mkdir $(INSTALLDIR)
101 | -@mkdir $(INSTALLDIR)/include/
102 | -@mkdir $(INSTALLDIR)/include/conf/
103 | -@echo $(HEADERS)
104 | -@cp -rf $(HEADERS) $(INSTALLDIR)/include/
105 | -@cp -rf conf/config.h $(INSTALLDIR)/include/conf/
106 | -@cp -rf $(TARGET) $(INSTALLDIR)/bin/
107 |
108 | clean:
109 | -@rm $(BUILD)/*.o $(TARGET)
110 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # oneproxy-monitor
2 | 在实现一个数据库的监控器,需要实现下面的接口,在本框架中提供了一个默认的直接转发的监控部分。
3 | 必须实现的接口:
4 | 1. is_currentDatabase: 这个类是用来选择数据库类的,当connection第一次接收到数据包时,通过此类来判断当前连接是否属于这个数据库的连接,如果是则返回true。
5 | 否则返回false。如果为true,则框架将从配置中读取数据库地址和端口,连接连接,同时转发数据到这个连接上面。
6 | 2. createInstance: 框架通过调用这个函数来创建对应的实例,建议不要使用单例模式来创建,因为在这个实例中有prepared的相关信息,不同的连接可能有相同的句柄。
7 | 3. destoryInstance: 当连接完成时,会调用此函数来释放相关的内存等。
8 | 4. get_packetType:根据包的数据返回包的类型,由于不同数据库包的格式不同,类型的位置和长度不同,故需要不同的数据库协议类自己实现此接口。
9 | 可选实现的接口:
10 | 1. protocol_front: 前端接收到的数据包,都会传递给这个函数,协议类可以通过重新实现这个函数来改变默认的处理方式。框架在调用这个函数后,就直接把数据包转发到服务端了。
11 | 2. protocol_backend: 后端接收到数据包,都会传递给这个函数,协议类可以通过重新实现这个函数改变默认的处理方式。框架在调用这个函数后,就直接把数据包转发到客户端了。
12 | 3. prehandle_frontPacket:默认实现是没有处理数据包的任何内容。如果需要针对接收到的前端数据包进行处理,则需要实现此函数。比如:当客户端的数据包特别大时,被客户 端分成了多个数据包发送到服务端,在进行统计前,需要针对这些数据包进行合并,那么就需要在此包中进行合并的逻辑。
13 | 4. prehandle_backendPacket:与prehandle_frontPacket相同。不同的点是,这个函数针对接收到的后端数据包
14 | 5. protocol_initFrontStatPacket: 默认实现只是把bufpointer的指针指向接收到的数据包。如果在进行执行处理函数前,需要针对数据进行修改,那么需要实现此函数。
15 | 6. protocol_initBackendStatPacket: 与protocol_initFrontStatPacket函数功能相同,不同点是,这个针对后端数据包。
16 | 7. protocol_clearFrontStatPacket:当执行完协议类注册的处理函数后,执行此函数。默认实现是空的。
17 | 8. protocol_clearBackendStatPacket:功能与protocol_clearFrontStatPacket相同,不同的是这个函数针对后端数据包的处理。
18 |
19 | 默认具有如下的功能:
20 | 1. 可以指定多个端口,不同的端口转发到不同的数据库。也就是通过一个监控器管理多个数据库
21 | 2. 可以通过配置控制前端连接数
22 | 3. 自动根据cpu数量设置线程个数
23 | 4. 支持windows和Linux。其中windows只支持select。Linux支持select和epoll,默认为epoll方式
24 | 5. FakeProtocol 是针对包直接进行转发。
25 | 更多特性关键:https://github.com/onexsoft/oneproxy-monitor/wiki
26 |
27 | 目前平民软件基于此架构已经提供sql server, postgresql的监控功能。
28 | 监控效果可以看在线的mysql的监控效果:http://www.onexsoft.com:8080/
29 | 更多信息,请访问我们的官网:http://www.onexsoft.com 或者加入群:数据库监控 521095285。
30 |
31 | oneproxy-for-sqlserver支持功能点:
32 | 1) 直接转发并且统计sql使用情况。
33 | 2) 直接转发不统计sql使用情况。
34 | 3) 支持前后端使用不同的密码
35 | 4) 支持读写分离
36 | 5) 支持连接管理功能(类似连接池)
37 | 6) 支持监控多个端口,前端连接到不同的端口上面
38 | 7) 支持前端固定端口转发到后端固定的数据库上面
39 |
40 | oneproxy-for-postgresql 支持功能点:
41 | 1) 直接转发并且统计sql使用情况。
42 | 2) 直接转发不统计sql使用情况。
43 | 3) 支持连接管理功能(类似连接池)
44 | 4) 支持监控多个端口,前端连接到不同的端口上面
45 | 5) 支持前端固定端口转发到后端固定的数据库上面
46 |
47 | libev 下载地址:http://pkgs.fedoraproject.org/repo/pkgs/libev/
48 |
--------------------------------------------------------------------------------
/assistthread.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | *
19 | * @FileName: assistthread.h
20 | * @Description: TODO
21 | * All rights Reserved, Designed By huih
22 | * @Company: onexsoft
23 | * @Author: hui
24 | * @Version: V1.0
25 | * @Date: 2016年11月9日 下午1:38:52
26 | *
27 | */
28 |
29 | #ifndef ASSISTTHREAD_H_
30 | #define ASSISTTHREAD_H_
31 |
32 | #include "thread.h"
33 | #include "connectionpool.h"
34 |
35 | class AssistThread : public Thread{
36 | private:
37 | bool is_stop;
38 | public:
39 | AssistThread();
40 | ~AssistThread();
41 |
42 | void stop();
43 | bool get_stop();
44 |
45 | bool connect_dataBaseIsOk(std::string addr, unsigned int port);
46 | void check_dataBaseActive();
47 | private:
48 | static thread_start_func(start);
49 |
50 | };
51 |
52 | #endif /* ASSISTTHREAD_H_ */
53 |
--------------------------------------------------------------------------------
/bin/postgresql/config.ini:
--------------------------------------------------------------------------------
1 | [oneproxy]
2 | logfile = oneproxy_log.log
3 | pidfile = oneproxy_pid.pid
4 | listen_addr = 0.0.0.0
5 | listen_port = 9999,7777,6666
6 | httpserver_addr = 0.0.0.0
7 | httpserver_port = 8080
8 | log_level = error
9 | data_dump = false
10 | log_sql = false
11 | logclientsql=false
12 | clientusername = sa
13 | clientpassword = 0000
14 | keepalive = 1
15 | acceptthreadnum = 1
16 | maxconnectnum = 40000
17 | vip_ifname = em1:0
18 | vip_address = 172.30.12.22
19 | #threadnum = 1
20 |
21 | [database_1433]
22 | host = 192.168.7.236
23 | port = 51915
24 | username = sa
25 | password = 0000
26 |
27 | [database_1434]
28 | host = 192.168.7.236
29 | port = 55555
30 | username = sa
31 | password = abcdefuz
32 |
33 | [database_1435]
34 | host = 192.168.7.236
35 | port = 30867
36 | username = sa
37 | password = 0000
38 |
39 | [database_5432]
40 | host = 172.30.12.12
41 | port = 5432
42 | username = db_user
43 | password = 0000
44 |
45 | [database_7777_5432]
46 | host = 172.30.12.7
47 | port = 5432
48 | username = db_user
49 | password = 0000
50 |
51 | [database_8888_5432]
52 | host = 172.30.12.8
53 | port = 5432
54 | username = db_user
55 | password = 0000
56 |
57 |
58 | [sqlserver_9999]
59 | dbmastergroup = database_1433
60 | dbslavegroup = database_1434
61 | classname = SSProtocol
62 | useconnectionpool = true
63 | readslave = true
64 | passwordseparate = true
65 |
66 | [sqlserver_7777]
67 | dbmastergroup = database_1435
68 | classname = SSProtocol
69 | frontport = 7777
70 | passwordseparate = false
71 |
72 | [postgresql_5432]
73 | dbmastergroup = database_5432
74 | dbslavegroup = database_7777_5432, database_8888_5432
75 | classname = PGProtocol
76 | frontport = 0
77 | passwordseparate=true
78 | useconnectionpool=true
79 | readslave = true
80 | clearbackendconnection = true
81 |
82 |
--------------------------------------------------------------------------------
/bin/postgresql/oneproxy-for-postgresql_win64-1.2.8.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onexsoft/oneproxy-monitor/474f43eb154c9e587ed3dd65a6b94003059474de/bin/postgresql/oneproxy-for-postgresql_win64-1.2.8.zip
--------------------------------------------------------------------------------
/bin/postgresql/oneproxy-for-postgresql_x64-1.2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onexsoft/oneproxy-monitor/474f43eb154c9e587ed3dd65a6b94003059474de/bin/postgresql/oneproxy-for-postgresql_x64-1.2.zip
--------------------------------------------------------------------------------
/bin/sqlserver/config.ini:
--------------------------------------------------------------------------------
1 | [oneproxy]
2 | logfile = oneproxy_log.log
3 | pidfile = oneproxy_pid.pid
4 | listen_addr = 0.0.0.0
5 | listen_port = 9999,7777,6666
6 | httpserver_addr = 0.0.0.0
7 | httpserver_port = 8080
8 | log_level = debug
9 | data_dump = false
10 | log_sql = false
11 | logclientsql=false
12 | clientusername = sa
13 | clientpassword = 0000
14 | keepalive = 0
15 | acceptthreadnum = 1
16 | maxconnectnum = 40000
17 | usemonitor = 0
18 | monitordevicename = {69E4307F-5EB3-4076-9A18-78290796E5F7}
19 | monitorportclass = SSProtocol:51915;SSProtocol:55555;SSProtocol:30867;
20 | threadnum = 1
21 |
22 | [database_1433]
23 | host = 192.168.7.147
24 | port = 51915
25 | username = sa
26 | password = 0000
27 |
28 | [database_1434]
29 | host = 192.168.7.147
30 | port = 55555
31 | username = sa
32 | password = abcdefuz
33 |
34 | [database_1435]
35 | host = 192.168.7.147
36 | port = 30867
37 | username = sa
38 | password = 0000
39 |
40 | [database_5432]
41 | host = 172.30.12.12
42 | port = 5432
43 | username = db_user
44 | password = 0000
45 |
46 | [database_7777_5432]
47 | host = 172.30.12.7
48 | port = 5432
49 | username = db_user
50 | password = 0000
51 |
52 | [database_8888_5432]
53 | host = 172.30.12.8
54 | port = 5432
55 | username = db_user
56 | password = 0000
57 |
58 |
59 | [sqlserver_9999]
60 | dbmastergroup = database_1433
61 | dbslavegroup = database_1434
62 | classname = SSProtocol
63 | useconnectionpool = true
64 | readslave = true
65 | passwordseparate = true
66 |
67 | #[sqlserver_7777]
68 | #dbmastergroup = database_1435
69 | #classname = SSProtocol
70 | #frontport = 7777
71 | #passwordseparate = false
72 |
73 | #[postgresql_5432]
74 | #dbmastergroup = database_5432
75 | #dbslavegroup = database_7777_5432, database_8888_5432
76 | #classname = PGProtocol
77 | #frontport = 0
78 | #passwordseparate=true
79 | #useconnectionpool=true
80 | #readslave = true
81 | #clearbackendconnection = true
82 | #usemasterassalve = true
83 |
84 |
--------------------------------------------------------------------------------
/bin/sqlserver/oneproxy-for-sqlserver_win64-1.2.8.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onexsoft/oneproxy-monitor/474f43eb154c9e587ed3dd65a6b94003059474de/bin/sqlserver/oneproxy-for-sqlserver_win64-1.2.8.zip
--------------------------------------------------------------------------------
/bin/sqlserver/oneproxy-for-sqlserver_x64-1.2.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onexsoft/oneproxy-monitor/474f43eb154c9e587ed3dd65a6b94003059474de/bin/sqlserver/oneproxy-for-sqlserver_x64-1.2.zip
--------------------------------------------------------------------------------
/build/superMonitor.pcap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/onexsoft/oneproxy-monitor/474f43eb154c9e587ed3dd65a6b94003059474de/build/superMonitor.pcap
--------------------------------------------------------------------------------
/commercial/freeimpl.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | *
19 | * @FileName: FreeImpl.cpp
20 | * @Description: TODO
21 | * All rights Reserved, Designed By huih
22 | * @Company: onexsoft
23 | * @Author: hui
24 | * @Version: V1.0
25 | * @Date: 2016年12月7日 下午3:05:08
26 | *
27 | */
28 |
29 | #include "freeimpl.h"
30 |
31 | FreeImpl::FreeImpl() {
32 | // TODO Auto-generated constructor stub
33 |
34 | }
35 |
36 | FreeImpl::~FreeImpl() {
37 | // TODO Auto-generated destructor stub
38 | }
39 |
40 | int FreeImpl::get_databaseFromGroup(Connection& con)
41 | {
42 | uif(con.database.dataBaseGroup == NULL)
43 | return -1;
44 |
45 | std::vector::iterator it = con.database.dataBaseGroup->get_dbMasterGroupVec().begin();
46 | for (; it != con.database.dataBaseGroup->get_dbMasterGroupVec().end(); ++it) {
47 | if ((*it)->get_isActive()) {
48 | con.database.masterDataBase = *it;
49 | break;
50 | }
51 | }
52 | if (con.database.masterDataBase == NULL) {//必须需要master
53 | logs(Logger::ERR, "no valid database in config file");
54 | return -1;
55 | }
56 |
57 | std::vector::iterator sit = con.database.dataBaseGroup->get_dbSlaveGroupVec().begin();
58 | for (; sit != con.database.dataBaseGroup->get_dbSlaveGroupVec().end(); ++sit) {
59 | if ((*sit)->get_isActive()) {
60 | con.database.slaveDataBase = *sit;
61 | break;
62 | }
63 | }
64 |
65 | //first set current database is master database
66 | con.database.currentDataBase = con.database.masterDataBase;
67 |
68 | return 0;
69 | }
70 |
--------------------------------------------------------------------------------
/commercial/freeimpl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | *
19 | * @FileName: FreeImpl.h
20 | * @Description: TODO
21 | * All rights Reserved, Designed By huih
22 | * @Company: onexsoft
23 | * @Author: hui
24 | * @Version: V1.0
25 | * @Date: 2016年12月7日 下午3:05:08
26 | *
27 | */
28 |
29 | #ifndef FreeImpl_FreeImpl_H_
30 | #define FreeImpl_FreeImpl_H_
31 |
32 | #include "connection.h"
33 | #include "define.h"
34 |
35 | class FreeImpl {
36 | public:
37 | FreeImpl();
38 | virtual ~FreeImpl();
39 |
40 | virtual int get_databaseFromGroup(Connection& con);
41 | };
42 |
43 | #endif /* FreeImpl_FreeImpl_H_ */
44 |
--------------------------------------------------------------------------------
/commercial/strategyfactory.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | *
19 | * @FileName: strategyfactory.cpp
20 | * @Description: TODO
21 | * All rights Reserved, Designed By huih
22 | * @Company: onexsoft
23 | * @Author: hui
24 | * @Version: V1.0
25 | * @Date: 2016年12月7日 下午5:17:10
26 | *
27 | */
28 |
29 | #include "strategyfactory.h"
30 | #ifndef GITHUB_OPENSOURCE
31 | #include "commericialimpl.h"
32 | #endif
33 | #include "mutexlock.h"
34 |
35 | FreeImpl* StrategyFactory::impl = NULL;
36 | MutexLock StrategyFactory::mutexLock;
37 | FreeImpl* StrategyFactory::get_strategy()
38 | {
39 | if (impl == NULL) {
40 | mutexLock.lock();
41 | if (impl == NULL) {
42 | #ifdef GITHUB_OPENSOURCE
43 | impl = new FreeImpl();
44 | #else
45 | if (userIsFree()) {
46 | impl = new FreeImpl();
47 | } else {
48 | impl = new CommericialImpl();
49 | }
50 | #endif
51 | }
52 | mutexLock.unlock();
53 | }
54 | return impl;
55 | }
56 |
57 | StrategyFactory::~StrategyFactory() {
58 | if (StrategyFactory::impl != NULL) {
59 | delete StrategyFactory::impl;
60 | StrategyFactory::impl = NULL;
61 | }
62 | }
63 |
64 | bool StrategyFactory::userIsFree() {
65 | return false;
66 | }
67 |
--------------------------------------------------------------------------------
/commercial/strategyfactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | *
19 | * @FileName: strategyfactory.h
20 | * @Description: TODO
21 | * All rights Reserved, Designed By huih
22 | * @Company: onexsoft
23 | * @Author: hui
24 | * @Version: V1.0
25 | * @Date: 2016年12月7日 下午5:15:12
26 | *
27 | */
28 |
29 | #ifndef COMMERCIAL_STRATEGYFACTORY_H_
30 | #define COMMERCIAL_STRATEGYFACTORY_H_
31 |
32 | #include "freeimpl.h"
33 | #include "mutexlock.h"
34 |
35 | class StrategyFactory{
36 | public:
37 | static FreeImpl* get_strategy();
38 | private:
39 | ~StrategyFactory();
40 |
41 | static bool userIsFree();
42 |
43 | private:
44 | static MutexLock mutexLock;
45 | static FreeImpl* impl;
46 | };
47 |
48 |
49 |
50 | #endif /* COMMERCIAL_STRATEGYFACTORY_H_ */
51 |
--------------------------------------------------------------------------------
/config.ini:
--------------------------------------------------------------------------------
1 | [oneproxy]
2 | logfile = oneproxy_log.log
3 | pidfile = oneproxy_pid.pid
4 | listen_addr = 0.0.0.0
5 | listen_port = 9999,7777,6666
6 | httpserver_addr = 0.0.0.0
7 | httpserver_port = 8080
8 | log_level = error
9 | data_dump = false
10 | log_sql = false
11 | clientusername = sa
12 | clientpassword = 0000
13 | keepalive = 0
14 |
15 | [database_1433]
16 | host = 192.168.7.52
17 | port = 51915
18 | username = sa
19 | password = 0000
20 |
21 | [database_1434]
22 | host = 192.168.7.52
23 | port = 55555
24 | username = sa
25 | password = abcdefuz
26 |
27 | [database_1435]
28 | host = 192.168.7.52
29 | port = 30867
30 | username = sa
31 | password = 0000
32 |
33 | [database_6666]
34 | host = 127.0.0.1
35 | port = 6666
36 | username = sa
37 | password = 0000
38 |
39 | [database_5432]
40 | host = 172.30.12.12
41 | port = 5432
42 | username = db_user
43 | password = 0000
44 |
45 | [database_7838]
46 | host = 127.0.0.1
47 | port = 7838
48 | username = 1111
49 | password = 1111
50 |
51 |
52 | [sqlserver_9999]
53 | dbmastergroup = database_1435
54 | dbslavegroup = database_1434
55 | classname = SSProtocol
56 | frontport = 9999
57 | useconnectionpool = true
58 | readslave = true
59 | passwordseparate = true
60 |
61 | [sqlserver_7777]
62 | dbmastergroup = database_1435
63 | classname = SSProtocol
64 | frontport = 7777
65 | passwordseparate = false
66 |
67 | [postgresql_5432]
68 | dbmastergroup = database_5432
69 | classname = PGProtocol
70 | frontport = 0
71 |
72 |
73 |
--------------------------------------------------------------------------------
/connectmanager.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | *
19 | * @FileName: connectmanager.h
20 | * @Description: TODO
21 | * All rights Reserved, Designed By huih
22 | * @Company: onexsoft
23 | * @Author: hui
24 | * @Version: V1.0
25 | * @Date: 2016年8月4日
26 | *
27 | */
28 |
29 | #ifndef CONNECTMANAGER_H_
30 | #define CONNECTMANAGER_H_
31 |
32 |
33 | #include "vip.h"
34 | #include "record.h"
35 | #include "thread.h"
36 | #include "httpserver.h"
37 | #include "mutexlock.h"
38 | #include "networksocket.h"
39 | #include "assistthread.h"
40 | #include "oneproxyserver.h"
41 | #include "clientthread.h"
42 |
43 | #include