egghead avatar egghead committed acb9395

initial commit - using json short polls

Comments (0)

Files changed (21)

+0.0
+---
+
+-  Initial version
+include *.txt *.ini *.cfg *.rst
+recursive-include sysmon *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml
+sysmon README
+---------
+
+a simple system monitor reading memory and cpu usage to a html5 canvas
+project requires psutil, pyramid and (eventually) hookbox for websocket support
+[app:sysmon]
+use = egg:sysmon
+reload_templates = true
+mako.directories = sysmon:templates
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = true
+default_locale_name = en
+
+[pipeline:main]
+pipeline =
+    egg:WebError#evalerror
+    sysmon
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 7777
+
+# Begin logging configuration
+
+[loggers]
+keys = root, sysmon
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_sysmon]
+level = DEBUG
+handlers =
+qualname = sysmon
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
+
+# End logging configuration
+[app:sysmon]
+use = egg:sysmon
+reload_templates = false
+debug_authorization = false
+debug_notfound = false
+debug_routematch = false
+debug_templates = false
+default_locale_name = en
+
+[filter:weberror]
+use = egg:WebError#error_catcher
+debug = false
+;error_log = 
+;show_exceptions_in_wsgi_errors = true
+;smtp_server = localhost
+;error_email = janitor@example.com
+;smtp_username = janitor
+;smtp_password = "janitor's password"
+;from_address = paste@localhost
+;error_subject_prefix = "Pyramid Error"
+;smtp_use_tls =
+;error_message =
+
+[pipeline:main]
+pipeline =
+    weberror
+    sysmon
+
+[server:main]
+use = egg:Paste#http
+host = 0.0.0.0
+port = 6543
+
+# Begin logging configuration
+
+[loggers]
+keys = root, sysmon
+
+[handlers]
+keys = console
+
+[formatters]
+keys = generic
+
+[logger_root]
+level = WARN
+handlers = console
+
+[logger_sysmon]
+level = WARN
+handlers =
+qualname = sysmon
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[formatter_generic]
+format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
+
+# End logging configuration
+[nosetests]
+match = ^test
+nocapture = 1
+cover-package = sysmon
+with-coverage = 1
+cover-erase = 1
+
+[compile_catalog]
+directory = sysmon/locale
+domain = sysmon
+statistics = true
+
+[extract_messages]
+add_comments = TRANSLATORS:
+output_file = sysmon/locale/sysmon.pot
+width = 80
+
+[init_catalog]
+domain = sysmon
+input_file = sysmon/locale/sysmon.pot
+output_dir = sysmon/locale
+
+[update_catalog]
+domain = sysmon
+input_file = sysmon/locale/sysmon.pot
+output_dir = sysmon/locale
+previous = true
+import os
+
+from setuptools import setup, find_packages
+
+here = os.path.abspath(os.path.dirname(__file__))
+README = open(os.path.join(here, 'README.txt')).read()
+CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
+
+requires = ['pyramid', 'WebError']
+
+setup(name='sysmon',
+      version='0.0',
+      description='sysmon',
+      long_description=README + '\n\n' +  CHANGES,
+      classifiers=[
+        "Programming Language :: Python",
+        "Framework :: Pylons",
+        "Topic :: Internet :: WWW/HTTP",
+        "Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
+        ],
+      author='',
+      author_email='',
+      url='',
+      keywords='web pyramid pylons',
+      packages=find_packages(),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=requires,
+      tests_require=requires,
+      test_suite="sysmon",
+      entry_points = """\
+      [paste.app_factory]
+      main = sysmon:main
+      """,
+      paster_plugins=['pyramid'],
+      )
+

sysmon.egg-info/PKG-INFO

+Metadata-Version: 1.0
+Name: sysmon
+Version: 0.0
+Summary: sysmon
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: UNKNOWN
+Description: sysmon README
+        
+        
+        
+        
+        
+        0.0
+        ---
+        
+        -  Initial version
+        
+Keywords: web pyramid pylons
+Platform: UNKNOWN
+Classifier: Programming Language :: Python
+Classifier: Framework :: Pylons
+Classifier: Topic :: Internet :: WWW/HTTP
+Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application

sysmon.egg-info/SOURCES.txt

+CHANGES.txt
+MANIFEST.in
+README.txt
+development.ini
+production.ini
+setup.cfg
+setup.py
+sysmon/__init__.py
+sysmon/resources.py
+sysmon/tests.py
+sysmon/views.py
+sysmon.egg-info/PKG-INFO
+sysmon.egg-info/SOURCES.txt
+sysmon.egg-info/dependency_links.txt
+sysmon.egg-info/entry_points.txt
+sysmon.egg-info/not-zip-safe
+sysmon.egg-info/paster_plugins.txt
+sysmon.egg-info/requires.txt
+sysmon.egg-info/top_level.txt
+sysmon/static/favicon.ico
+sysmon/static/footerbg.png
+sysmon/static/headerbg.png
+sysmon/static/ie6.css
+sysmon/static/middlebg.png
+sysmon/static/pylons.css
+sysmon/static/pyramid-small.png
+sysmon/static/pyramid.png
+sysmon/static/transparent.gif
+sysmon/templates/mytemplate.pt

sysmon.egg-info/dependency_links.txt

+

sysmon.egg-info/entry_points.txt

+      [paste.app_factory]
+      main = sysmon:main
+      

sysmon.egg-info/not-zip-safe

+

sysmon.egg-info/paster_plugins.txt

+pyramid

sysmon.egg-info/requires.txt

+pyramid
+WebError

sysmon.egg-info/top_level.txt

+sysmon

sysmon/__init__.py

+from pyramid.config import Configurator
+from sysmon.resources import Root
+
+def main(global_config, **settings):
+    """ This function returns a Pyramid WSGI application.
+    """
+    config = Configurator(root_factory=Root, settings=settings)
+    config.scan()
+    config.add_static_view('static', 'sysmon:static')
+    return config.make_wsgi_app()

sysmon/resources.py

+class Root(object):
+    def __init__(self, request):
+        self.request = request

sysmon/static/app.js

+var cpu_smoothie = new SmoothieChart({
+  grid: {
+    lineWidth: 1,
+    verticalSections: 3
+  },
+});
+var pmem_smoothie = new SmoothieChart({
+  grid: {
+    lineWidth: 1,
+    verticalSections: 3
+  },
+});
+var vmem_smoothie = new SmoothieChart({
+  grid: {
+    lineWidth: 1,
+    verticalSections: 3
+  },
+});
+cpu_smoothie.streamTo(document.getElementById('cpu'), 1000);
+pmem_smoothie.streamTo(document.getElementById('pmem'), 1000);
+vmem_smoothie.streamTo(document.getElementById('vmem'), 1000);
+var cpu_line = new TimeSeries();
+var mem_line_phys = new TimeSeries();
+var mem_line_virt = new TimeSeries();
+setInterval(function () {
+  $.getJSON('/cpu', function(data) {
+    $.each(data, function(k, v) {
+      cpu_line.append(new Date().getTime(), v);
+    });
+  });
+  $.getJSON('/mem', function(data) {
+    $.each(data, function(k, v) {
+      if (k == 'physical_memory_percent') {
+        mem_line_phys.append(new Date().getTime(), v);
+      } else if (k == 'virtual_memory_percent') {
+        mem_line_virt.append(new Date().getTime(), v);
+      };
+    });
+  });
+}, 1000);
+cpu_smoothie.addTimeSeries(cpu_line, {
+  lineWidth: 3
+});
+pmem_smoothie.addTimeSeries(mem_line_phys, {
+  lineWidth: 3
+});
+vmem_smoothie.addTimeSeries(mem_line_virt, {
+  lineWidth: 3
+});

sysmon/templates/index.mak

+<!DOCTYPE html>
+<html lang='en'>
+<head>
+  <meta charset='utf-8'>
+  <title>slyph system info</title>
+  <script src='https://github.com/joewalnes/smoothie/raw/master/smoothie.js'></script>
+  <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js'></script>
+  <style>
+    body, html{
+	  width: 100%;
+	  height: 100%;
+	}
+	body{
+	  background-color: black;
+      color: #ccc;
+	  font-size: 18px;
+	}
+  </style>
+</head>
+<body>
+  <h1>CPU Usage (%)</h1>
+  <canvas id='cpu' width='800' height ='100'></canvas>
+  <h1>Physical Memory Usage (%)</h1>
+  <canvas id='pmem' width='800' height='100'></canvas>
+  <h1>Virtual Memory Usage (%)</h1>
+  <canvas id='vmem' width='800' height='100'></canvas>
+  <script src='/static/app.js'></script>
+</body>
+import unittest
+
+from pyramid import testing
+
+class ViewTests(unittest.TestCase):
+    def setUp(self):
+        self.config = testing.setUp()
+
+    def tearDown(self):
+        testing.tearDown()
+
+    def test_my_view(self):
+        from sysmon.views import my_view
+        request = testing.DummyRequest()
+        info = my_view(request)
+        self.assertEqual(info['project'], 'sysmon')
+from pyramid.view import view_config
+import psutil
+
+@view_config(renderer='index.mak')
+def index(request):
+    return {}
+
+@view_config(name='cpu', renderer='json')
+def cpuinfo(request):
+    cpu_percent = psutil.cpu_percent(interval=0.1)
+    return {'cpu_percent':cpu_percent}
+
+@view_config(name='mem', renderer='json')
+def meminfo(request):
+    total_physmem = psutil.TOTAL_PHYMEM
+    avail_physmem = psutil.avail_phymem()
+    phys_perc = (total_physmem - avail_physmem) / float(total_physmem)
+    total_virtmem = psutil.total_virtmem()
+    avail_virtmem = psutil.avail_virtmem()
+    virt_perc = (total_virtmem - avail_virtmem) / float(total_virtmem)
+    return {'physical_memory_percent': phys_perc,
+            'virtual_memory_percent': virt_perc}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.