由于领导安排,今天遇到一个新需求,需要展示7天内cf app 高峰期cpu平均值,翻阅一看,grafana只保留了一天的数据,所以修改指标保留期限:
vi /opt/graphite/conf/storage-schemas.conf # Schema definitions for Whisper files. Entries are scanned in order, # and first match wins. This file is scanned for changes every 60 seconds. # # [name] # pattern = regex # retentions = timePerPoint:timeToStore, timePerPoint:timeToStore, ... # Carbon's internal metrics. This entry should match what is specified in # CARBON_METRIC_PREFIX and CARBON_METRIC_INTERVAL settings [carbon] pattern = ^carbon\. retentions = 60:90d [default_1min_for_1day] pattern = .* retentions = 60s:15d
修改完毕,页面指标数据依然保持一天的量,当时想当然的以为需要重启graphite使配置生效。后来验证表明,调整这里的配置后,必须删除以前生成的wsp文件,生成新的wsp文件后方可生效。
结果如下操作后,grafana报错无法正常连接sqlite数据库。
1 2 3 4 5 6 7 8 | $ cd /opt/graphite/ $ sudo ./bin/carbon-cache.py start $ sudo /etc/init.d/apache2 restart # cd /opt/graphite # PYTHONPATH=`pwd`/storage/whisper ./bin/run-graphite-devel-server.py --port=8085 --libs=`pwd`/webapp /opt/graphite 1>/opt/graphite/storage/log/webapp/process.log 2>&1 & # tail -f /opt/graphite/storage/log/webapp/process.log |
访问http://ip:8085 ,graphite webapp报出如下类似的问题.
File "/opt/graphite/webapp/graphite/urls.py", line 15, in <module> from django.conf.urls.defaults import *ImportError: No module named defaults
原因在于:Django版本变化,由原来的1.5.12升级到Django 1.6 时改变了模块结构,原先的defaults模块被去除了。查看django版本:
Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> print django.VERSION (1, 5, 12, 'final', 0) >>>
为了解决这一问题你有两种方式。
1:回滚到1.5.12
2:找到代码问题行,将此行改为
from
django.conf.urls
import
patterns, url, include
经过反复百度查阅资料,终于找到一个靠谱的解决方法:
python scirpte name: fixerrorNomodule.py import re files = ["/opt/graphite/webapp/graphite/urls.py", "/opt/graphite/webapp/graphite/urls.py", "/opt/graphite/webapp/graphite/render/urls.py", "/opt/graphite/webapp/graphite/cli/urls.py", "/opt/graphite/webapp/graphite/composer/urls.py", "/opt/graphite/webapp/graphite/metrics/urls.py", "/opt/graphite/webapp/graphite/browser/urls.py", "/opt/graphite/webapp/graphite/account/urls.py", "/opt/graphite/webapp/graphite/dashboard/urls.py", "/opt/graphite/webapp/graphite/whitelist/urls.py", "/opt/graphite/webapp/graphite/graphlot/urls.py", "/opt/graphite/webapp/graphite/version/urls.py", "/opt/graphite/webapp/graphite/events/urls.py"] files2= ["/opt/graphite/webapp/graphite/urls.py"] str = 'from django.conf.urls.defaults import *\n' for file in files: print file f = open(file, "r+") flists = f.readlines() print len(flists), for i in range(len(flists)): if flists[i] == str: print flists[i] flists[i] = "from django.conf.urls import patterns, url, include \n" else: pass f = open(file, "w+") f.writelines(flists) f.close()
修复后,再次重启服务,grafana得以回复正常。
再次提醒:调整配置后,必须删除以前生成的wsp文件,生成新的wsp文件后方可生效。