Graphite
跳转到导航
跳转到搜索
配置
由于 SQLite3 的局限性,在事件比较多时会很慢甚至报错。推荐使用 PostgreSQL。
Web
cd /opt/graphite/conf
cp graphite.wsgi.example graphite.wsgi
# edit graphite.wsgi
cd /opt/graphite/webapp/graphite
cp local_settings.py.example local_settings.py
# edit local_settings.py
# 注意修改时区!它并不会默认使用系统时区
PYTHONPATH=/opt/graphite/webapp django-admin.py syncdb --settings=graphite.settings
# 创建 events 需要
setfacl -m u:graphite:rwx /opt/graphite/storage
nginx 配置
server {
listen 80;
server_name xxx;
location / {
root /opt/graphite/webapp;
try_files $uri @uwsgi;
}
location /static {
alias /opt/graphite/webapp/content;
}
location @uwsgi {
uwsgi_pass unix:/var/run/graphite/graphite.sock;
include uwsgi_params;
}
}
uwsgi 配置
[uwsgi]
master = true
workers = 10
socket = /var/run/graphite/graphite.sock
chdir = /opt/graphite/conf
virtualenv = /opt/graphite
wsgi-file = graphite.wsgi
chmod-socket = 660
# uid = graphite
# gid = graphite
# plugins = python2
mkdir -p /var/run/graphite
chown graphite: /var/run/graphite /opt/graphite/storage /opt/graphite/storage/graphite.db /opt/graphite/storage/log/webapp
usermod -aG graphite http
uwsgi --ini /etc/uwsgi/graphite.ini --daemonize2 /var/log/graphite.log
carbon
配置:
cd /opt/graphite/conf
cp carbon.conf.example carbon.conf
# edit carbon.conf
cp storage-schemas.conf.example storage-schemas.conf
# edit storage-schemas.conf
cp storage-aggregation.conf.example storage-aggregation.conf
# edit storage-aggregation.conf
chown carbon: /opt/graphite/storage/log
chown carbon: /opt/graphite/storage
chown carbon: /opt/graphite/storage/whisper
启动:
sudo -u carbon /opt/graphite/bin/carbon-cache.py start
自启动
uwsgi --ini /etc/uwsgi/graphite.ini --daemonize2 /var/log/graphite.log
su carbon -c "/opt/graphite/bin/carbon-cache.py start"
statsd
可在 storage-schemas.conf
中加入如下设置:
[statsd]
pattern = ^stats
retentions = 10s:2d,1m:14d,10m:365d,1h:1800d
在 storage-aggregation.conf
中如下设置:
[min]
pattern = \.(min|lower)$
xFilesFactor = 0.1
aggregationMethod = min
[max]
pattern = \.(max|upper)$
xFilesFactor = 0.1
aggregationMethod = max
[sum]
pattern = \.count$
xFilesFactor = 0
aggregationMethod = sum
[default_average]
pattern = .*
xFilesFactor = 0.5
aggregationMethod = average
注意
whisper 存储数据时,数据的时间戳会根据 retention 取到不大于其的时间点上。比如提交的数据时间戳是 1464767098,最小 retention 是 10s,那么 whipser 会将数据存储到 1464767090。
启动 carbon 时如遇到以下错误:
twisted.python.usage.UsageError: The specified reactor cannot be used, failed with error: reactor already installed.
See the list of available reactors with --help-reactors
可注释掉 /opt/graphite/lib/carbon/util.py:61
twistd_options.append("--reactor=epoll")
参见
- statsd
- Tools That Work With Graphite — Graphite 0.10.0 documentation
- InfluxDB: 另一存储后端
- Grafana: 另一展示界面