Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPU metrics to CLI, Jobs and automate start #705

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions agent/agent
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ exit
# License along with this program; If not, see <https://www.gnu.org/licenses/>
########################################################################
#load files
#Accept argument of port for agent to run on. No argument generates random port number
if {$argc == 0} {
set port {}
set restart true
} else {
if {$argc != 1} {
puts {Usage: agent port}
#exit
} else {
set restart false
set port [lindex $argv 0]
if { ![string is entier $port] } {
puts {Usage: agent port}
#exit
} else { ; }
}
}
set UserDefaultDir [ file dirname [ info script ] ]
::tcl::tm::path add "../$UserDefaultDir/modules"
package require comm
Expand Down Expand Up @@ -116,7 +133,7 @@ global cpu_model
}
}

proc ConfigureNetworkAgent { } {
proc ConfigureNetworkAgent { port restart } {
global agentlist S connectestablished
set chanlist [ lindex [ ::comm channels ] end ]
if { $chanlist eq "::Slave" } {
Expand All @@ -125,7 +142,7 @@ if { [catch { $chanlist destroy } b] } {
puts "Error $b"
}
}
if { [catch {::comm new Agent -listen 1 -local 0 -silent "TRUE" -port {}} b] } {
if { [catch {::comm new Agent -listen 1 -local 0 -silent "TRUE" -port $port} b] } {
puts "Creation Failed : $b" } else {
puts "HammerDB Metric Agent active @ id [ Agent self ] hostname [ info hostname ] (Ctrl-C to Exit)"
Agent hook incoming {
Expand All @@ -136,19 +153,29 @@ set connectestablished 1
}
}
Agent hook lost {
global agentlist S connectestablished
global agentlist S connectestablished restart
set todel [ lsearch $agentlist $id ]
if { $todel != -1 } {
puts "Connection to display $id lost: $reason"
unset -nocomplain connectestablished
if {$restart} {
puts "Reinitializing HammerDB Metric Agent"
} else {
puts "Closing HammerDB Metric Agent"
}
set agentlist [ lreplace $agentlist $todel $todel ]
set ::DONE 2
}
}
Agent hook eval {
global agentlist S
if {[regexp {\"([0-9]+)\W([[:alnum:],[:punct:]]+)\"} $buffer all id host]} {
if { [ string match "*STOP*" $buffer ] } {
#Received Message to Stop Metrics before a Display connection
puts "Closing HammerDB Metric Agent"
::Agent destroy
exit
}
lappend agentlist "$id $host"
puts "New display accepted @ $id $host"
#Start Gathering and Sending Metrics
Expand Down Expand Up @@ -211,7 +238,7 @@ puts "connection established"
if $iswin {
set fin [open "| mpstat.bat" r]
} else {
set fin [open "|mpstat -P [join $::S(cpus,list) ,] 2" r]
set fin [open "|mpstat -P ALL 2" r]
}
fconfigure $fin -blocking false
fileevent $fin readable [list isReadable $fin]
Expand Down Expand Up @@ -241,12 +268,16 @@ HowManyProcessorsLinux
}

puts "Initializing HammerDB Metric Agent $version"
ConfigureNetworkAgent
ConfigureNetworkAgent $port $restart
vwait ::DONE
while 1 {
#Lost connection, reinitialize agent
::Agent destroy
unset -nocomplain ::DONE
ConfigureNetworkAgent
if {$restart} {
ConfigureNetworkAgent $port $restart
vwait ::DONE
} else {
exit
}
}
2 changes: 1 addition & 1 deletion agent/agent.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@echo off
set path=..\.\bin;%PATH%
START tclsh86t .\agent
START tclsh86t .\agent %1
3 changes: 2 additions & 1 deletion agent/mpstat.bat
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ set cpus_per_node [ expr $cpu_count / $numa_node_count ]
puts "Mpstat for Windows $osinfo $osversion {$hostname} [clock format [twapi::large_system_time_to_secs_since_1970 [twapi::get_system_time]] -format "%d/%m/%Y"] {$cpu_count CPU}\n"
puts "[clock format [twapi::large_system_time_to_secs_since_1970 [twapi::get_system_time]] -format "%I:%M:%S %p"]\tCPU\t%usr\t%nice\t%sys\t%iowait\t%irq\t%soft\t%steal\t%guest\t%idle"
#Define Query
set qh [ twapi::pdh_system_performance_query user_utilization_per_cpu privileged_utilization_per_cpu interrupt_utilization_per_cpu idle_utilization_per_cpu]
set qh [ twapi::pdh_system_performance_query user_utilization privileged_utilization interrupt_utilization idle_utilization user_utilization_per_cpu privileged_utilization_per_cpu interrupt_utilization_per_cpu idle_utilization_per_cpu]
#Get Data
while {1} {
set cpu_number 0
catch { twapi::pdh_query_update $qh }
catch { set perf_data [ twapi::pdh_query_get $qh ] }
if { [ info exists perf_data ] } {
if { [ dict size $perf_data ] > 0 } {
puts "[clock format [clock seconds] -format "%I:%M:%S %p"]\tall\t[format "%.2f" [ dict get $perf_data user_utilization ]]\t0.00\t[format "%.2f" [dict get $perf_data privileged_utilization ]]\t0.00\t[format "%.2f" [ dict get $perf_data interrupt_utilization ]]\t0.00\t0.00\t0.00\t[format "%.2f" [ dict get $perf_data idle_utilization ]]"
for {set i 0} {$i < $numa_node_count} {incr i} {
for {set j 0} {$j < $cpus_per_node} {incr j} {
puts "[clock format [clock seconds] -format "%I:%M:%S %p"]\t$cpu_number\t[format "%.2f" [ dict get [ dict get $perf_data user_utilization_per_cpu ] $i,$j ]]\t0.00\t[format "%.2f" [dict get [ dict get $perf_data privileged_utilization_per_cpu ] $i,$j ]]\t0.00\t[format "%.2f" [dict get [ dict get $perf_data interrupt_utilization_per_cpu ] $i,$j ]]\t0.00\t0.00\t0.00\t[format "%.2f" [ dict get [ dict get $perf_data idle_utilization_per_cpu ] $i,$j ]]"
Expand Down
2 changes: 1 addition & 1 deletion config/generic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<metrics>
<metric_options>
<agent_hostname>localhost</agent_hostname>
<agent_id>0</agent_id>
<agent_id>10000</agent_id>
</metric_options>
</metrics>
<datageneration>
Expand Down
2 changes: 1 addition & 1 deletion hammerdbcli
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ set cli_common_init {set UserDefaultDir [ file dirname [ info script ] ]
}
}

append loadlist { genvu.tcl gentpcc.tcl gentpch.tcl gengen.tcl genxml.tcl genmodes.tcl gentccmn.tcl gentccli.tcl geninitcli.tcl gencli.tcl genhelp.tcl genstep.tcl }
append loadlist { genvu.tcl gentpcc.tcl gentpch.tcl gengen.tcl genxml.tcl genmodes.tcl genmetricscli.tcl gentccmn.tcl gentccli.tcl geninitcli.tcl gencli.tcl genhelp.tcl genstep.tcl }
for { set loadcount 0 } { $loadcount < [llength $loadlist] } { incr loadcount } {
set f [lindex $loadlist $loadcount]
set loadtext $f
Expand Down
Loading