多数のグラファイト+ virtualenv + collectdをセットアップします

この記事では、 グラファイトと連携して収集された統計の収集および視覚化統計サービスを設定した経験を共有したいと思います。 1つ目はデータコレクタとして使用され、2つ目はビジュアライザを備えたリポジトリとして使用されます。



やる気



最近まで、統計を収集して表示するためにMuninを使用していましたが、そのグラフは常に私を悩ませました(外観)理由はわかりません。 さらに、更新後、何かが絶えず落ちてしまい、気になりました。 これらすべてに関連して、私は代替手段を探すことにし、collectdに出会いました。 一般的に、彼は私にふさわしい代替品のように見えましたが、私が彼を探していたすべてのWebビジュアライザーは私には少し悲惨なようでした。 そして、最近、職場でグラファイトを設置したことを思い出しました。 私はそれから来るものを試してみることにしました。



目的



スーパーバイザー、uwsgi、virtualenvを使用して動作し、外部(nginx)から見えるようにグラファイトを構成します。 同時に収集すると、グラファイトデータが直接得られます。



黒鉛


まず、グラファイトが存在するディレクトリを作成し、そこに仮想環境を展開する必要があります。

$ mkdir /var/projects/graphite $ cd /var/projects/graphite $ virtualenv --no-site-packages .env $ virtualenv --relocatable .env $ source .env/bin/activate
      
      





画像を操作するには、グラファイトはcairoを使用するため、このライブラリがシステムにインストールされている必要があります。 私の場合、すべてがすでにそこにあるので、仮想環境にpycarioをインストールする方法のみを説明します。



py2cairoをダウンロードしてインストールする


 $ wget http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2 $ tar -jxf py2cairo-1.10.0.tar.bz2 && cd py2cairo-1.8.10 $ ./waf configure --prefix=$VIRTUAL_ENV $ ./waf build $ ./waf install $ cd .. && rm -R py2cairo-1.8.10 && rm py2cairo-1.10.0.tar.bz2
      
      





ささやき


 $ wget https://launchpad.net/graphite/0.9/0.9.9/+download/whisper-0.9.9.tar.gz $ tar -xzpf whisper-0.9.9.tar.gz && cd whisper-0.9.9 $ python setup.py install $ cd .. && rm -R whisper-0.9.9 && rm whisper-0.9.9.tar.gz
      
      





カーボンを入れる


 $ wget https://launchpad.net/graphite/0.9/0.9.9/+download/carbon-0.9.9.tar.gz $ tar -xzpf carbon-0.9.9.tar.gz && cd carbon-0.9.9
      
      





すべてをサンドボックスにインストールするために、setup.cfgファイルで以下を変更します。

prefix = /opt/graphite





に:

prefix = $VIRTUAL_ENV/..





その後:

 $ python setup.py install $ cd .. && rm -R carbon-0.9.9 && rm carbon-0.9.9.tar.gz
      
      





グラファイト(webapp)を入れます


 $ wget https://launchpad.net/graphite/0.9/0.9.9/+download/graphite-web-0.9.9.tar.gz $ tar -xzpf graphite-web-0.9.9.tar.gz && cd graphite-web-0.9.9
      
      





check-dependencies.pyを使用して、他に何をインストールする必要があるかをチェックします。私の場合は次のとおりです。

 $ pip install django django-tagging twisted python-memcached psycopg2 egenix-mx-base
      
      





後者は、原則として、意のままですが、私はまだ持っているので、そうしようと思いました。

カーボンとの類推により、setup.cfgファイルで以下を変更します。

prefix = /opt/graphite





に:

prefix = $VIRTUAL_ENV/..





その後:

 $ python setup.py install $ cd .. && rm -R graphite-web-0.9.9 && rm graphite-web-0.9.9.tar.gz
      
      





カーボンとグラファイトをカスタマイズする


Supervisordの構成ファイルは次のようになります。

 [program:graphite_uwsgi] command=/usr/bin/uwsgi --pidfile /var/projects/graphite/run/graphite_uwsgi.pid -x /var/projects/graphite/conf/uwsgi.conf --vacuum directory=/var/projects/graphite/webapp/ autostart=true autorestart=true startsecs=5 startretries=3 stopsignal=TERM stopwaitsecs=15 stopretries=1 stopsignal=QUIT redirect_stderr=false stdout_logfile=/var/projects/graphite/storage/log/graphite_uwsgi.log stdout_logfile_maxbytes=1MB stdout_logfile_backups=10 stdout_capture_maxbytes=1MB stderr_logfile=/var/projects/graphite/storage/log/graphite_uwsgi-error.log stderr_logfile_maxbytes=1MB stderr_logfile_backups=10 stderr_capture_maxbytes=1MB [program:carbon] command=/var/projects/graphite/.env/bin/python /var/projects/graphite/bin/carbon-cache.py --debug start priority=1 autostart=true autorestart=true startsecs=3 redirect_stderr=false stdout_logfile=/var/projects/graphite/storage/log/carbon.log stdout_logfile_maxbytes=1MB stdout_logfile_backups=10 stdout_capture_maxbytes=1MB stderr_logfile=/var/projects/graphite/storage/log/carbon-error.log stderr_logfile_maxbytes=1MB stderr_logfile_backups=10 stderr_capture_maxbytes=1MB
      
      





グラファイトバックエンドとカーボンサーバーの実行方法を示します。 私の場合、このファイルをサンドボックスのconfディレクトリに配置し、supervisordが見つけるディレクトリにリンクを作成します。

次に、次のようなuwsgiの構成を作成しています。

 <uwsgi> <socket>127.0.0.1:8001</socket> <processes>2</processes> <home>/var/projects/graphite/.env</home> <pythonpath>/var/projects/graphite/webapp/</pythonpath> <chdir>/var/projects/graphite/webapp</chdir> <max-requests>2000</max-requests> <touch-reload>/var/projects/graphite/uwsgi.reload</touch-reload> <harakiri>120</harakiri> <post-buffering>8192</post-buffering> <post-buffering-bufsize>65536</post-buffering-bufsize> <master/> <single-interpreter/> <env>DJANGO_SETTINGS_MODULE=graphite.settings</env> <module>wsgi</module> </uwsgi>
      
      





モジュールディレクティブは、起動するPythonモジュールを指します。 基礎として、私はすぐそこにあるgraph.wsgi.exampleを取り、それを修正して、/ var / projects / graphite / webapp ディレクトリにwsgi.pyという名前で入れました。 編集後、彼は次のようになり始めました。

 import os import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() # READ THIS # Initializing the search index can be very expensive, please include # the WSGIScriptImport directive pointing to this script in your vhost # config to ensure the index is preloaded before any requests are handed # to the process. from graphite.logger import log log.info("graphite.wsgi - pid %d - reloading search index" % os.getpid()) import graphite.metrics.search
      
      





次に、confディレクトリで、いくつかのファイルの名前を変更します。

 $ mv carbon.conf.example carbon.conf $ mv storage-schemas.conf.example storage-schemas.conf
      
      





さらに、webapp /グラファイトディレクトリで、設定ファイルの名前を変更する必要があります。

 $ mv local_settings.py.example local_settings.py
      
      





また、このファイルに必要な変更を加えることをお勧めします。たとえば、そこにposgresqlにアクセスするための設定を入力しました。

local_settingsを編集した後、グラファイトデータベースを初期化するには、実行して指示に従う必要があります。

 $ python webapp/graphite/manage.py syncdb
      
      





グラファイト用Nginx


次のようなファイルを作成しました。

 server { access_log /var/projects/graphite/storage/log/nginx.access.log main; error_log /var/projects/graphite/storage/log/nginx.error.log info; listen 80; server_name graphite.some_site.com; root /var/projects/graphite/webapp/; location / { include /etc/nginx/uwsgi_params; uwsgi_pass 127.0.0.1:8001; } location /content/ { access_log off; expires 30d; } }
      
      





スーパーバイザーおよびuwsgiの上記のファイルの横にあるサンドボックスconfディレクトリに保存し、nginx.confという名前を付けて、nginx仮想ホストディレクトリにシンボリックリンクを作成しました。



打ち上げ


Supervisordとnginxを再起動する前に、nginxとSupervisordが起動するユーザーがファイルとディレクトリを読み取りできるように、サンドボックスディレクトリの権限を修正する必要があります。 さらに、これらのユーザーには、ストレージディレクトリの実行を許可する必要があります。 私の場合、スーパーバイザーとnginxの両方がwwwグループに属しているため、次のことを行います。

 $ mkdir /var/projects/graphite/run $ chown myuser:www -R /var/projects/graphite $ cd /var/projects/graphite $ chmod -R 770 storage run
      
      





それだけです。supervisordとnginxを再起動してください。 ストレージ内のログから、すべてが正常であることがわかります。指定されたアドレスのブラウザーには、グラファイトがあります。



収集した


ここではすべてがはるかに簡単です:-)最初に、必要なプラグインのセットを使用してシステムにcollectdをインストールする必要があります。 特定のディストリビューションにアプリケーションをインストールする方法は誰もが知っているため、このプロセスについては説明しません。

このサービスはデータストレージを必要としないため、rrd *をインストールしませんでした。 rrftoolの代わりに、グラファイトが使用されます。 収集したデータを必要な場所に転送するには、これを行うプラグインをインストールする必要があります。 Pythonで書かれたcollectd-carbonを選択しました 。 最初はCで書かれたプラグイン( collectd-write_graphite )を使用しようとしましたが、すぐに動作しました。メトリックの奇妙な名前だけが送信され、拒否しました。

プラグインの設定はシンプルで簡単で、上記のリンクのgithubで表示できます。



まとめ


目標が達成されたので、おそらく私はそれを終えるでしょう。 このバンドルを使用してホームサーバーの統計を表示し、近い将来、いくつかの外部マシンからの送信データをここに追加する予定です。 したがって、グラファイトは統計情報のアグリゲーターとして機能します。

ご清聴ありがとうございました。この投稿が他の誰かに役立つことを願っています。 それが少し長いことが判明した場合(そして、いくつかの場所で非常にスムーズではないかもしれません)、私は謝罪します。



参照資料


http://graphite.readthedocs.org/en/1.0/index.html

http://www.frlinux.eu/?p=199

http://graphite.wikidot.com/

http://mldav.blogspot.com/2011/10/debian-graphite.html

http://collectd.org/



PS


「体の動き」について。 これは、何らかの理由で、例えば3 +環境をセットアップする小さなスクリプトの代わりに1つのパッケージを作成することを気にしなかったグラファイト開発者の方向性の石です。



All Articles