使用graphite和cabot搭建监控服务 一时失言乱红尘 2021-06-24 14:35 424阅读 0赞 说起监控,我们一般会首先想到zabbix,nagios,ganglia等等。但是对于非ops开发人员而言,这些东西,多多少少让人感到陌生。所以本文将从一个服务端开发人员的视角,介绍如何通过graphite,cabot,加一个shell定时脚本,搭建监控报警服务。 python环境安装 虽然linux系统上一般都有python环境,但是默认的python版本较低。而且yum等系统工具,都依赖于默认的python。所以推荐的做法是再安装一个python,并使用virtualenv等工具,分项目进行环境管理,并与系统默认的python环境进行隔离。 以python2.7.3为例,介绍python环境的安装。 sudo yum install bzip2-devel.x86_64 sudo yum install sqlite-devel.x86_64 sudo yum install readline-devel.x86_64 sudo yum install openssl-devel.x86_64 wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 tar jxvf Python-2.7.3.tar.bz2 cd Python-2.7.3 ./configure --prefix=/usr/local/python2.7.3 make && sudo make install cd .. wget https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz --no-check-certificate tar zxvf distribute-0.6.49.tar.gz cd distribute-0.6.49 sudo /usr/local/python2.7.3/bin/python setup.py install sudo /usr/local/python2.7.3/bin/easy_install pbr cd .. wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.10.1.tar.gz --no-check-certificate tar zxvf virtualenv-1.10.1.tar.gz cd virtualenv-1.10.1 sudo /usr/local/python2.7.3/bin/python setup.py install sudo /usr/local/python2.7.3/bin/easy_install virtualenvwrapper 如果遇到 \[FATAL\] Failed to create text with cairo, this probably means cairo cant find any fonts. Install some system fonts and try again。可以尝试安装bitmap font。 sudo yum install bitmap.x86_64 sudo yum install bitmap-fonts-compat.noarch 相关配置 创建管理python环境的用户 为了便于环境的统一管理,创建一个普通用户进行新创建python环境的管理和相关python扩展的安装。同时,向数字公司的addops们致敬。 useradd appops 创建python环境安装目录 sudo mkdir -p /data/server/python-envs sudo chown -R appops.appops /data/server 配置新安装的python2.7.3环境 sudo su appops -c 'vim ~/.bashrc' 添加如下内容 export WORKON_HOME=/data/server/python-envs export VIRTUALENVWRAPPER_PYTHON=/usr/local/python2.7.3/bin/python export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/python2.7.3/bin/virtualenv source /usr/local/python2.7.3/bin/virtualenvwrapper.sh 搭建graphite监控服务 安装步骤 创建目录: sudo mkdir /opt/graphite sudo chown -R appops.appops /opt/graphite 创建python虚拟环境: sudo su appops source ~/.bashrc mkvirtualenv graphite graphite安装: pip install whisper pip install carbon pip install graphite-web pip install django==1.5 pip install django-tagging pip install uwsgi pip install MySQL-python pip install daemonize graphite使用cairo进行绘图,由于系统自带的cairo版本较低(需要cairo1.10以上),使用pip安装cairo会出错,所以采用编译安装。 wget http://cairographics.org/releases/pycairo-1.8.8.tar.gz tar zxvf pycairo-1.8.8.tar.gz python -c "import sys; print sys.prefix" cd pycairo-1.8.8 ./configure --prefix=/data/server/python-envs/graphite make make install 目录说明: bin -- 数据收集相关工具 conf -- 数据存储相关配置文件 carbon.conf -- 数据收集carbon进程涉及的配置 dashboard.conf -- Dashboard UI相关配置 graphite.wsgi -- wsgi相关配置 storage-schemas.conf -- Schema definitions for Whisper files whitelist.conf -- 定义允许存储的metrics白名单 graphTemplates.conf -- 图形化展示数据时使用的模板 examples -- 示例脚本 lib -- carbon和twisted库 storage -- 数据文件存储目录 webapp -- 数据前端展示涉及程序 配置graphite-web 初始化配置文件 cd /opt/graphite/webapp/graphite cp local_settings.py.example local_settings.py cp /opt/graphite/conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi cp /opt/graphite/conf/graphTemplates.conf.example /opt/graphite/conf/graphTemplates.conf cp /opt/graphite/conf/dashboard.conf.example /opt/graphite/conf/dashboard.conf 初始化数据库 python manage.py syncdb 启动: uwsgi --http localhost:8085 --master --processes 1 --home /data/server/python-envs/graphite --pythonpath /opt/graphite/webapp/graphite --wsgi-file=/opt/graphite/conf/graphite.wsgi --enable-threads --thunder-lock 参考:http://wrox.cn/article/100000312/
还没有评论,来说两句吧...