Grafana-优化
配置缓存
rpm 安装的路径在/var/lib/grafana
ini
# grafana.ini
[metrics]
# Enable caching of metric results
enable_metrics_source_cache = true
# Cache results for this many seconds
metrics_source_cache_ttl_seconds = 60数据源缓存
某些数据源插件支持自己的缓存机制,例如 Prometheus 插件。
ini
# grafana.ini
[datasources]
# Prometheus data source cache settings
prometheus:
# Enable caching
enable_metrics_source_cache = true
# Cache results for this many seconds
metrics_source_cache_ttl_seconds = 60配置 Nginx 反向代理
Nginx 可以作为 Grafana 的反向代理,提供静态缓存功能
nginx
server {
listen 80;
server_name grafana.example.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Enable caching
proxy_cache_valid 200 60m;
proxy_cache_use_stale error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_cache_key "$scheme$request_method$host$request_uri";
}
}