The Code Behind The Tool: Building Your Own Bandwidth Calculator
The Code Behind The Tool: Building Your Own Bandwidth Calculator
The Code Behind The Tool: Building Your Own Bandwidth Calculator
Share:
Table of Contents
Getting the Environment Set-Up .............................................................................................3
Lesson 1 - Installation ................................................................................................................. 3
Lesson 2 The Environment ........................................................................................................ 3
Share:
Do You Need
Easy Server Monitoring?
In this series, I will explain step by step how I built this calculator, explain what everything means,
then give you all the code needed along the way so you can build one yourself. This will be your
Visual Basic (VB) classroom starting today. At the end, you get to keep the calculator you've recreated below (it even talks).
Note: The only way to get this calculator is to build it following the steps in this document. It will
not be available for download nor will SolarWinds offer support for this tool. The code for this tool is
made available for educational purposes only.
Lesson 1 Installation
Before we begin, you'll need to install Visual Basic Express 2010, free courtesy of Microsoft. Click
here to begin downloading, followed by the installation.
Share:
If you done everything successfully, your screen should now look like this:
Now you have all you need to build the Bandwidth Calculator, minus the code. Let me explain what
you're looking at above:
Highlighted in red is a Form. A form, in essence, is a window; hence the name, Windows.
A form is an empty workspace where all of your buttons and controls will live, once you put
them there. (Notice the form of the calculator above with all of its controls.)
Highlighted in green is the Toolbox. The toolbox contains all of the controls you will need
to build almost anything, including the calculator. (In fact, you can even build your own
controls, but I will not cover that in this piece.) These controls may be placed on the form
as needed. As you can see in the calculator, there are multiple text boxes, sliders, labels, a
pie chart, and a button. These all came from the toolbox.
Highlighted in purple is the Properties window. Every control, or object (including the
form itself) has certain properties. These properties can be set and changed both before
running the program and while the program is running. Think about the properties of
television. One property is its color. Other properties include the TV's height, weight,
picture resolution, and so on. The reason the button on the calculator says "Reset" is
because I changed the Text property in the Properties window to read "Reset."
Homework
Play around with this new environment and try to get comfortable. Explore the controls and the
properties of the more common controls.
Share:
Tip: Once you place a control on the form and select it, the Properties window will show the
properties of that control.
Stretch the Form to make it about twice as wide as it is high. (Select it and grab a corner
node to do this.)
2.
With the Form still selected, go to the Properties window to the right of the Form and
find the Text property.
3.
4.
Also in the Properties window, change the Name property to read frmMain.
Make a Container:
1.
From the Toolbox on the left, select Groupbox and draw one on the left side of your
Form. This Groupbox will house the majority of your controls. Ensure that it's wide
enough to do so.
2.
With the Groupbox still selected, go to the Properties window to the right of the Form
and find the Text property.
3.
Label It:
1.
From the Toolbox on the left, select Label, then draw four labels on the Form inside the
Groupbox.
2.
Change the text of these Labels to read, WMI, SNMP, RPC, and Nodes (ICMP).
3.
2.
Draw four Textboxes below the Labels you created in the previous step.
3.
Change the Text property of these four Textboxes to read nothing. (Delete the default
text from the Properties window for each Textbox.)
4.
Change the name of each Textbox using the Properties window. Rename these four
Textboxes to txtWMI, txtSNMP, txtRPC, and txtICMP.
5.
Share:
Arrange them under their respective labels (created in the previous steps).
2.
Place four TrackBars on the Form to the right of each Textbox you created in the
previous section. (Note: These also go into the Groupbox.)
3.
4.
5.
Arrange them to the right of their respective Textbox while still keeping them in the Groupbox.
More Labeling:
1.
2.
Draw four labels on the Form inside the Groupbox and to the right of each TrackBar.
3.
Change the Name property of these Labels to read, lblWMI, lblSNMP, lblRPC, and lblICMP.
4.
Change the Text property of these Labels to all read 00.00 Kbps.
5.
6.
Add an additional Label above these four and change the Text property to read Per Protocol.
Adding a PictureBox:
1.
2.
Place it and size it in the GroupBox next to the Reset button (in the initial illustration).
3.
b.
From there, click the ellipsis (...) button, and then select Local Resource.
c.
d.
2.
3.
From the Properties window, change the Name property of the button to cmdReset.
4.
2.
3.
Place it outside of the Groupbox and to the top-right of the Form, as illustrated above.
Learn More
Share:
Try It FREE
6
From the Toolbox on the left, under the collapsed heading, Data, select Chart.
2.
Draw a Chart on the right side of the Form and outside of the Groupbox, as illustrated
above.
a.
From the Properties window, change the Series property by clicking the ellipsis
(...) button.
3.
Select ChartType and then select Pie from the dropdown menu.
4.
Click OK.
More Groupboxes:
1.
2.
Change the Text property of the first to read Total Number of Monitors.
3.
4.
5.
6.
Share:
a.
b.
b.
If you've done everything successfully, you should have a Form that looks something like this:
This probably looks a bit different from what you have, which leads to today's homework
assignment.
Homework
Now, I've given you the minimum you need to design the calculator. That is, all the objects needed
for the calculator to work are now on the Form. By now, I'm sure you've noticed there are many
more properties that you can tweak, like the color and size of the fonts. Your assignment is to play
with these properties and try and get the calculator to look as close in appearance to the one at the
top of this paper.
Next, we'll begin coding.....oooooohhhhh.
Share:
components.
Share:
' The colon (:) in the above line acts like a new line of code. If the IF statement is
true, first - change the text of lblWMI, then navigate to the sub called DoTotal, then Exit
the Sub.
'The below If...Then statement incorporates the Else statement. So we have IF, THEN,
ELSE.
If WMIConvert < 1 Then ' If the value of the variable, WMIConvert, is less than 1,
execute the code below until the ELSE statement is reached. If not, execute the code below
the ELSE statement, ending on the End IF statement.
DoTotal() ' Call the sub, DoTotal and execute the code of that sub.
WMIsuffix = " Kbps" ' This string variable is now equal to the text within the
quotes.
WMIConvert2 = WMIConvert * 1024 ' The variable, WMIConvert2 is equal to the value
of the variable, WMIConvert, multiplied by the number 1024.
lblWMI.Text = Format(WMIConvert2, "###,###") & WMIsuffix ' The text property of
the label, lblWMI, is equal to the number held in the variable WMIConvert2 AND (&) the
variable WMIsuffix.
' The Format(WMIConvert2, "###,###") formats the value of the variable WMIConvert2
to be in proper numerical readable format (999,123, as opposed to, 999123). In this case
the comma is added after every three numbers. The ampersand (&) does not do addition,
rather, it concatenates, or joins the two variables (e.g. 5 & 4 would result in 54)
Exit Sub ' Work is done in this sub, perform no more actions
Else
DoTotal() ' Call the sub named, DoTotal, and execute the code of that sub.
WMIsuffix = " Mbps" ' This string variable, WMISuffix, now stores the text within
the quotes.
lblWMI.Text = Format(WMIConvert, "standard") & WMIsuffix ' The text property of the
variable, lblWMI, is equal to the number held in the variable WMIConvert AND (&) the
variable WMIsuffix. The value is formatted using 'Standard'.
Exit Sub ' Work is done in this sub, perform no more actions
End If ' The required statement to close a multi-line If...Then...(Else) statement.
End Sub ' This is the end of this subroutine.
Homework
None. You've been good thus far and I don't like homework either.
Do You Need
Headache-Free
Server Monitoring?
The only way to get this calculator is to build it following the steps in this series. It will not
be available for download nor will SolarWinds offer support for this tool. The code for this
tool is made available for educational purposes only.
When built, the calculator will only provide recommendations based on a small amount of
testing. Your environment will be different and you may want to modify the code to suit
your needs. (Comments in the code are given on what to modify, if you so desire.)
This calculator has not been tested for accuracy and will not be supported in any way,
shape, or form, by SolarWinds, or by the author of this white paper.
SolarWinds is not responsible for any errors or non-working code. Sorry, you'll have to
troubleshoot yourselves.
This is only one of an infinite number of ways to code this calculator. I'm sure there are
more elegant designs. The bottom line is, it works.
Share:
10
If and when you get this to work where others cannot, please help them if you can.
Wireshark is a free tool that you can use to measure and filter your bandwidth traffic.
Wireshark was used in getting bandwidth averages for the four protocols in this calculator.
You can use Wireshark to get your own averages and modify the figures in this code,
which is commented.
If all is well, hit the Play button, highlighted above. The calculator should appear before you
working as planned. If everything works, compile your code into an executable.
Share:
11
Share:
12
TBSNMP.Value = txtSNMP.Text
Else
TBSNMP.Value = 10000
End If
If SNMPMonitorNumbers < 1 Then txtSNMP.Text = "0" : SNMPCalc()
End Sub
Private Sub txtICMP_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles
txtICMP.LostFocus
On Error Resume Next
If IsNumeric(txtICMP.Text) = False Or txtICMP.Text > 10000 Then
txtICMP.Text = "0"
ICMPMonitorNumbers = txtICMP.Text
TBICMP.Value = 0
ICMPCalc()
Exit Sub
End If
ICMPMonitorNumbers = txtICMP.Text
txtICMP.Text = Format(ICMPMonitorNumbers, "###,###")
ICMPCalc()
If txtICMP.Text <= 10000 Then
TBICMP.Value = txtICMP.Text
Else
TBICMP.Value = 10000
End If
If ICMPMonitorNumbers < 1 Then txtICMP.Text = "0" : ICMPCalc()
End Sub
Private Sub txtWMI_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtWMI.KeyDown
On Error Resume Next
If e.KeyCode = Keys.Return Then
If IsNumeric(txtWMI.Text) = False Or txtWMI.Text > 10000 Then
txtWMI.Text = "0" : Exit Sub
End If
WMIMonitorNumbers = txtWMI.Text
txtWMI.Text = Format(WMIMonitorNumbers, "###,###")
WMICalc()
If txtWMI.Text <= 10000 Then
TBWMI.Value = txtWMI.Text
Else
TBWMI.Value = 10000
End If
End If
End Sub
Private Sub WMICalc()
On Error Resume Next
WMIStat = 315 'This is the key figure. This number represents multiple tests and
averages using Wireshark, filtering out data that is not pertinent. Changing this number
will allow you to fine tune the amount of bandwidth used by this protocol.
WMINeededBW = WMIStat * WMIMonitorNumbers
WMIConvert = ((WMINeededBW / 1024) * 8) / 1024
If WMIConvert = 0 Then lblWMI.Text = "00.00 Kbps" : DoTotal() : Exit Sub
If WMIConvert < 1 Then
DoTotal()
WMIsuffix = " Kbps"
WMIConvert2 = WMIConvert * 1024
lblWMI.Text = Format(WMIConvert2, "###,###") & WMIsuffix
Exit Sub
Share:
13
Else
DoTotal()
WMIsuffix = " Mbps"
lblWMI.Text = Format(WMIConvert, "standard") & WMIsuffix
Exit Sub
End If
End Sub
Private Sub TBWMI_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles
TBWMI.ValueChanged
On Error Resume Next
WMIMonitorNumbers = TBWMI.Value
If txtWMI.Text <= 10000 Then
txtWMI.Text = Format(TBWMI.Value, "###,###")
End If
If WMIMonitorNumbers < 1 Then txtWMI.Text = "0"
WMICalc()
End Sub
Private Sub txtSNMP_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtSNMP.KeyDown
On Error Resume Next
If e.KeyCode = Keys.Return Then
If IsNumeric(txtSNMP.Text) = False Or txtSNMP.Text > 10000 Then
txtSNMP.Text = "0" : Exit Sub
End If
SNMPMonitorNumbers = txtSNMP.Text
txtSNMP.Text = Format(SNMPMonitorNumbers, "###,###")
SNMPCalc()
If txtSNMP.Text <= 10000 Then
TBSNMP.Value = txtSNMP.Text
Else
TBSNMP.Value = 10000
End If
End If
End Sub
Private Sub SNMPCalc()
On Error Resume Next
SNMPStat = 0.66 'This is the key figure. This number represents multiple tests and
averages using Wireshark, filtering out data that is not pertinent. Changing this number
will allow you to fine tune the amount of bandwidth used by this protocol.
SNMPNeededBW = SNMPStat * SNMPMonitorNumbers
SNMPConvert = ((SNMPNeededBW / 1024) * 8) / 1024
If SNMPConvert = 0 Then lblSNMP.Text = "00.00 Kbps" : DoTotal() : Exit Sub
If SNMPConvert < 1 Then
DoTotal()
SNMPsuffix = " Kbps"
SNMPConvert2 = SNMPConvert * 1024
If SNMPConvert2 < 1 Then SNMPConvert2 = 1
lblSNMP.Text = Format(SNMPConvert2, "###,###") & SNMPsuffix
Exit Sub
Else
DoTotal()
SNMPsuffix = " Mbps"
lblSNMP.Text = Format(SNMPConvert, "standard") & SNMPsuffix
Exit Sub
End If
End Sub
Private Sub TBSNMP_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Handles TBSNMP.ValueChanged
On Error Resume Next
SNMPMonitorNumbers = TBSNMP.Value
If txtSNMP.Text <= 10000 Then
txtSNMP.Text = Format(TBSNMP.Value, "###,###")
Share:
14
End If
If SNMPMonitorNumbers < 1 Then txtSNMP.Text = "0"
SNMPCalc()
End Sub
Private Sub txtRPC_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtRPC.KeyDown
On Error Resume Next
If e.KeyCode = Keys.Return Then
If IsNumeric(txtRPC.Text) = False Or txtRPC.Text > 10000 Then
txtRPC.Text = "0" : Exit Sub
End If
RPCMonitorNumbers = txtRPC.Text
txtRPC.Text = Format(RPCMonitorNumbers, "###,###")
RPCCalc()
If txtRPC.Text <= 10000 Then
TBRPC.Value = txtRPC.Text
Else
TBRPC.Value = 10000
End If
End If
End Sub
Private Sub RPCCalc()
On Error Resume Next
Dim Exponent As Double
RPCStat = 2392 'This is the key figure. This number represents multiple tests and
averages using Wireshark, filtering out data that is not pertinent. Changing this number
will allow you to fine tune the amount of bandwidth used by this protocol.
Exponent = 1
RPCStat = RPCStat ^ Exponent
RPCNeededBW = RPCStat * RPCMonitorNumbers
RPCConvert = ((RPCNeededBW / 1024) * 8) / 1024
If RPCConvert = 0 Then lblRPC.Text = "00.00 Kbps" : DoTotal() : Exit Sub
If RPCConvert < 1 Then
DoTotal()
RPCsuffix = " Kbps"
RPCConvert2 = RPCConvert * 1024
lblRPC.Text = Format(RPCConvert2, "###,###") & RPCsuffix
Exit Sub
Else
DoTotal()
RPCsuffix = " Mbps"
lblRPC.Text = Format(RPCConvert, "standard") & RPCsuffix
Exit Sub
End If
End Sub
Private Sub TBRPC_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles
TBRPC.ValueChanged
On Error Resume Next
RPCMonitorNumbers = TBRPC.Value
If txtRPC.Text <= 10000 Then
txtRPC.Text = Format(TBRPC.Value, "###,###")
End If
If RPCMonitorNumbers < 1 Then txtRPC.Text = "0"
RPCCalc()
End Sub
Private Sub txtICMP_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtICMP.KeyDown
On Error Resume Next
If e.KeyCode = Keys.Return Then
If IsNumeric(txtICMP.Text) = False Then
txtICMP.Text = "0" : Exit Sub
End If
ICMPMonitorNumbers = txtICMP.Text
txtICMP.Text = Format(ICMPMonitorNumbers, "###,###")
Share:
15
ICMPCalc()
If txtICMP.Text <= 10000 Then
TBICMP.Value = txtICMP.Text
Else
TBICMP.Value = 10000
End If
End If
End Sub
Private Sub ICMPCalc()
On Error Resume Next
ICMPStat = 1.15 'This is the key figure. This number represents multiple tests and
averages using Wireshark, filtering out data that is not pertinent. Changing this number
will allow you to fine tune the amount of bandwidth used by this protocol.
ICMPNeededBW = ICMPStat * ICMPMonitorNumbers
ICMPConvert = ((ICMPNeededBW / 1024) * 8) / 1024
If ICMPConvert = 0 Then lblICMP.Text = "00.00 Kbps" : DoTotal() : Exit Sub
If ICMPConvert < 1 Then
DoTotal()
ICMPsuffix = " Kbps"
ICMPConvert2 = ICMPConvert * 1024
If ICMPConvert2 < 1 Then ICMPConvert2 = 1
lblICMP.Text = Format(ICMPConvert2, "###,###") & ICMPsuffix
Exit Sub
Else
DoTotal()
ICMPsuffix = " Mbps"
lblICMP.Text = Format(ICMPConvert, "standard") & ICMPsuffix
Exit Sub
End If
End Sub
Private Sub TBICMP_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Handles TBICMP.ValueChanged
On Error Resume Next
ICMPMonitorNumbers = TBICMP.Value
If txtICMP.Text <= 10000 Then
txtICMP.Text = Format(TBICMP.Value, "###,###")
End If
If ICMPMonitorNumbers < 1 Then txtICMP.Text = "0"
ICMPCalc()
End Sub
Private Sub DoTotal()
On Error Resume Next
suffixtotal = " Mbps"
FinalTotal = WMIConvert + SNMPConvert + RPCConvert + ICMPConvert
If FinalTotal >= 1024 Then
suffixtotal = " Gbps"
FinalTotal = FinalTotal / 1024
End If
If FinalTotal < 1 Then
suffixtotal = " Kbps"
FinalTotal = FinalTotal * 1024
End If
Monitortotal = WMIMonitorNumbers + RPCMonitorNumbers + SNMPMonitorNumbers +
ICMPMonitorNumbers
lblMonitors.Text = Format(Monitortotal, "###,###")
lblTotal.Text = Format(FinalTotal, "Standard") & suffixtotal
If Monitortotal < 1 Then lblMonitors.Text = "0"
FinalTotal = 0
Piecalc()
End Sub
Share:
16
Share:
17
All$ = "The total recommended bandwidth for your" & Monitortotal & "monitors
is" & CNumber & prefix$
SAPI.Speak(All$)
Exit Sub
End If
End Sub
Private Sub picSpeak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles picSpeak.Click
speak()
End Sub
End Class
2.
C:\VS2010\Calculator\BWCalc\BWCalc\bin\Release
Share:
18
About SolarWinds
Monitor
Server
&
Application
SolarWinds Server & Application Monitor delivers agentless performance and availability monitoring,
alerting, and reporting for hundreds of applications and server types. Within minutes of download and
installation, you can start monitoring virtually any application, including Microsoft Exchange, Active
Directory, Java, and more. Server & Application Monitor is an affordable, easy to use server
monitoring tool that tracks the health of Dell, HP, and IBM System x servers along with the
underlying hardware for your VMware hosts. Server & Application Monitor also provides insight into
environmental data, hardware status, and more.
Product Highlights:
Monitors performance and user experience for virtually any application Microsoft Exchange,
Active Directory, IIS, any ODBC database, amd more
Monitors server hardware faults and operating systems across platforms Windows, UNIX,
Linux, and more
Provides expert guidance on what to monitor, why to monitor it, and optimal thresholds
Includes customizable dashboards and reports showing trends, capacity, and performance
Downloads and deploys in less than an hour, is simple to use, and easy on your budget
About SolarWinds
SolarWinds (NYSE: SWI) provides powerful and affordable IT management software to customers
worldwide - from Fortune 500 enterprises to small businesses. The company works to put its users first
and remove the obstacles that have become status quo in traditional enterprise software. SolarWinds
products are downloadable, easy to use and maintain, and provide the power, scale, and flexibility
needed to address users management priorities. SolarWinds online user community,
http://thwack.com, is a gathering place where tens of thousands of IT pros solve problems, share
technology, and participate in product development for all of the companys products. Learn more today
at http://solarwinds.com.
http://www.solarwinds.com/partners/reseller_locator.aspx
2012 SolarWinds Worldwide, LLC. All rights reserved. SOLARWINDS, SOLARWINDS & Design and other SolarWinds marks, identified
on the SolarWinds website, as updated from SolarWinds from time to time and incorporated herein, are registered with the U.S. Patent
and Trademark Office and may be registered or pending registration in other countries. All other SolarWinds trademarks may be
common law marks or registered or pending registration in the United States or in other countries. All other trademarks or registered
trademarks contained and/or mentioned herein are used for identification purposes only and may be trademarks or registered
trademarks of their respective companies.
Share:
19