Permalink
Browse files

Added support for multiple hosts.

  • Loading branch information...
Jahaja committed Aug 17, 2014
1 parent f5c860a commit d6e1b39fa3a05259cdfc8a16c3fd84f740fd9fb5
Showing with 552 additions and 255 deletions.
  1. +4 −0 CHANGELOG
  2. +1 −0 Vagrantfile
  3. +2 −4 psdash/net.py
  4. +61 −8 psdash/node.py
  5. +172 −51 psdash/run.py
  6. +64 −50 psdash/templates/base.html
  7. +59 −80 psdash/web.py
  8. +3 −1 setup.py
  9. +7 −4 tests/test_log.py
  10. +42 −41 tests/test_node.py
  11. +118 −9 tests/test_run.py
  12. +19 −7 tests/test_web.py
View
@@ -1,5 +1,9 @@
--- v0.5.0 [Not released] ---
* [NEW] Added support for multiple hosts.
* [NEW] Changed to using the netifaces lib for reading the host ip-address. (Thanks to Leonardo Santagada)
* [NEW] Made it possible to filter on remote/local address port on the system-wide connections page.
--- v0.4.0 [2014-07-24] ---
View
@@ -14,6 +14,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.hostname = "%s" % box[:hostname]
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", box[:ram]]
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
config.vm.network :forwarded_port, guest: 5000, host: 5000
config.vm.provision "shell", path: "vagrant.sh"
View
@@ -1,7 +1,5 @@
# coding=utf-8
import socket
import struct
import psutil
import time
import netifaces
@@ -60,7 +58,7 @@ def update(self):
return counters
def get_interface_addresses(max_interfaces=10):
def get_interface_addresses():
"""
Get addresses of available network interfaces.
See netifaces on pypi for details.
@@ -69,7 +67,7 @@ def get_interface_addresses(max_interfaces=10):
"""
addresses = []
ifaces = netifaces.interfaces()[:max_interfaces]
ifaces = netifaces.interfaces()
for iface in ifaces:
addrs = netifaces.ifaddresses(iface)
families = addrs.keys()
View
@@ -2,21 +2,74 @@
import logging
import os
import platform
from psdash.log import Logs
from psdash.helpers import socket_families, socket_types
from psdash.net import get_interface_addresses, NetIOCounters
import psutil
import socket
import time
import zerorpc
from psdash.log import Logs
from psdash.helpers import socket_families, socket_types
from psdash.net import get_interface_addresses, NetIOCounters
logger = logging.getLogger("psdash.node")
class Node(object):
def __init__(self):
self._service = None
def get_id(self):
raise NotImplementedError
def _create_service(self):
raise NotImplementedError
def get_service(self):
if not self._service:
self._service = self._create_service()
return self._service
class RemoteNode(Node):
def __init__(self, name, host, port):
super(RemoteNode, self).__init__()
self.name = name
self.host = host
self.port = int(port)
self.last_registered = None
def _create_service(self):
logger.info('Connecting to node %s', self.get_id())
c = zerorpc.Client()
c.connect('tcp://%s:%s' % (self.host, self.port))
logger.info('Connected.')
return c
def get_id(self):
return '%s:%s' % (self.host, self.port)
def update_last_registered(self):
self.last_registered = int(time.time())
class LocalNode(Node):
def __init__(self):
super(LocalNode, self).__init__()
self.name = "psDash"
self.net_io_counters = NetIOCounters()
self.logs = Logs()
def get_id(self):
return 'localhost'
def _create_service(self):
return LocalService(self)
class LocalService(object):
def __init__(self, node):
self.node = node
def get_sysinfo(self):
uptime = int(time.time() - psutil.boot_time())
sysinfo = {
@@ -75,7 +128,7 @@ def get_users(self):
return [u._asdict() for u in psutil.users()]
def get_network_interfaces(self):
io_counters = self.net_io_counters.get()
io_counters = self.node.net_io_counters.get()
addresses = get_interface_addresses()
netifs = {}
@@ -268,7 +321,7 @@ def get_connections(self, filters=None):
def get_logs(self):
available_logs = []
for log in self.logs.get_available():
for log in self.node.logs.get_available():
try:
stat = os.stat(log.filename)
available_logs.append({
@@ -279,18 +332,18 @@ def get_logs(self):
})
except OSError:
logger.info('Could not stat "%s", removing from available logs', log.filename)
self.logs.remove_available(log.filename)
self.node.logs.remove_available(log.filename)
return available_logs
def read_log(self, filename, session_key=None, seek_tail=False):
log = self.logs.get(filename, key=session_key)
log = self.node.logs.get(filename, key=session_key)
if seek_tail:
log.set_tail_position()
return log.read()
def search_log(self, filename, text, session_key=None):
log = self.logs.get(filename, key=session_key)
log = self.node.logs.get(filename, key=session_key)
pos, bufferpos, res = log.search(text)
stat = os.stat(log.filename)
data = {
Oops, something went wrong.

0 comments on commit d6e1b39

Please sign in to comment.