InfluxDB Proxy with High Availability and Consistent Hash
9.4K
This project adds a basic high availability and consistent hash layer to InfluxDB.
NOTE: influx-proxy must be built with Go 1.16+ with Go module support, don't implement udp.
NOTE: InfluxDB Cluster - open source alternative to InfluxDB Enterprise has been released, which is better than InfluxDB Proxy.
We used InfluxDB Relay before, but it doesn't support some demands. We use grafana for visualizing time series data, so we need add datasource for grafana. We need change the datasource config when influxdb is down. We need transfer data across idc, but Relay doesn't support gzip. It's inconvenient to analyse data with connecting different influxdb. Therefore, we made InfluxDB Proxy. More details please visit https://github.com/shell909090/influx-proxy.
Forked from the above InfluxDB Proxy, after many improvements and optimizations, InfluxDB Proxy v1 has released, which no longer depends on python and redis, and supports more features.
Since the InfluxDB Proxy v1 is limited by the only ONE database and the KEYMAPS configuration, we refactored InfluxDB Proxy v2 with high availability and consistent hash, which supports multiple databases and tools to rebalance, recovery, resync and cleanup.
Download docker-compose.yml and proxy.json from docker/quick
$ docker-compose up -d
An influx-proxy container (port: 7076) and 4 influxdb containers will start.
$ git clone https://github.com/chengshiwen/influx-proxy.git
$ cd influx-proxy
$ make
$ ./bin/influx-proxy -config proxy.json
$ ./bin/influx-proxy -h
Usage of ./bin/influx-proxy:
-config string
proxy config file with json/yaml/toml format (default "proxy.json")
-version
proxy version
$ # build current platform
$ make build
$ # build linux amd64
$ make linux
$ # cross-build all platforms
$ make release
Before developing, you need to install and run Docker
$ ./script/setup.sh # start 4 influxdb instances by docker
$ make run
$ ./script/write.sh # write data
$ ./script/query.sh # query data
$ ./script/remove.sh # remove 4 influxdb instances
The architecture is fairly simple, one InfluxDB Proxy instance and two consistent hash circles with two InfluxDB instances respectively. The Proxy should point HTTP requests with db and measurement to the two circles and the four InfluxDB servers.
The setup should look like this:
┌───────────┐
│ writes & queries │
└───────────┘
│
▼
┌───────────┐
│ │
│ InfluxDB Proxy │
│ (only http) │
│ │
└───────────┘
│
▼
┌───────────┐
│ db,measurement │
│ consistent hash │
└───────────┘
| |
┌┼────────┘
│ └─────────┐
▼ ▼
Circle 1 Circle 2
┌───────┐ ┌───────┐
│ │ │ │
│ InfluxDB 1 │ │ InfluxDB 3 │
│ InfluxDB 2 │ │ InfluxDB 4 │
│ │ │ │
└───────┘ └───────┘
The configuration file supports format json, yaml and toml, such as proxy.json, proxy.yaml and proxy.toml.
The configuration settings are as follows:
circles: circle list
name: circle name, requiredbackends: backend list belong to the circle, required
name: backend name, requiredurl: influxdb addr or other http backend which supports influxdb line protocol, requiredusername: influxdb username, with encryption if auth_encrypt is enabled, default is empty which means no authpassword: influxdb password, with encryption if auth_encrypt is enabled, default is empty which means no authauth_encrypt: whether to encrypt auth (username/password), default is falsewrite_only: whether to write only on the influxdb, default is falselisten_addr: proxy listen addr, default is :7076db_list: database list permitted to access, default is []data_dir: data dir to save .dat .rec, default is datatlog_dir: transfer log dir to rebalance, recovery, resync or cleanup, default is loghash_key: backend key for consistent hash, including "idx", "exi", "name" or "url", default is idx, once changed rebalance operation is necessaryflush_size: default is 10000, wait 10000 points writeflush_time: default is 1, wait 1 second write whether point count has bigger than flush_size configcheck_interval: default is 1, check backend active every 1 secondrewrite_interval: default is 10, rewrite every 10 secondsconn_pool_size: default is 20, create a connection pool which size is 20write_timeout: default is 10, write timeout until 10 secondsidle_timeout: default is 10, keep-alives wait time until 10 secondsusername: proxy username, with encryption if auth_encrypt is enabled, default is empty which means no authpassword: proxy password, with encryption if auth_encrypt is enabled, default is empty which means no authauth_encrypt: whether to encrypt auth (username/password), default is falsewrite_tracing: enable logging for the write, default is falsequery_tracing: enable logging for the query, default is falsepprof_enabled: enable /debug/pprof HTTP endpoint, default is falsehttps_enabled: enable https, default is falsehttps_cert: the ssl certificate to use when https is enabled, default is emptyhttps_key: use a separate private key location, default is emptyThe following commands are forbid.
GRANTREVOKEKILLEXPLAINSELECT INTOCONTINUOUS QUERYMultiple queries delimited by semicolon ;Multiple measurements delimited by comma ,Regexp measurementOnly support match the following commands.
select fromshow fromshow measurementsshow seriesshow field keysshow tag keysshow tag valuesshow statsshow databasescreate databasedrop databaseshow retention policiescreate retention policyalter retention policydrop retention policydelete fromdrop series fromdrop measurementon clausefrom clause like from <db>.<rp>.<measurement>There are three tools for benchmarking InfluxDB, which can also be applied to InfluxDB Proxy:
There is a tool for InfluxDB and InfluxDB Proxy:
MIT.
Content type
Image
Digest
sha256:5ae35e1ee…
Size
9.4 MB
Last updated
about 2 years ago
docker pull chengshiwen/influx-proxy