[THIN] Re: track user load at given time intervals

  • From: "Jeff Durbin" <techlists@xxxxxxxxxxxxx>
  • To: <thin@xxxxxxxxxxxxx>
  • Date: Fri, 12 Dec 2003 15:49:04 +1300

You caught me with 15 minutes and feeling like writing code, so here's a
script that will do it for you:
 
 
Option Explicit
 
Const cInterval = 60000 ' 60000 = 60 seconds 
Const cLogFileName = "TS Session Log.csv"
Const cForReading = 1, cForWriting = 2, cForAppending = 8
 
WriteHeader
While 1
  WriteSample
  wscript.Sleep cInterval
Wend
 
Sub WriteHeader
  Dim oFS, oFileOut  
  Set oFS = createobject("Scripting.FileSystemObject")
  Set oFileOut = oFS.OpenTextFile(cLogFileName, cForWriting, True)
  oFileOut.Write "Date,Time,Sessions" & vbcRLF
  Set oFileOut = Nothing
  Set oFS = Nothing
End Sub
 
Sub WriteSample
  Dim intSessionCount, strData, _
      strLines, strLine, strOut, _
      oFS, oFileOut
    strData = Cmd("quser")
  strLines = Split(strData, vbCrLf)
  For Each strLine In strLines
    if instr(strLine,"tcp#") then
      intSessionCount = intSessionCount + 1
    end if
  next
  strOut = day(now) & "-" & month(now) & "-" & year(now) & "," & _
           hour(now) & ":" & minute(now) & ":" & second(time) & "," & _
           intSessionCount & vbCRLF
  Set oFS = createobject("Scripting.FileSystemObject")
  Set oFileOut = oFS.OpenTextFile(cLogFileName, cForAppending, True)
  oFileOut.Write strOut
  Set oFileOut = Nothing
  Set oFS = Nothing
End Sub
 
Function Cmd(cmdline)
  Dim oShell, oFS, strOutFile, oFileOut, sCmd
  Set oShell = createobject("WScript.Shell")
  Set oFS = createobject("Scripting.FileSystemObject")
  strOutFile = oFS.GetTempName
  sCmd = "%COMSPEC% /c " & cmdline & " >" & strOutFile
  oShell.Run sCmd, 0, True
  If oFS.FileExists(strOutFile) Then
    If oFS.GetFile(strOutFile).Size>0 Then
      Set oFileOut = oFS.OpenTextFile(strOutFile)
      Cmd = oFileOut.Readall
      oFileOut.Close
    End If
    oFS.DeleteFile(strOutFile)
  End If
  set oShell = Nothing
  set oFileOut = Nothing
  set oFS = Nothing
End Function

 
 
  Copy the script into notepad and save it with the extension VBS. I called
it "Log Connected TS Sessions.vbs". I set the sampling interval to 60
seconds (that's 60,000 thousandths), which you can change by modifying this
line:
 
Const cInterval = 60000 ' 60000 = 60 seconds 
 
  Just multiply 60,000 by the number of minutes you want to use for your
sampling interval and re-save it. 
  Because this is VBScript, there's not a convenient way to end it when
you're through collecting the data, so you'll have to open Task Manager and
end the Wscript.exe process when you're finished. 
  The output file is a CSV file that you can open in Excel. To graph it,
just open the file, highlight the three columns (or you can just highlight
everything), and click the "Chart Wizard" button in the toolbar. Choose
"Line" as the chart type and pick whatever sub-type suits you. Click Finish
and you'll have your graph.
  I borrowed the CMD function from whoever's web page is located at
http://dev.remotenetworktechnology.com/wsh/lib/tslib.htm, so thanks to
whoever you are. That function lets you get the output of a program executed
by the shell, in this case: QUSER.EXE. Needless to say, the script relies on
QUSER.EXE.
 
Regards,
 
Jeff Durbin
Red Fish Information Systems Limited
www.redfish.co.nz <http://www.redfish.co.nz/> 
 
 
-----Original Message-----
From: thin-bounce@xxxxxxxxxxxxx [mailto:thin-bounce@xxxxxxxxxxxxx] On Behalf
Of Roger Riggins
Sent: 12 December 2003 2:32 PM
To: thin@xxxxxxxxxxxxx
Subject: [THIN] track user load at given time intervals


I'd like to be able to see how many users were logged in during certain time
intervals over a period of about a week. Something like perfmon to give me a
nice line graph would be perfect. The counter for session latency doesn't do
what I'd like.
 
Anybody know of a tool to do this?
 
Thanks,
R
 Notice of Confidentiality:
This e-mail and any attachments may contain privileged and/or confidential
information. This e-mail is intended solely for the use of the individual or
entity to which it is addressed. If you are not the intended recipient of
this e-mail, you are hereby notified that any copying, distribution,
dissemination or action taken in relation to the contents of this e-mail and
any of its attachments is strictly prohibited and may be unlawful. If you
have received this e-mail in error, please notify the sender immediately and
permanently delete the original e-mail and destroy any copies or printouts
of this e-mail as well as any attachments. Please note Lutheran Services in
Iowa does not endorse any opinions, conclusions or other information
contained within this message that does not pertain to official business.

Other related posts: