| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,60 @@ State files can be written using YAML, the Jinja2 template system or pure python | |||
| 120 | 120 | ||
| 121 | 121 | `Salt Documentation <http://docs.saltstack.org/en/latest/index.html>`_ | |
| 122 | 122 | ||
| 123 | + | ||
| 124 | + Psutil | ||
| 125 | + ------ | ||
| 126 | + `Psutil <https://code.google.com/p/psutil/>`_ is an interface to different system information (e.g. CPU, memory, disks, network, users and processes). | ||
| 127 | + | ||
| 128 | + Here is an example to be aware of some server overload. In case of some failed test (net, CPU) it send an email. | ||
| 129 | + | ||
| 130 | + .. code-block:: python | ||
| 131 | + | ||
| 132 | + # Functions to get system values: | ||
| 133 | + from psutil import cpu_percent, net_io_counters | ||
| 134 | + # Functions to take a break: | ||
| 135 | + from time import sleep | ||
| 136 | + # Package for email services: | ||
| 137 | + import smtplib | ||
| 138 | + import string | ||
| 139 | + MAX_NET_USAGE = 400000 | ||
| 140 | + MAX_ATTACKS = 4 | ||
| 141 | + attack = 0 | ||
| 142 | + counter = 0 | ||
| 143 | + while attack <= MAX_ATTACKS: | ||
| 144 | + sleep(4) | ||
| 145 | + counter = counter + 1 | ||
| 146 | + # Check the cpu usage | ||
| 147 | + if cpu_percent(interval = 1) > 70: | ||
| 148 | + attack = attack + 1 | ||
| 149 | + # Check the net usage | ||
| 150 | + neti1 = net_io_counters()[1] | ||
| 151 | + neto1 = net_io_counters()[0] | ||
| 152 | + sleep(1) | ||
| 153 | + neti2 = net_io_counters()[1] | ||
| 154 | + neto2 = net_io_counters()[0] | ||
| 155 | + # Calculate the bytes per second | ||
| 156 | + net = ((neti2+neto2) - (neti1+neto1))/2 | ||
| 157 | + if net > MAX_NET_USAGE: | ||
| 158 | + attack = attack + 1 | ||
| 159 | + if counter > 25: | ||
| 160 | + attack = 0 | ||
| 161 | + counter = 0 | ||
| 162 | + # Write a very important email if attack is higher then 4 | ||
| 163 | + TO = "you@your_email.com" | ||
| 164 | + FROM = "webmaster@your_domain.com" | ||
| 165 | + SUBJECT = "Your domain is out of system resources!" | ||
| 166 | + text = "Go and fix your server!" | ||
| 167 | + BODY = string.join(("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text), "\r\n") | ||
| 168 | + server = smtplib.SMTP('127.0.0.1') | ||
| 169 | + server.sendmail(FROM, [TO], BODY) | ||
| 170 | + server.quit() | ||
| 171 | + | ||
| 172 | + | ||
| 173 | + A full terminal application like a widely extended top which is based on psutil and with the ability of a client-server | ||
| 174 | + monitoring is `glance <https://github.com/nicolargo/glances/>`_. | ||
| 175 | + | ||
| 176 | + | ||
| 123 | 177 | Chef | |
| 124 | 178 | ---- | |
| 125 | 179 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,66 +9,20 @@ Python Imaging Library | |||
| 9 | 9 | ---------------------- | |
| 10 | 10 | ||
| 11 | 11 | The `Python Imaging Library <http://www.pythonware.com/products/pil/>`_, or PIL | |
| 12 | - for short, is *the* library for image manipulation in Python. | ||
| 12 | + for short, is *the* library for image manipulation in Python. Unfortunately, its | ||
| 13 | + development has stagnated, with its last release in 2009. | ||
| 13 | 14 | ||
| 14 | - It works with Python 1.5.2 and above, including 2.5, 2.6 and 2.7. Unfortunately, | ||
| 15 | - it doesn't work with 3.0+ yet. | ||
| 15 | + Lucky for you, there's an actively-developed fork of PIL called `Pillow <http://python-imaging.github.io/>`_ - | ||
| 16 | + it's easier to install, runs on all operating systems, and supports Python 3. | ||
| 16 | 17 | ||
| 17 | 18 | Installation | |
| 18 | 19 | ~~~~~~~~~~~~ | |
| 19 | 20 | ||
| 20 | - PIL has a reputation of not being very straightforward to install. Listed below | ||
| 21 | - are installation notes on various systems. | ||
| 21 | + Before installing Pillow, you'll have to install Pillow's prerequisites. Find | ||
| 22 | + the instructions for your platform `here <https://pypi.python.org/pypi/Pillow/2.1.0#platform-specific-instructions>`_. | ||
| 22 | 23 | ||
| 23 | - Also, there's a fork named `Pillow <http://pypi.python.org/pypi/Pillow>`_ which is easier | ||
| 24 | - to install. It has good setup instructions for all platforms. | ||
| 25 | - | ||
| 26 | - Installing on Linux | ||
| 27 | - ~~~~~~~~~~~~~~~~~~~ | ||
| 28 | - | ||
| 29 | - Arch Linux | ||
| 30 | - `````````` | ||
| 31 | - | ||
| 32 | - PIL is maintained in the official community repository, and installed with the system installer as: | ||
| 33 | - | ||
| 34 | - .. code-block:: bash | ||
| 35 | - | ||
| 36 | - $ sudo pacman -S python2-imaging | ||
| 37 | - | ||
| 38 | - Ubuntu 12.10 | ||
| 39 | - ```````````` | ||
| 40 | - | ||
| 41 | - Can be installed on the command line as: | ||
| 42 | - | ||
| 43 | - .. code-block:: bash | ||
| 44 | - | ||
| 45 | - $ sudo apt-get install python-imaging | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - Installing on Mac OS X | ||
| 49 | - ~~~~~~~~~~~~~~~~~~~~~~ | ||
| 50 | - | ||
| 51 | - PIP doesn't know about the Mac OS X Freetype paths. To rectify that: | ||
| 52 | - | ||
| 53 | - .. code-block:: bash | ||
| 54 | - | ||
| 55 | - $ ln -s /usr/X11/include/freetype2 /usr/local/include/ | ||
| 56 | - $ ln -s /usr/X11/include/ft2build.h /usr/local/include/ | ||
| 57 | - $ ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/ | ||
| 58 | - $ ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib | ||
| 59 | - | ||
| 60 | - then: | ||
| 24 | + After that, it's straightforward: | ||
| 61 | 25 | ||
| 62 | 26 | .. code-block:: bash | |
| 63 | 27 | ||
| 64 | - $ brew install libjpeg | ||
| 65 | - $ pip install PIL | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - Installing on Windows | ||
| 69 | - ~~~~~~~~~~~~~~~~~~~~~ | ||
| 70 | - | ||
| 71 | - .. todo:: | ||
| 72 | - Notes on installing on Windows machines | ||
| 73 | - | ||
| 74 | - | ||
| 28 | + $ pip install Pillow | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,7 +319,7 @@ to use. | |||
| 319 | 319 | import tornado.ioloop | |
| 320 | 320 | import tornado.web | |
| 321 | 321 | ||
| 322 | - # Load tamplate file templates/site.html | ||
| 322 | + # Load template file templates/site.html | ||
| 323 | 323 | TEMPLATE_FILE = "site.html" | |
| 324 | 324 | templateLoader = FileSystemLoader( searchpath="templates/" ) | |
| 325 | 325 | templateEnv = Environment( loader=templateLoader ) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments