From bcdd2e401316548cbd0741f4a9e58761b002e1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 23 Apr 2014 12:53:48 +0200 Subject: [PATCH 1/5] added stats display --- .../libraries/Maven__log4j_log4j_1_2_9.xml | 13 +++ .../Maven__org_snmp4j_snmp4j_1_9_1f.xml | 13 +++ healthdisplay/healthdisplay.iml | 2 + healthdisplay/pom.xml | 5 ++ .../main/java/de/psychose/ActorDisplay.form | 20 ++--- .../main/java/de/psychose/ActorDisplay.java | 7 +- .../src/main/java/de/psychose/MainForm.java | 26 +++++- .../main/java/de/psychose/SnmpStatClient.java | 81 +++++++++++++++++++ .../main/java/de/psychose/StatsDisplay.form | 46 ++++++++--- .../main/java/de/psychose/StatsDisplay.java | 10 +++ .../src/main/java/de/psychose/Test.java | 7 ++ 11 files changed, 197 insertions(+), 33 deletions(-) create mode 100644 healthdisplay/.idea/libraries/Maven__log4j_log4j_1_2_9.xml create mode 100644 healthdisplay/.idea/libraries/Maven__org_snmp4j_snmp4j_1_9_1f.xml create mode 100644 healthdisplay/src/main/java/de/psychose/SnmpStatClient.java diff --git a/healthdisplay/.idea/libraries/Maven__log4j_log4j_1_2_9.xml b/healthdisplay/.idea/libraries/Maven__log4j_log4j_1_2_9.xml new file mode 100644 index 0000000..37a2238 --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__log4j_log4j_1_2_9.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/libraries/Maven__org_snmp4j_snmp4j_1_9_1f.xml b/healthdisplay/.idea/libraries/Maven__org_snmp4j_snmp4j_1_9_1f.xml new file mode 100644 index 0000000..31252ff --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__org_snmp4j_snmp4j_1_9_1f.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/healthdisplay.iml b/healthdisplay/healthdisplay.iml index 8a76843..d987de2 100644 --- a/healthdisplay/healthdisplay.iml +++ b/healthdisplay/healthdisplay.iml @@ -17,6 +17,8 @@ + + diff --git a/healthdisplay/pom.xml b/healthdisplay/pom.xml index 30de015..53cfc74 100644 --- a/healthdisplay/pom.xml +++ b/healthdisplay/pom.xml @@ -25,6 +25,11 @@ forms_rt 7.0.3 + + org.snmp4j + snmp4j + 1.9.1f + diff --git a/healthdisplay/src/main/java/de/psychose/ActorDisplay.form b/healthdisplay/src/main/java/de/psychose/ActorDisplay.form index 1884b4e..d72dc0a 100644 --- a/healthdisplay/src/main/java/de/psychose/ActorDisplay.form +++ b/healthdisplay/src/main/java/de/psychose/ActorDisplay.form @@ -140,16 +140,6 @@ - - - - - - - - - - @@ -170,6 +160,16 @@ + + + + + + + + + + diff --git a/healthdisplay/src/main/java/de/psychose/ActorDisplay.java b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java index 542cd83..abef1e0 100644 --- a/healthdisplay/src/main/java/de/psychose/ActorDisplay.java +++ b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java @@ -3,7 +3,6 @@ package de.psychose; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; -import java.util.Random; /** * @author: lucas @@ -73,14 +72,10 @@ public class ActorDisplay { } public ActorDisplay() { - final Random r = new Random(); - final Timer timer = new Timer(100, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { -// actorPanel.setBackground(new Color(r.nextInt(), false)); - if (++counterTemperature > timeout) { lblTemperature.setForeground(offColor); } else { @@ -113,6 +108,7 @@ public class ActorDisplay { if (++counterHeartbeat > timeout) { lblHeartbeat.setForeground(offColor); + lblHeartbeat.setText("no data"); } else { lblHeartbeat.setForeground(onColor); } @@ -122,7 +118,6 @@ public class ActorDisplay { } else { lblBreath.setForeground(onColor); } - } }); timer.setRepeats(true); diff --git a/healthdisplay/src/main/java/de/psychose/MainForm.java b/healthdisplay/src/main/java/de/psychose/MainForm.java index d4cd4b1..45fe384 100644 --- a/healthdisplay/src/main/java/de/psychose/MainForm.java +++ b/healthdisplay/src/main/java/de/psychose/MainForm.java @@ -17,6 +17,7 @@ import java.util.Date; */ public class MainForm { private ChaOSCclient osCclient; + private SnmpStatClient snmpStatClient; private JPanel mainPanel; private ActorDisplay actor1; @@ -27,8 +28,12 @@ public class MainForm { private int totalMessageCount = 0; private int messagesTempCounter = 0; - public MainForm(ChaOSCclient chaOSCclient) { - osCclient = chaOSCclient; + private long totalTraffic = 0; + private long lastTraffic = 0; + + public MainForm(final ChaOSCclient chaOSCclient, final SnmpStatClient snmpStatClient) { + this.osCclient = chaOSCclient; + this.snmpStatClient = snmpStatClient; addActor("merle", "Proband 1", actor1); addActor("uwe", "Proband 2", actor2); @@ -46,6 +51,18 @@ public class MainForm { }); timer.setRepeats(true); timer.start(); + + final Timer snmpTimer = new Timer(5000, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + totalTraffic = snmpStatClient.getTrafficSum(); + statDisplay.setTotalTraffic(String.valueOf(totalTraffic / 1024)); + statDisplay.setBandwidth(String.valueOf((totalTraffic - lastTraffic) / 1024 / 5)); + lastTraffic = totalTraffic; + } + }); + snmpTimer.setRepeats(true); + snmpTimer.start(); } @@ -56,7 +73,7 @@ public class MainForm { public void acceptMessage(Date time, OSCMessage message) { if (message.getArguments().length == 3) { totalMessageCount++; - actorDisplay.setHeartbeat(message.getArguments()[0].toString()); + actorDisplay.setHeartbeat(message.getArguments()[0].toString().equals("0") ? "Systole" : "Diastole"); actorDisplay.setPulse(message.getArguments()[1].toString()); actorDisplay.setOxy(message.getArguments()[2].toString()); } @@ -111,7 +128,8 @@ public class MainForm { try { final ChaOSCclient chaOSCclient = new ChaOSCclient(host, port); - final MainForm mainForm = new MainForm(chaOSCclient); + final SnmpStatClient snmp = new SnmpStatClient("switch/161"); + final MainForm mainForm = new MainForm(chaOSCclient, snmp); final JFrame frame = new JFrame("MainForm"); frame.setContentPane(mainForm.mainPanel); frame.setResizable(false); diff --git a/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java b/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java new file mode 100644 index 0000000..5825031 --- /dev/null +++ b/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java @@ -0,0 +1,81 @@ +package de.psychose; + +import org.snmp4j.CommunityTarget; +import org.snmp4j.Snmp; +import org.snmp4j.TransportMapping; +import org.snmp4j.mp.SnmpConstants; +import org.snmp4j.smi.OID; +import org.snmp4j.smi.OctetString; +import org.snmp4j.smi.UdpAddress; +import org.snmp4j.smi.VariableBinding; +import org.snmp4j.transport.DefaultUdpTransportMapping; +import org.snmp4j.util.DefaultPDUFactory; +import org.snmp4j.util.TreeEvent; +import org.snmp4j.util.TreeUtils; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; + +/** + * @author: lucas + * @date: 18.04.14 12:10 + */ +public class SnmpStatClient { + public static final String OID_COUNTER = "1.3.6.1.2.1.2.2.1.10"; + private final String host; + private HashMap lastPorts = new HashMap<>(); + private HashMap sumPorts = new HashMap<>(); + + private CommunityTarget getCommunityTarget() { + CommunityTarget communityTarget = new CommunityTarget(); + communityTarget.setCommunity(new OctetString("public")); + communityTarget.setVersion(SnmpConstants.version2c); + communityTarget.setAddress(new UdpAddress(host)); + communityTarget.setTimeout(500); + return communityTarget; + } + + public SnmpStatClient(String host) { + this.host = host; + } + + public long getTrafficSum() { + + long sum = 0; + + try { + final TransportMapping transportMapping = new DefaultUdpTransportMapping(); + transportMapping.listen(); + + final Snmp snmp = new Snmp(transportMapping); + final TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory()); + final List treeEventList = treeUtils.getSubtree(getCommunityTarget(), new OID(OID_COUNTER)); + + for (TreeEvent treeEvent : treeEventList) { + if (treeEvent.getStatus() == TreeEvent.STATUS_OK) { + for (VariableBinding binding : treeEvent.getVariableBindings()) { + int oid = binding.getOid().last(); + long value = binding.getVariable().toLong(); + long lastValue = 0; + if(lastPorts.containsKey(oid)) lastValue = lastPorts.get(oid); + long diff = value - lastValue; + + if(diff > 0) { + sumPorts.put(oid, lastValue + diff); + } + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + for(long port: sumPorts.values()) { + sum+=port; + } + + return sum; + } + +} diff --git a/healthdisplay/src/main/java/de/psychose/StatsDisplay.form b/healthdisplay/src/main/java/de/psychose/StatsDisplay.form index 0dd0183..0ea389a 100644 --- a/healthdisplay/src/main/java/de/psychose/StatsDisplay.form +++ b/healthdisplay/src/main/java/de/psychose/StatsDisplay.form @@ -1,6 +1,6 @@
- + @@ -24,7 +24,7 @@ - + @@ -47,16 +47,6 @@ - - - - - - - - - - @@ -77,7 +67,27 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -87,6 +97,16 @@ + + + + + + + + + + diff --git a/healthdisplay/src/main/java/de/psychose/StatsDisplay.java b/healthdisplay/src/main/java/de/psychose/StatsDisplay.java index 4989777..7b3c76c 100644 --- a/healthdisplay/src/main/java/de/psychose/StatsDisplay.java +++ b/healthdisplay/src/main/java/de/psychose/StatsDisplay.java @@ -11,6 +11,8 @@ public class StatsDisplay { private JLabel lblMessageCount; private JLabel lblMessagesPerSec; private JPanel statPanel; + private JLabel lblTraffic; + private JLabel lblBandwidth; public void setMessageCount(String count) { lblMessageCount.setText(count); @@ -20,4 +22,12 @@ public class StatsDisplay { lblMessagesPerSec.setText(messagesPerSec); } + public void setTotalTraffic(String totalTraffic) { + lblTraffic.setText(totalTraffic); + } + + public void setBandwidth(String bandwidth) { + lblBandwidth.setText(bandwidth); + } + } diff --git a/healthdisplay/src/main/java/de/psychose/Test.java b/healthdisplay/src/main/java/de/psychose/Test.java index deb48b6..6a1e54c 100644 --- a/healthdisplay/src/main/java/de/psychose/Test.java +++ b/healthdisplay/src/main/java/de/psychose/Test.java @@ -27,6 +27,13 @@ public class Test { public static void main(String[] args) throws Exception { + SnmpStatClient snmpStatClient = new SnmpStatClient("switch/161"); + + System.out.println(snmpStatClient.getTrafficSum() / 1024 / 1024 + "MB"); + + + if(true) return; + Enumeration nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { displayInterfaceInformation(netint); From 3c2cb48eeda321982ab07cf7f56138ed529b8ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 23 Apr 2014 22:35:04 +0200 Subject: [PATCH 2/5] changed offline lines to "no data" --- .../src/main/java/de/psychose/ActorDisplay.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/healthdisplay/src/main/java/de/psychose/ActorDisplay.java b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java index abef1e0..6bed33b 100644 --- a/healthdisplay/src/main/java/de/psychose/ActorDisplay.java +++ b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java @@ -11,6 +11,7 @@ import java.awt.event.ActionEvent; public class ActorDisplay { private final static Color onColor = Color.WHITE; private final static Color offColor = Color.RED; + private final static String offText = "no data"; private JPanel actorPanel; private JLabel lblCaption; @@ -78,43 +79,49 @@ public class ActorDisplay { if (++counterTemperature > timeout) { lblTemperature.setForeground(offColor); + lblTemperature.setText(offText); } else { lblTemperature.setForeground(onColor); } if (++counterPulse > timeout) { lblPulse.setForeground(offColor); + lblPulse.setText(offText); } else { lblPulse.setForeground(onColor); } if (++counterOxy > timeout) { lblOxy.setForeground(offColor); + lblOxy.setText(offText); } else { lblOxy.setForeground(onColor); } if (++counterEkg > timeout) { lblEkg.setForeground(offColor); + lblEkg.setText(offText); } else { lblEkg.setForeground(onColor); } if (++counterEmg > timeout) { lblEmg.setForeground(offColor); + lblEkg.setText(offText); } else { lblEmg.setForeground(onColor); } if (++counterHeartbeat > timeout) { lblHeartbeat.setForeground(offColor); - lblHeartbeat.setText("no data"); + lblHeartbeat.setText(offText); } else { lblHeartbeat.setForeground(onColor); } if (++counterBreath > timeout) { lblBreath.setForeground(offColor); + lblBreath.setText(offText); } else { lblBreath.setForeground(onColor); } From 8f57a6d36a12953ecb768e9fa0bf10a1f2b7b3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Thu, 24 Apr 2014 10:49:54 +0200 Subject: [PATCH 3/5] fade animation --- texter/texter/main.py | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/texter/texter/main.py b/texter/texter/main.py index 01762ee..1ed9459 100644 --- a/texter/texter/main.py +++ b/texter/texter/main.py @@ -109,6 +109,63 @@ class TextSorterDialog(QtGui.QWidget, Ui_TextSorterDialog): self.text_list.setCurrentIndex(index) self.text_list.clicked.emit(index) +class FadeAnimation(QtCore.QObject): + animation_started = QtCore.pyqtSignal() + animation_finished = QtCore.pyqtSignal() + animation_stopped = QtCore.pyqtSignal() + + def __init__(self, live_text, fade_steps=6, parent=None): + super(FadeAnimation, self).__init__(parent) + self.live_text = live_text + self.fade_steps = fade_steps + self.current_alpha = 255 + self.timer = None + + + def start_animation(self): + print "start_animation" + self.animation_started.emit() + + if self.current_alpha == 255: + self.fade_delta = 255 / self.fade_steps + else: + self.fade_delta = -255 / self.fade_steps + self.timer = QtCore.QTimer(self) + self.timer.timeout.connect(self.slot_animate) + self.timer.start(100) + + + def slot_animate(self): + print "slot_animate" + print "current_alpha", self.current_alpha + if self.fade_delta > 0: + if self.current_alpha > 0: + self.live_text.setStyleSheet("color:%d, %d, %d;" % (self.current_alpha, self.current_alpha,self.current_alpha)) + self.current_alpha -= self.fade_delta + else: + self.live_text.setStyleSheet("color:black;") + self.current_alpha = 0 + self.timer.stop() + self.timer.timeout.disconnect(self.slot_animate) + self.timer.deleteLater() + self.timer = None + self.animation_finished.emit() + print "animation_finished" + else: + if self.current_alpha < 255: + self.live_text.setStyleSheet("color:%d,%d, %d;" % (self.current_alpha, self.current_alpha,self.current_alpha)) + self.current_alpha -= self.fade_delta + else: + self.live_text.setStyleSheet("color:white") + self.current_alpha = 255 + self.timer.stop() + self.timer.timeout.disconnect(self.slot_animate) + self.timer.deleteLater() + self.timer = None + self.animation_finished.emit() + print "animation_finished" + + class TextAnimation(QtCore.QObject): animation_started = QtCore.pyqtSignal() @@ -229,10 +286,13 @@ class MainWindow(KMainWindow, Ui_MainWindow): self.animation = TextAnimation(self) self.db_dirty = False self.is_animate = False + self.fade_animation = None self.is_auto_publish = False self.setupUi(self) + + self.fade_animation = FadeAnimation(self.live_text, 6, self) self.font = QtGui.QFont("monospace", self.default_size) self.font.setStyleHint(QtGui.QFont.TypeWriter) @@ -274,6 +334,7 @@ class MainWindow(KMainWindow, Ui_MainWindow): self.preview_size_action.triggered[QtGui.QAction].connect(self.slot_preview_font_size) self.live_size_action.triggered[QtGui.QAction].connect(self.slot_live_font_size) + self.fade_action.triggered.connect(self.slot_fade) self.next_action.triggered.connect(self.slot_next_item) self.previous_action.triggered.connect(self.slot_previous_item) @@ -433,6 +494,12 @@ class MainWindow(KMainWindow, Ui_MainWindow): spacer = KToolBarSpacerAction(self.action_collection) self.action_collection.addAction("1_spacer", spacer) + + self.fade_action = self.action_collection.addAction("fade_action") + #icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page")) + #self.fade_action.setIcon(icon) + self.fade_action.setIconText("fade") + self.fade_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.previous_action = self.action_collection.addAction("previous_action") icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page")) @@ -595,6 +662,10 @@ class MainWindow(KMainWindow, Ui_MainWindow): def slot_clear_preview(self): self.preview_text.clear() self.slot_set_preview_defaults() + + def slot_fade(self): + if self.fade_animation.timer is None: + self.fade_animation.start_animation() def fill_combo_box(self): self.text_combo.clear() From eaaddd80f28dc97ba4a5233dec4be191be229861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Thu, 24 Apr 2014 14:20:10 +0200 Subject: [PATCH 4/5] minor ekplotter update --- ekgplotter/ekgplotter/main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ekgplotter/ekgplotter/main.py b/ekgplotter/ekgplotter/main.py index dbc1ba2..601d196 100644 --- a/ekgplotter/ekgplotter/main.py +++ b/ekgplotter/ekgplotter/main.py @@ -97,7 +97,7 @@ class OSCThread(threading.Thread): print "%s: starting up osc receiver on '%s:%d'" % ( datetime.now().strftime("%x %X"), self.client_address[0], self.client_address[1]) - #self.subscribe_me() + self.subscribe_me() def subscribe_me(self): """Use this procedure for a quick'n dirty subscription to your chaosc instance. @@ -148,12 +148,12 @@ class OSCThread(threading.Thread): queue.put_nowait((osc_address, messages)) except Exception, e: print "recvfrom error", e - #else: - #queue.put_nowait(("/bjoern/ekg", [0])) - #queue.put_nowait(("/merle/ekg", [0])) - #queue.put_nowait(("/uwe/ekg", [0])) + else: + queue.put_nowait(("/bjoern/ekg", [0])) + queue.put_nowait(("/merle/ekg", [0])) + queue.put_nowait(("/uwe/ekg", [0])) - #self.unsubscribe_me() + self.unsubscribe_me() print "OSCThread is going down" @@ -245,6 +245,7 @@ class EkgPlot(object): def __init__(self, actor_names, num_data, colors): self.plot = pg.PlotWidget() self.plot.hide() + #self.plot.show() #self.plot.setLabel('left', "

Amplitude

") #self.plot.setLabel('bottom', "

Time

") self.plot.showGrid(False, False) @@ -256,6 +257,8 @@ class EkgPlot(object): bl = self.plot.getAxis("left") ba.setTicks([]) bl.setTicks([]) + ba.hide() + bl.hide() self.active_actors = list() self.actors = dict() From cf756d4cf7ff4965f8b7bee6456e78bcfae626ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Thu, 24 Apr 2014 20:22:41 +0200 Subject: [PATCH 5/5] fixed bug where ekg does not show "no data" and fixed bug where snmp was not closed correctly --- healthdisplay/src/main/java/de/psychose/ActorDisplay.java | 2 +- healthdisplay/src/main/java/de/psychose/SnmpStatClient.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/healthdisplay/src/main/java/de/psychose/ActorDisplay.java b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java index 6bed33b..efe1d63 100644 --- a/healthdisplay/src/main/java/de/psychose/ActorDisplay.java +++ b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java @@ -107,7 +107,7 @@ public class ActorDisplay { if (++counterEmg > timeout) { lblEmg.setForeground(offColor); - lblEkg.setText(offText); + lblEmg.setText(offText); } else { lblEmg.setForeground(onColor); } diff --git a/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java b/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java index 5825031..a523318 100644 --- a/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java +++ b/healthdisplay/src/main/java/de/psychose/SnmpStatClient.java @@ -67,6 +67,8 @@ public class SnmpStatClient { } } } + + snmp.close(); } catch (IOException e) { e.printStackTrace(); }