added stats display
This commit is contained in:
parent
a53cf435de
commit
bcdd2e4013
|
@ -0,0 +1,13 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: log4j:log4j:1.2.9">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.9/log4j-1.2.9.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.9/log4j-1.2.9-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/log4j/log4j/1.2.9/log4j-1.2.9-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -0,0 +1,13 @@
|
|||
<component name="libraryTable">
|
||||
<library name="Maven: org.snmp4j:snmp4j:1.9.1f">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/snmp4j/snmp4j/1.9.1f/snmp4j-1.9.1f.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/snmp4j/snmp4j/1.9.1f/snmp4j-1.9.1f-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/snmp4j/snmp4j/1.9.1f/snmp4j-1.9.1f-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
|
@ -17,6 +17,8 @@
|
|||
<orderEntry type="library" name="Maven: asm:asm:3.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.jgoodies:forms:1.1-preview" level="project" />
|
||||
<orderEntry type="library" name="Maven: jdom:jdom:1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.snmp4j:snmp4j:1.9.1f" level="project" />
|
||||
<orderEntry type="library" name="Maven: log4j:log4j:1.2.9" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
<artifactId>forms_rt</artifactId>
|
||||
<version>7.0.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.snmp4j</groupId>
|
||||
<artifactId>snmp4j</artifactId>
|
||||
<version>1.9.1f</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -140,16 +140,6 @@
|
|||
<text value="-"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9b787" class="javax.swing.JLabel" binding="lblCaption">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Droid Sans Mono" size="28" style="1"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Label"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="29a78" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
|
@ -170,6 +160,16 @@
|
|||
<text value="-"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="9b787" class="javax.swing.JLabel" binding="lblCaption">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Droid Sans Mono" size="28" style="1"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Label"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Integer, Long> lastPorts = new HashMap<>();
|
||||
private HashMap<Integer, Long> 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<TreeEvent> 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.StatsDisplay">
|
||||
<grid id="27dc6" binding="statPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="statPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="248" height="180"/>
|
||||
|
@ -24,7 +24,7 @@
|
|||
</component>
|
||||
<vspacer id="9a59f">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="1d950" class="javax.swing.JLabel">
|
||||
|
@ -47,16 +47,6 @@
|
|||
<text value="Ev/Sek"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="4b993" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Droid Sans Mono" size="20"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="Herz"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="54c59" class="javax.swing.JLabel" binding="lblMessageCount">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
|
@ -77,7 +67,27 @@
|
|||
<text value="-"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a2840" class="javax.swing.JLabel">
|
||||
<component id="95ca8" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Droid Sans Mono" size="20"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="kb"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="b1b4b" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Droid Sans Mono" size="20"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="kb/Sek"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="af868" class="javax.swing.JLabel" binding="lblTraffic">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
@ -87,6 +97,16 @@
|
|||
<text value="-"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="88e99" class="javax.swing.JLabel" binding="lblBandwidth">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Droid Sans Mono" size="20"/>
|
||||
<foreground color="-1"/>
|
||||
<text value="-"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
|
||||
for (NetworkInterface netint : Collections.list(nets)) {
|
||||
displayInterfaceInformation(netint);
|
||||
|
|
Loading…
Reference in New Issue