From 2fbb7ddf3f27c623962ba84cf1a26e7c8ebb4607 Mon Sep 17 00:00:00 2001 From: kuyan Date: Mon, 29 Jul 2013 21:59:59 -0700 Subject: [PATCH 1/4] Added note on Python 3 and Pillow. --- docs/scenarios/imaging.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/scenarios/imaging.rst b/docs/scenarios/imaging.rst index 8defa0b73..f55815797 100644 --- a/docs/scenarios/imaging.rst +++ b/docs/scenarios/imaging.rst @@ -20,8 +20,9 @@ Installation PIL has a reputation of not being very straightforward to install. Listed below are installation notes on various systems. -Also, there's a fork named `Pillow `_ which is easier -to install. It has good setup instructions for all platforms. +Also, there's a fork named `Pillow `_ which +is easier to install. It has good setup instructions for all platforms and +supports Python 3 (PIL currently does not). Installing on Linux ~~~~~~~~~~~~~~~~~~~ From 63fecf8808ed942bb7bf17eede67f8a61085653d Mon Sep 17 00:00:00 2001 From: kuyan Date: Tue, 30 Jul 2013 00:06:29 -0700 Subject: [PATCH 2/4] Completely recommend Pillow over PIL. --- docs/scenarios/imaging.rst | 63 +++++--------------------------------- 1 file changed, 8 insertions(+), 55 deletions(-) diff --git a/docs/scenarios/imaging.rst b/docs/scenarios/imaging.rst index f55815797..171043228 100644 --- a/docs/scenarios/imaging.rst +++ b/docs/scenarios/imaging.rst @@ -9,67 +9,20 @@ Python Imaging Library ---------------------- The `Python Imaging Library `_, or PIL -for short, is *the* library for image manipulation in Python. +for short, is *the* library for image manipulation in Python. Unfortunately, its +development has stagnated, with its last release in 2009. -It works with Python 1.5.2 and above, including 2.5, 2.6 and 2.7. Unfortunately, -it doesn't work with 3.0+ yet. +Lucky for you, there's an actively-developed fork of PIL called `Pillow `_ - +it's easier to install, runs on all operating systems, and supports Python 3. Installation ~~~~~~~~~~~~ -PIL has a reputation of not being very straightforward to install. Listed below -are installation notes on various systems. +Before installing Pillow, you'll have to install Pillow's prerequisites. Find +the instructions for your platform `here `_. -Also, there's a fork named `Pillow `_ which -is easier to install. It has good setup instructions for all platforms and -supports Python 3 (PIL currently does not). - -Installing on Linux -~~~~~~~~~~~~~~~~~~~ - -Arch Linux -`````````` - -PIL is maintained in the official community repository, and installed with the system installer as: - -.. code-block:: bash - - $ sudo pacman -S python2-imaging - -Ubuntu 12.10 -```````````` - -Can be installed on the command line as: - -.. code-block:: bash - - $ sudo apt-get install python-imaging - - -Installing on Mac OS X -~~~~~~~~~~~~~~~~~~~~~~ - -PIP doesn't know about the Mac OS X Freetype paths. To rectify that: - -.. code-block:: bash - - $ ln -s /usr/X11/include/freetype2 /usr/local/include/ - $ ln -s /usr/X11/include/ft2build.h /usr/local/include/ - $ ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/ - $ ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib - -then: +After that, it's straightforward: .. code-block:: bash - $ brew install libjpeg - $ pip install PIL - - -Installing on Windows -~~~~~~~~~~~~~~~~~~~~~ - -.. todo:: - Notes on installing on Windows machines - - + $ pip install Pillow From f8586cd010cad935f06fc8fbed52e47a81b2232a Mon Sep 17 00:00:00 2001 From: tommy3001 Date: Tue, 30 Jul 2013 20:25:17 +0200 Subject: [PATCH 3/4] Psutil system resources library to scenarios/admin added --- docs/scenarios/admin.rst | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 481b3410a..8260e641a 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -120,6 +120,60 @@ State files can be written using YAML, the Jinja2 template system or pure python `Salt Documentation `_ + +Psutil +------ + `Psutil `_ is an interface to different system information (e.g. CPU, memory, disks, network, users and processes). + +Here is an example to be aware of some server overload. In case of some failed test (net, CPU) it send an email. + +.. code-block:: python + + # Functions to get system values: + from psutil import cpu_percent, net_io_counters + # Functions to take a break: + from time import sleep + # Package for email services: + import smtplib + import string + MAX_NET_USAGE = 400000 + MAX_ATTACKS = 4 + attack = 0 + counter = 0 + while attack <= MAX_ATTACKS: + sleep(4) + counter = counter + 1 + # Check the cpu usage + if cpu_percent(interval = 1) > 70: + attack = attack + 1 + # Check the net usage + neti1 = net_io_counters()[1] + neto1 = net_io_counters()[0] + sleep(1) + neti2 = net_io_counters()[1] + neto2 = net_io_counters()[0] + # Calculate the bytes per second + net = ((neti2+neto2) - (neti1+neto1))/2 + if net > MAX_NET_USAGE: + attack = attack + 1 + if counter > 25: + attack = 0 + counter = 0 + # Write a very important email if attack is higher then 4 + TO = "you@your_email.com" + FROM = "webmaster@your_domain.com" + SUBJECT = "Your domain is out of system resources!" + text = "Go and fix your server!" + BODY = string.join(("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text), "\r\n") + server = smtplib.SMTP('127.0.0.1') + server.sendmail(FROM, [TO], BODY) + server.quit() + + +A full terminal application like a widely extended top which is based on psutil and with the ability of a client-server +monitoring is `glance `_. + + Chef ---- From 32a14b763e70d94c77b15a3d0356ba096d6610b5 Mon Sep 17 00:00:00 2001 From: tommy3001 Date: Tue, 30 Jul 2013 20:27:30 +0200 Subject: [PATCH 4/4] Psutil system resources library to scenarios/admin added --- docs/scenarios/admin.rst | 2 +- docs/scenarios/web.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/scenarios/admin.rst b/docs/scenarios/admin.rst index 8260e641a..081eae440 100644 --- a/docs/scenarios/admin.rst +++ b/docs/scenarios/admin.rst @@ -123,7 +123,7 @@ State files can be written using YAML, the Jinja2 template system or pure python Psutil ------ - `Psutil `_ is an interface to different system information (e.g. CPU, memory, disks, network, users and processes). +`Psutil `_ is an interface to different system information (e.g. CPU, memory, disks, network, users and processes). Here is an example to be aware of some server overload. In case of some failed test (net, CPU) it send an email. diff --git a/docs/scenarios/web.rst b/docs/scenarios/web.rst index 32a0ce231..4ec664796 100644 --- a/docs/scenarios/web.rst +++ b/docs/scenarios/web.rst @@ -319,7 +319,7 @@ to use. import tornado.ioloop import tornado.web - # Load tamplate file templates/site.html + # Load template file templates/site.html TEMPLATE_FILE = "site.html" templateLoader = FileSystemLoader( searchpath="templates/" ) templateEnv = Environment( loader=templateLoader )