in reply to Bandwidth measurement with Perl?

See the Win32::PerfLib module (it comes as standard with ActiveState distributions). It gives you access to some 240+ counters (XP, other versions vary). The API is not the easiest in the world to use, but the following program lists all the counters + a textual description of what they are. See the module POD for further info;

#! perl -slw use strict; use Data::Dumper; use Win32::PerfLib; my( %counterNames, %counterHelp ); Win32::PerfLib::GetCounterNames( undef, \%counterNames ); Win32::PerfLib::GetCounterHelp( undef, \%counterHelp ); print "There are ${\ keys %counterNames } performance counters availab +le."; for my $key ( sort{ $a <=> $b } keys %counterNames ) { print "$key: $counterNames{ $key }"; ( my $wrapped = $counterHelp{ $key+1 } || 'n/a' ) =~ s[(.{0,64})\b +\s][$1\n\t]g; print "\t$wrapped\n"; } __END__ There are 242 performance counters available. 1: 1847 n/a 2: System The System performance object consists of counters that apply +to more than one instance of a component processors on the computer. 4: Memory The Memory performance object consists of counters that describe the behavior of physical and virtual memory on the computer. Physical memory is the amount of random access memo +ry on the computer. Virtual memory consists of the space in physical memory and on disk. Many of the memory counters monitor paging, which is the movement of pages of code and dat +a between disk and physical memory. Excessive paging, a symptom of a memory shortage, can cause delays which interfere with al +l system processes. 6: % Processor Time % Processor Time is the percentage of elapsed time that the processor spends to execute a non-Idle thread. It is calculate +d by measuring the duration of the idle thread is active in the sample interval, and subtracting that time from interval duration. (Each processor has an idle thread that consumes cycles when no other threads are ready to run). This counter i +s the primary indicator of processor activity, and displays the average percentage of busy time observed during the sample interval. It is calculated by monitoring the time that the service is inactive, and subtracting that value from 100%. 10: File Read Operations/sec File Read Operations/sec is the combined rate of file system read requests to all devices on the computer, including reques +ts to read from the file system cache. It is measured in numbers of reads. This counter displays the difference between the values observed in the last two samples, divided by the durati +on of the sample interval. [...] 274: Read Bytes Network/sec Read Bytes Network/sec is the rate at which applications are reading data across the network. This occurs when data sought +in the file system cache is not found there and must be retrieved from the network. Dividing this value by Bytes Received/sec indicates the proportion of application data traveling across the network. (see Bytes Received/sec). 276: Bytes Transmitted/sec Bytes Transmitted/sec is the rate at which bytes are leaving t +he Redirector to the network. It includes all application data a +s well as network protocol information (such as packet headers a +nd the like). 278: Packets Transmitted/sec Packets Transmitted/sec is the rate at which the Redirector is sending packets (also called SMBs or Server Message Blocks). Network transmissions are divided into packets. The average number of bytes transmitted in a packet can be obtaine +d by dividing Bytes Transmitted/sec by this counter. 280: Write Bytes Paging/sec Write Bytes Paging/sec is the rate at which the Redirector is attempting to write bytes changed in the pages being used by applications. The program data changed by modules (such as programs and libraries) that were loaded over the network are 'paged out' when no longer needed. Other output pages come fr +om the file system cache (see Write Bytes Cache/sec). 282: Write Bytes Non-Paging/sec Write Bytes Non-Paging/sec is the rate at which bytes are written by the Redirector in response to normal file outputs b +y an application when they are redirected to another computer. +In addition to file requests, this count includes other methods o +f writing across the network, such as Named Pipes and Transactions. This counter does not count network protocol information, just application data. 284: Write Bytes Cache/sec Write Bytes Cache/sec is the rate at which applications on you +r computer are writing to the file system cache by using the Redirector. The data might not leave your computer immediately; it can be retained in the cache for further modification before being written to the network. This saves network traffic. Each write of a byte into the cache is count +ed here. 286: Write Bytes Network/sec Write Bytes Network/sec is the rate at which applications are writing data across the network. This occurs when the file system cache is bypassed, such as for Named Pipes or Transactions, or when the cache writes the bytes to disk to ma +ke room for other data. Dividing this counter by Bytes Transmitted/sec will indicate the proportion of application da +ta being to the network (see Transmitted Bytes/sec). 288: Read Operations/sec File Read Operations/sec is the rate at which applications are asking the Redirector for data. Each call to a file system or similar Application Program Interface (API) call counts as one operation. 290: Read Operations Random/sec Read Operations Random/sec counts the rate at which, on a file-by-file basis, reads are made that are not sequential. I +f a read is made using a particular file handle, and then is followed by another read that is not immediately the contiguou +s next byte, this counter is incremented by one. 292: Read Packets/sec Read Packets/sec is the rate at which read packets are being -- More --

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^2: Bandwidth measurement with Perl?
by DaWolf (Curate) on Sep 08, 2004 at 05:29 UTC