Skip to content

Commit 109aba0

Browse files
authored
Merge pull request #60 from graphite-project/DZ-RedisTagDB
Introducing Redis TagDB
2 parents e3fce96 + 9679982 commit 109aba0

File tree

5 files changed

+86
-12
lines changed

5 files changed

+86
-12
lines changed

Dockerfile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ RUN python3 -m pip install --upgrade virtualenv virtualenv-tools && \
2323
. /opt/graphite/bin/activate && \
2424
python3 -m pip install --upgrade pip && \
2525
pip3 install django==1.11.15 && \
26-
pip3 install fadvise && \
2726
pip3 install msgpack-python && \
2827
pip3 install gunicorn && \
2928
pip3 install fadvise && \
29+
pip3 install redis && \
3030
pip3 install msgpack-python && \
3131
pip3 install django-statsd-mozilla
3232

@@ -95,16 +95,16 @@ RUN apt-get update --fix-missing \
9595
&& apt-get -y upgrade \
9696
&& apt-get install --yes --no-install-recommends \
9797
git \
98+
redis \
9899
nginx \
99-
python-flup \
100-
python-pip \
101-
python-ldap \
100+
python3-pip \
101+
python3-ldap \
102102
expect \
103103
memcached \
104104
sqlite3 \
105105
libcairo2 \
106-
python-cairo \
107-
python-rrdtool && \
106+
python3-cairo \
107+
python3-rrdtool && \
108108
apt-get clean && \
109109
apt-get autoremove --yes && \
110110
rm -rf /var/lib/apt/lists/*
@@ -117,6 +117,9 @@ RUN rm /etc/nginx/sites-enabled/default
117117
ADD conf/etc/nginx/nginx.conf /etc/nginx/nginx.conf
118118
ADD conf/etc/nginx/sites-enabled/graphite-statsd.conf /etc/nginx/sites-enabled/graphite-statsd.conf
119119

120+
# config redis
121+
ADD conf/etc/redis/redis.conf /etc/redis/redis.conf
122+
120123
# logging support
121124
RUN mkdir -p /var/log/carbon /var/log/graphite /var/log/nginx /var/log/graphite/
122125
ADD conf/etc/logrotate.d/graphite-statsd /etc/logrotate.d/graphite-statsd
@@ -127,6 +130,8 @@ ADD conf/etc/service/carbon-aggregator/run /etc/service/carbon-aggregator/run
127130
ADD conf/etc/service/graphite/run /etc/service/graphite/run
128131
ADD conf/etc/service/statsd/run /etc/service/statsd/run
129132
ADD conf/etc/service/nginx/run /etc/service/nginx/run
133+
ADD conf/etc/service/redis/run /etc/service/redis/run
134+
RUN chmod 0755 /etc/service/*/run
130135

131136
# default conf setup
132137
ADD conf /etc/graphite-statsd/conf
@@ -139,7 +144,7 @@ RUN chmod +x /usr/local/bin/manage.sh && /usr/local/bin/django_admin_init.exp
139144

140145
# defaults
141146
EXPOSE 80 2003-2004 2023-2024 8080 8125 8125/udp 8126
142-
VOLUME ["/opt/graphite/conf", "/opt/graphite/storage", "/opt/graphite/webapp/graphite/functions/custom", "/etc/nginx", "/opt/statsd", "/etc/logrotate.d", "/var/log"]
147+
VOLUME ["/opt/graphite/conf", "/opt/graphite/storage", "/opt/graphite/webapp/graphite/functions/custom", "/etc/nginx", "/opt/statsd", "/etc/logrotate.d", "/var/log", "/var/lib/redis"]
143148
WORKDIR /
144149
ENV HOME /root
145150
ENV STATSD_INTERFACE udp

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ DOCKER ASSIGNED | /etc/nginx | nginx config
6666
DOCKER ASSIGNED | /opt/statsd | statsd config
6767
DOCKER ASSIGNED | /etc/logrotate.d | logrotate config
6868
DOCKER ASSIGNED | /var/log | log files
69+
DOCKER ASSIGNED | /var/lib/redis | Redis TagDB data (optional)
6970

7071
### Base Image
7172

@@ -144,6 +145,21 @@ Additional environment variables can be set to adjust performance.
144145
* GRAPHITE_FIND_CACHE_DURATION: (0) Time to cache remote metric find results
145146
* GRAPHITE_STATSD_HOST: ("127.0.0.1") If set, django_statsd.middleware.GraphiteRequestTimingMiddleware and django_statsd.middleware.GraphiteMiddleware will be enabled.
146147

148+
## TagDB
149+
Graphite stores tag information in a separate tag database (TagDB). Please check [tags documentation](https://graphite.readthedocs.io/en/latest/tags.html) for details.
150+
151+
* GRAPHITE_TAGDB: ('graphite.tags.localdatabase.LocalDatabaseTagDB') TagDB is a pluggable store, by default it uses the local SQLite database.
152+
* REDIS_TAGDB: (false) if set to true will use local Redis instance to store tags.
153+
* GRAPHITE_TAGDB_CACHE_DURATION: (60) Time to cache seriesByTag results.
154+
* GRAPHITE_TAGDB_AUTOCOMPLETE_LIMIT: (100) Autocomplete default result limit.
155+
* GRAPHITE_TAGDB_REDIS_HOST: ('localhost') Redis TagDB host
156+
* GRAPHITE_TAGDB_REDIS_PORT: (6379) Redis TagDB port
157+
* GRAPHITE_TAGDB_REDIS_DB: (0) Redis TagDB database number
158+
* GRAPHITE_TAGDB_HTTP_URL: ('') URL for HTTP TagDB
159+
* GRAPHITE_TAGDB_HTTP_USER: ('') Username for HTTP TagDB
160+
* GRAPHITE_TAGDB_HTTP_PASSWORD: ('') Password for HTTP TagDB
161+
* GRAPHITE_TAGDB_HTTP_AUTOCOMPLETE: (false) Does the remote TagDB support autocomplete?
162+
147163
## Change the Configuration
148164

149165
Read up on Graphite's [post-install tasks](https://graphite.readthedocs.org/en/latest/install.html#post-install-tasks).

conf/etc/redis/redis.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
daemonize no
2+
pidfile /var/run/redis/redis-server.pid
3+
port 6379
4+
bind 127.0.0.1
5+
timeout 0
6+
tcp-keepalive 0
7+
loglevel notice
8+
logfile /var/log/redis/redis-server.log
9+
databases 16
10+
save 900 1
11+
save 300 10
12+
save 60 10000
13+
stop-writes-on-bgsave-error yes
14+
rdbcompression yes
15+
rdbchecksum yes
16+
dbfilename dump.rdb
17+
dir /var/lib/redis
18+
slave-serve-stale-data yes
19+
slave-read-only yes
20+
repl-disable-tcp-nodelay no
21+
slave-priority 100
22+
appendonly yes
23+
appendfilename "appendonly.aof"
24+
appendfsync everysec
25+
no-appendfsync-on-rewrite no
26+
auto-aof-rewrite-percentage 100
27+
auto-aof-rewrite-min-size 64mb
28+
lua-time-limit 5000
29+
slowlog-log-slower-than 10000
30+
slowlog-max-len 128
31+
notify-keyspace-events ""
32+
hash-max-ziplist-entries 512
33+
hash-max-ziplist-value 64
34+
list-max-ziplist-entries 512
35+
list-max-ziplist-value 64
36+
set-max-intset-entries 512
37+
zset-max-ziplist-entries 128
38+
zset-max-ziplist-value 64
39+
activerehashing yes
40+
client-output-buffer-limit normal 0 0 0
41+
client-output-buffer-limit slave 256mb 64mb 60
42+
client-output-buffer-limit pubsub 32mb 8mb 60
43+
hz 10
44+
aof-rewrite-incremental-fsync yes

conf/etc/service/redis/run

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
[[ -n ${REDIS_TAGDB} ]] || exit 1
4+
exec /usr/bin/redis-server /etc/redis/redis.conf

conf/opt/graphite/webapp/graphite/local_settings.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,13 @@
392392
# TagDB Settings #
393393
#####################################
394394
# Tag Database
395-
#TAGDB = 'graphite.tags.localdatabase.LocalDatabaseTagDB'
396-
TAGDB = os.environ.get('GRAPHITE_TAGDB', '')
395+
396+
# set TAGDB to Redis if REDIS_TAGDB env var is set
397+
_REDIS_TAGDB = os.environ.get('REDIS_TAGDB', 'false').lower() in ['1', 'true', 'yes']
398+
399+
# default TAGDB is local database. Set to '' to disable
400+
TAGDB = 'graphite.tags.redis.RedisTagDB' if _REDIS_TAGDB else \
401+
os.environ.get('GRAPHITE_TAGDB', 'graphite.tags.localdatabase.LocalDatabaseTagDB')
397402

398403
# Time to cache seriesByTag results
399404
TAGDB_CACHE_DURATION = int(os.environ.get('GRAPHITE_TAGDB_CACHE_DURATION') or 60)
@@ -402,9 +407,9 @@
402407
TAGDB_AUTOCOMPLETE_LIMIT = int(os.environ.get('GRAPHITE_TAGDB_AUTOCOMPLETE_LIMIT') or 100)
403408

404409
# Settings for Redis TagDB
405-
#TAGDB_REDIS_HOST = 'localhost'
406-
#TAGDB_REDIS_PORT = 6379
407-
#TAGDB_REDIS_DB = 0
410+
TAGDB_REDIS_HOST = os.environ.get('GRAPHITE_TAGDB_REDIS_HOST', 'localhost')
411+
TAGDB_REDIS_PORT = int(os.environ.get('GRAPHITE_TAGDB_REDIS_PORT') or 6379)
412+
TAGDB_REDIS_DB = int(os.environ.get('GRAPHITE_TAGDB_REDIS_DB') or 0)
408413

409414
# Settings for HTTP TagDB
410415
TAGDB_HTTP_URL = os.environ.get('GRAPHITE_TAGDB_HTTP_URL', '')

0 commit comments

Comments
 (0)