Anda di halaman 1dari 19

The Code Behind the Tool:

Building Your Own


Bandwidth Calculator
By: Bronx

Share:

Table of Contents
Getting the Environment Set-Up .............................................................................................3
Lesson 1 - Installation ................................................................................................................. 3
Lesson 2 The Environment ........................................................................................................ 3

Creating the VB form ...............................................................................................................5


Lesson 3 The Build .................................................................................................................... 5

Writing the Code .....................................................................................................................8


Lesson 4 - The Coding .................................................................................................................. 8

Compiling the Code ...............................................................................................................10


Lesson 5 - Compiling the code ................................................................................................... 11

About SolarWinds Server and Application Monitor ...............................................................19

2003-2012 SolarWinds. All Rights Reserved.

Share:

Building Your Own Bandwidth Calculator

Getting the Environment Set-Up


A while back, I took it upon myself to create an internal tool we needed here at SolarWinds. Hence,
the Bandwidth Calculator was born. This calculator was designed specifically for Server &
Application Monitor (SAM) to estimate the recommended amount of bandwidth needed for a
certain amount of component monitors based on their protocol. As you can see below, 21 WMI
component monitors would, on average, use the same amount of bandwidth as 10,000 SNMP
component monitors.

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.

SolarWinds Server &


Application Monitor
Can Do That

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.

Lesson 2 The Environment


Now open Visual Studio Express and select New Project from the File menu. A new window will
pop open. From there, select Windows Form Application and then click OK.

Share:

Building Your Own Bandwidth Calculator

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:

Building Your Own Bandwidth Calculator

Tip: Once you place a control on the form and select it, the Properties window will show the
properties of that control.

Creating the Visual Basic form


Creating the visual elements of the calculator

Lesson 3 The Build


First, open Visual Basic and create a new project. (Use the pictures above as a visual aid.)
Get the Form in Shape:
1.

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.

Change the default text from Form1 to Bandwidth Calculator.

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.

Change the default text from Groupbox1 to Number of Monitors (1-10,000).

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.

Arrange them in the Groupbox on the Form as illustrated above.

Get the Textboxes Out:


1.

From the Toolbox on the left, select Textbox.

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).

Building Your Own Bandwidth Calculator

Now We Need Sliders:


1.

From the Toolbox on the left, select TrackBar (a slider).

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.

Change the name of each TrackBar using the Properties window.

4.

Rename these four TrackBars to TBWMI, TBSNMP, TBRPC, and TBICMP.

5.

Arrange them to the right of their respective Textbox while still keeping them in the Groupbox.

More Labeling:
1.

From the Toolbox on the left, select Label.

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.

Arrange them in the Groupbox on the Form as illustrated above.

6.

Add an additional Label above these four and change the Text property to read Per Protocol.

Adding a PictureBox:
1.

From the Toolbox on the left, select PictureBox.

2.

Place it and size it in the GroupBox next to the Reset button (in the initial illustration).

3.

To change the image of the PictureBox:


a.

Select the Image property for it from the Properties window.

b.

From there, click the ellipsis (...) button, and then select Local Resource.

c.

Click Import, then select an image and click OK.

d.

Change the Name property of the Picturebox to picSpeak.

Add the Button:


1.

From the Toolbox on the left, select Button

2.

Place it on the Form and in the Groupbox next to the PictureBox.

3.

From the Properties window, change the Name property of the button to cmdReset.

4.

Change the Text property of the button to read Reset.

Still More Labeling:


1.

From the Toolbox on the left, select Label.

2.

Change the Text property of the Label to read Share of Bandwidth.

3.

Place it outside of the Groupbox and to the top-right of the Form, as illustrated above.

SolarWinds Server & Application Monitor delivers agentless performance and


availability monitoring, alerting, and reporting for 100+ applications and a wide range of
server types.

Learn More
Share:

Try It FREE
6

Building Your Own Bandwidth Calculator

The Pie Chart:


1.

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.

Add two more Groupboxes to the Form.

2.

Change the Text property of the first to read Total Number of Monitors.

3.

Change the Text property of the second to read Recommended Bandwidth.

4.

Arrange them on the Form as shown above.

5.

Inside the Total Number of Monitors Groupbox, add a Label.

6.

Share:

a.

Rename the Label in the Property window to lblMonitors.

b.

Change the Text property to read 0.

Inside the Recommended Bandwidth Groupbox, add a Label.


a.

Rename it in the Property window to lblTotal.

b.

Change the Text property to read 00.00Kbps.

Building Your Own Bandwidth Calculator

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.

Writing the Code


Lesson 4 The Coding
The first question you may have is, "Where does the code go?" From the design screen, you can
either double-click the form (or any object on the form) to be taken to the Code View, or, click the
highlighted red icon above the Properties window in the Solution Explorer, as shown below on
the right. All of the code for this project will fall between Public Class frmMain and End Class, also
highlighted below:

Share:

Building Your Own Bandwidth Calculator

What Does the Code Mean?


The Visual Basic code we will write is a set of specific instructions designed to do what we want
within our program, in this case, calculate figures based on certain parameters. Below is a code
snippet taken from the calculator with a detailed explanation of what each element is and does. Be
aware that this is only a small bit of code. Explaining every line of the calculator in detail is simply
not practical. The point of this exercise is to provide an introductory explanation, hoping you'll
pursue more on your own. In the end, you will have a working bandwidth calculator for SAM's

components.

Code Snippet Explained


The apostrophe (') is a keyword used in Visual Basic to denote a remark or comment. The original
keyword in BASIC was REM (which still works) which is short for "Remark." Anything following either
of these two keywords will not be executed when the program is run. I've added comments to each
line. Comments appear as green text. VB keywords appear as blue text. Note: Code is normally
indented to make it easier to read.
Reminder: 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.
Private Sub WMICalc() ' This is the beginning of a subroutine (aka: sub, a block of code
named WMICalc). This subroutine ends with END SUB, at the bottom. PRIVATE means (in
essence) that this code will not execute unless called upon.
On Error Resume Next ' ON ERROR is a keyword that tells the code to do something in the
event of an error, in this case, RESUME NEXT (do nothing differently).
WMIStat = 315 ' WMIStat is a variable we created that holds a number, which can change.
In this case it is equal to 315.
WMINeededBW = WMIStat * WMIMonitorNumbers 'This is a formula using three numeric
variables to perform multiplication, as denoted by the asterisk (*).
WMIConvert = ((WMINeededBW / 1024) * 8) / 1024 ' Another formula of division and
multiplication with variables and numbers. Any formula within parentheses will execute
first.
'If...Then statement. This is a conditional meaning - If this happens, then do this; if
not, do that.
If WMIConvert = 0 Then lblWMI.Text = "00.00 Kbps" : DoTotal() : Exit Sub
' In the line above, if a variable (WMIConvert) is equal to zero, then the code will
set the label's text property to read, 00.00 Kpbs. If not, the next line of code will be
read.

Share:

Building Your Own Bandwidth Calculator

' 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?

Compiling the Code


This is the one you've been waiting for. The code! Before you get too excited, let me clarify a few
things, for the record:

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

SolarWinds Server &


Application Monitor
Can Do That

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

Building Your Own Bandwidth Calculator

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.

Lesson 5 Compiling the code


Below is the code you will need to add to your calculator project in Visual Basic. In your calculator
project, go to the Code view and delete everything. Next, copy and paste the code below. When
done, you should have something that looks like this:

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.

Copy and Paste Me


Imports System.Data.OleDb
Imports System.Drawing.Drawing2D
Public Class frmMain
Dim WMIMonitorNumbers, WMINeededBW, WMIStat, WMIConvert, WMITotal, FinalTotal, WMIConvert2
As Double
Dim SNMPMonitorNumbers, SNMPNeededBW, SNMPStat, SNMPConvert, SNMPTotal, SNMPConvert2 As
Double
Dim RPCMonitorNumbers, RPCNeededBW, RPCStat, RPCConvert, RPCTotal, RPCConvert2 As Double
Dim ICMPMonitorNumbers, ICMPNeededBW, ICMPStat, ICMPConvert, ICMPTotal, Monitortotal,
ICMPConvert2 As Double
Dim WMIsuffix, RPCsuffix, SNMPsuffix, ICMPsuffix, suffixtotal As String
Dim All$

Share:

11

Building Your Own Bandwidth Calculator

Private Sub txtWMI_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles


txtWMI.LostFocus
On Error Resume Next
If IsNumeric(txtWMI.Text) = False Or Val(txtWMI.Text) > 10000 Then
txtWMI.Text = "0"
WMIMonitorNumbers = txtWMI.Text
TBWMI.Value = 0
WMICalc()
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
If WMIMonitorNumbers < 1 Then txtWMI.Text = "0" : WMICalc()
End Sub
Private Sub txtRPC_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles
txtRPC.LostFocus
On Error Resume Next
If IsNumeric(txtRPC.Text) = False Or txtRPC.Text > 10000 Then
txtRPC.Text = "0"
RPCMonitorNumbers = txtRPC.Text
TBRPC.Value = 0
RPCCalc()
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
If RPCMonitorNumbers < 1 Then txtRPC.Text = "0" : RPCCalc()
End Sub
Private Sub txtSNMP_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles
txtSNMP.LostFocus
On Error Resume Next
If IsNumeric(txtSNMP.Text) = False Or txtSNMP.Text > 10000 Then
txtSNMP.Text = "0"
SNMPMonitorNumbers = txtSNMP.Text
TBSNMP.Value = 0
SNMPCalc()
Exit Sub
End If
SNMPMonitorNumbers = txtSNMP.Text
txtSNMP.Text = Format(SNMPMonitorNumbers, "###,###")
SNMPCalc()
If txtSNMP.Text <= 10000 Then

Share:

12

Building Your Own Bandwidth Calculator

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

Building Your Own Bandwidth Calculator

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

Building Your Own Bandwidth Calculator

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

Building Your Own Bandwidth Calculator

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

Building Your Own Bandwidth Calculator

Private Sub cmdReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles cmdReset.Click
txtWMI.Text = "0"
txtRPC.Text = "0"
txtSNMP.Text = "0"
txtICMP.Text = "0"
TBWMI.Value = 0
TBRPC.Value = 0
TBSNMP.Value = 0
TBICMP.Value = 0
DoTotal()
txtWMI.Text = "0"
txtRPC.Text = "0"
txtSNMP.Text = "0"
txtICMP.Text = "0"
TBWMI.Value = 0
TBRPC.Value = 0
TBSNMP.Value = 0
TBICMP.Value = 0
lblMonitors.Text = "0"
PieReset()
End Sub
Private Sub PieCalc()
Chart1.Series.Clear()
Dim ser1 As Windows.Forms.DataVisualization.Charting.Series
ser1 = Chart1.Series.Add("Pie Chart")
ser1.ChartType = DataVisualization.Charting.SeriesChartType.Pie
ser1.Points(ser1.Points.AddY(WMIConvert)).AxisLabel = "WMI"
ser1.Points(ser1.Points.AddY(SNMPConvert)).AxisLabel = "SNMP"
ser1.Points(ser1.Points.AddY(RPCConvert)).AxisLabel = "RPC"
ser1.Points(ser1.Points.AddY(ICMPConvert)).AxisLabel = "ICMP"
If WMIConvert + SNMPConvert + RPCConvert + ICMPConvert = 0 Then PieReset()
End Sub
Private Sub PieReset()
Chart1.Series.Clear()
Dim ser1 As Windows.Forms.DataVisualization.Charting.Series
ser1 = Chart1.Series.Add("Pie Chart")
ser1.ChartType = DataVisualization.Charting.SeriesChartType.Pie
ser1.Points(ser1.Points.AddY(100)).AxisLabel = "WMI"
ser1.Points(ser1.Points.AddY(100)).AxisLabel = "SNMP"
ser1.Points(ser1.Points.AddY(100)).AxisLabel = "RPC"
ser1.Points(ser1.Points.AddY(100)).AxisLabel = "ICMP"
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
PieReset()
End Sub
Private Sub speak()
Dim SAPI
Dim prefix$
Dim length As Integer
Dim CNumber As Double
SAPI = CreateObject("SAPI.spvoice")
length = Len(lblTotal.Text)
If Mid(lblTotal.Text, length - 3, 4) = "Mbps" Then
prefix$ = "mega bits per second"
Else
prefix$ = "kilabits per second"
End If
CNumber = Val(lblTotal.Text)
If Val(lblTotal.Text) = 0 Then
All$ = "I need numbers to do a calculation. Zero is not an option."
SAPI.Speak(All$)
Exit Sub
Else

Share:

17

Building Your Own Bandwidth Calculator

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

Compiling Your Code into an Executable:


1.

From the Build menu, select Build...

2.

If successful, your executable should reside in a path similar to this:

C:\VS2010\Calculator\BWCalc\BWCalc\bin\Release

Share:

18

Building Your Own Bandwidth Calculator

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.

For additional information, please contact SolarWinds at 866.530.8100 or e-mail


sales@solarwinds.com.
To locate an international reseller near you, visit

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

Anda mungkin juga menyukai