绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
graphite+grafana 修改指标存放时间后重启失败
2022-04-21 14:20:18

由于领导安排,今天遇到一个新需求,需要展示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文件后方可生效。

分享好友

分享这个小栈给你的朋友们,一起进步吧。

Graphite
创建时间:2022-04-21 10:18:11
Graphite
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • LCR_
    专家
戳我,来吐槽~