From Unix Wiki
Jump to: navigation, search

Graphite on smartos

Create user and group:

groupadd graphite
useradd -c "Graphite User" -m -d /opt/graphite -g graphite -s /bin/bash graphite

Install packages:

pkgin up
pkgin -y ug
pkgin -y in gcc47 openldap-client py27-amqplib py27-cairo py27-memcached py27-sqlite2 py27-twisted ap22-py27-wsgi-3.3

Configure Apache web server to run under 'graphite' user to avoid permission issues:

vi /opt/local/etc/httpd/includes/core.conf
- User www
- Group www
+ User graphite
+ Group graphite

Create wsgi directory:

mkdir /opt/local/etc/httpd/wsgi

Create virtual host config file: /opt/local/etc/httpd/virtualhosts/graphite.conf:

# This needs to be in your server's config somewhere, probably
# the main httpd.conf
# NameVirtualHost *:80

# This line also needs to be in your server's config.
# LoadModule wsgi_module modules/

# You need to manually edit this file to fit your needs.
# This configuration assumes the default installation prefix
# of /opt/graphite/, if you installed graphite somewhere else
# you will need to change all the occurances of /opt/graphite/
# in this file to your chosen install location.

<IfModule !wsgi_module.c>
    LoadModule wsgi_module lib/httpd/

# XXX You need to set this up!
# Read
WSGISocketPrefix etc/httpd/wsgi
WSGIPythonHome /opt/graphite

<VirtualHost *:80>
        DocumentRoot "/opt/graphite/webapp"
        ErrorLog /opt/graphite/storage/log/webapp/error.log
        CustomLog /opt/graphite/storage/log/webapp/access.log common

        # I've found that an equal number of processes & threads tends
        # to show the best performance for Graphite (ymmv).
        WSGIDaemonProcess graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120
        WSGIProcessGroup graphite
        WSGIApplicationGroup %{GLOBAL}
        WSGIImportScript /opt/graphite/conf/graphite.wsgi process-group=graphite application-group=%{GLOBAL}

        # XXX You will need to create this file! There is a graphite.wsgi.example
        # file in this directory that you can safely use, just copy it to graphite.wgsi
        WSGIScriptAlias / /opt/graphite/conf/graphite.wsgi

        Alias /content/ /opt/graphite/webapp/content/
        <Location "/content/">
                SetHandler None

        # XXX In order for the django admin site media to work you
        # must change @DJANGO_ROOT@ to be the path to your django
        # installation, which is probably something like:
        # /usr/lib/python2.6/site-packages/django
        Alias /static/admin/ "/opt/graphite/lib/python2.7/site-packages/django/contrib/admin/static/admin/"
        <Location "/media/">
                SetHandler None

        # The graphite.wsgi file has to be accessible by apache. It won't
        # be visible to clients because of the DocumentRoot though.
        <Directory /opt/graphite/conf/>
                Order deny,allow
                Allow from all

        <Directory /opt/graphite/webapp/>
                Order deny,allow
                Allow from all

        <Directory /opt/graphite/lib/python2.7/site-packages/django/contrib/admin/static/admin/>
                Order deny,alloW
                Allow from all

Switch to graphite user:

su - graphite

Dowload Virtual env script:

wget --no-check-certificate

Create Virtual Env:

python --system-site-packages /opt/graphite

Activate env:

echo "source ~/bin/activate" >> ~/.bashrc
su - graphite

Install python packages:

pip install django django-tagging django-admin-tools gunicorn python-ldap carbon whisper graphite-web

Copy configuration files (note: Standart configuration is very good):

cd ~/conf/
cp carbon.conf.example carbon.conf
cp graphite.wsgi.example graphite.wsgi
cp dashboard.conf.example dashboard.conf
cp storage-schemas.conf.example storage-schemas.conf
cp graphTemplates.conf.example graphTemplates.conf

Configure graphite:

cd ~/webapp/graphite

Uncomment and configure following:

TIME_ZONE = 'America/Los_Angeles'
GRAPHITE_ROOT = '/opt/graphite'
STORAGE_DIR = '/opt/graphite/storage'
CONTENT_DIR = '/opt/graphite/webapp/content'
DASHBOARD_CONF = '/opt/graphite/conf/dashboard.conf'
GRAPHTEMPLATES_CONF = '/opt/graphite/conf/graphTemplates.conf'
WHISPER_DIR = '/opt/graphite/storage/whisper'
RRD_DIR = '/opt/graphite/storage/rrd'
DATA_DIRS = [WHISPER_DIR, RRD_DIR] # Default: set from the above variables
LOG_DIR = '/opt/graphite/storage/log/webapp'
INDEX_FILE = '/opt/graphite/storage/index'  # Search index file
    'default': {
        'NAME': '/opt/graphite/storage/graphite.db',
        'ENGINE': 'django.db.backends.sqlite3',
#        'USER': ,
#        'PASSWORD': ,
#        'HOST': ,
#        'PORT': 


vi ~/webapp/graphite/
+ SECRET_KEY = 'secret00'

Set Allowed hosts:

vi ~/webapp/graphite/
+ ALLOWED_HOSTS = ["",""]
+ STATIC_URL = '/static/'

Create DATABASE and set Admin password:

python ~/webapp/graphite/ syncdb



Create carboon-cache service script:

cd /var/svc/manifest/site/


<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>
<service_bundle type='manifest' name='carbon-cache'>
  <service name='site/carbon-cache' type='service' version='0'>
    <create_default_instance enabled="false" />
    <single_instance />
    <dependency name='network' grouping='require_all' restart_on='error' type='service'>
      <service_fmri value='svc:/milestone/network:default' />
    <dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'>
      <service_fmri value='svc:/system/filesystem/local:default' />
    <dependency name='autofs' grouping='optional_all' restart_on='error' type='service'>
      <service_fmri value='svc:/system/filesystem/autofs:default' />
    <exec_method name='start' type='method' exec='/usr/local/svc/method/carbon-cache start' timeout_seconds='300' />
    <exec_method name='stop' type='method' exec='/usr/local/svc/method/carbon-cache stop' timeout_seconds='300' />
    <exec_method name='status' type='method' exec='/usr/local/svc/method/carbon-cache status' timeout_seconds='300' 

    <exec_method name='restart' type='method' exec='/usr/local/svc/method/carbon-cache restart' timeout_seconds='300' 

    <property_group name='startd' type='framework'>
      <propval name='ignore_error' type='astring' value='core,signal' />
    <stability value='Evolving' />
        <loctext xml:lang='C'>Carbon-cache service</loctext>
mkdir -p /usr/local/svc/method/



# Solaris carbon-cache startup script
# ident "@(#)carbon-cache SMI"


case "$1" in
  su - $USER -c "$CARBONBIN/ start"
  su - $USER -c "$CARBONBIN/ stop"
  su - $USER -c "$CARBONBIN/ status"
  su - $USER -c "$CARBONBIN/ stop"
  sleep 1
  su - $USER -c "$CARBONBIN/ start"
  echo $"Usage: $0 {start|stop|status|restart}"
  exit 1

exit 0
chmod +x /usr/local/svc/method/carbon-cache
svccfg import /var/svc/manifest/site/carbon-cache.xml

Start carbon-cache and check status:

svcadm enable carbon-cache
/usr/local/svc/method/carbon-cache status

Restart apache service:

svcadm restart apache