Forum Discussion
Export to Excel or .CSV
I would like to export CLI information, mostly performance information, to MSExcel or to a CSV file. I tried redirection from the command line. Is this redirection possible?
13 Replies
- JRahm
Admin
possible, but would require some scripting work in tmsh, bash, perl, or python.
- uni_87886
Cirrostratus
You can get stats in a reasonably usable for using the field-fmt option of the show commands. For example
tmsh show ltm virtual field-fmt rawIt's not csv, but not too hard to parse either
- nkingcade_12003
Nimbostratus
how do I parse it?
- uni
Altocumulus
You can get stats in a reasonably usable for using the field-fmt option of the show commands. For example
tmsh show ltm virtual field-fmt rawIt's not csv, but not too hard to parse either
- nkingcade_12003
Nimbostratus
how do I parse it?
- JRahm
Admin
I'm working on a script to look at real time interface statistics, and I'm parsing with TMSH using lindex and splitting on line numbers.
proc script::run {} { tmsh::clear_screen if { $tmsh::argc == 1 } { set int [getFeedback "Please enter the interface number (ie, 1.1): "] } else { set int [lindex $tmsh::argv 1] } set l1 [] set l2 [] set interval [getFeedback "Please enter refresh rate for the stats (in seconds): "] set delay [expr $interval * 1000] lappend l1 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 1] 1] lappend l1 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 2] 1] while { true } { after $delay lappend l2 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 1] 1] lappend l2 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 2] 1] tmsh::clear_screen set s1 $l1 set s2 $l2 set statsIn [expr ([lindex $s2 0] - [lindex $s1 0]) / $interval] set statsOut [expr ([lindex $s2 1] - [lindex $s1 1]) / $interval] puts "Interface\t\tInbound (bps)\t\tOutbound (bps)" puts "$int\t\t\t$statsIn\t\t\t$statsOut" set l1 $l2 unset l2 } }I would suggest instead of using a while loop, you can just use puts and commas for each field.
- JRahm
Admin
FYI, the getFeedback is a proc in the same TMSH script:
proc getFeedback { question } { puts -nonewline $question flush stdout return [gets stdin] } - uni_87886
Cirrostratus
Jason's method above is great if it is long term. For a quick-and-dirty solution, this perl will convert your output for you. Put it in a file, such as field-to-csv, and run it like this:
tmsh show ltm virtual field-fmt raw | field-to-csv!/usr/bin/perl while ($line = <>) { chomp($line); if ($line =~ /{/) { $out = ""} elsif ($line =~ /}/) { print "$out\n" } else { $out .= "," if (length($out) != 0); ($field,$value) = split(" ",$line,2); if ($value =~ /,/) { $out .= "\"$value\"" } else { $out .= $value } } }- uni_87886
Cirrostratus
finally got the formatting right - gratlmichael_22
Nimbostratus
Has anyone the script ready for the export the performance data to csv? mem usage, packets, ssl transactions, http,.. Thanks!
- uni
Altocumulus
Jason's method above is great if it is long term. For a quick-and-dirty solution, this perl will convert your output for you. Put it in a file, such as field-to-csv, and run it like this:
tmsh show ltm virtual field-fmt raw | field-to-csv!/usr/bin/perl while ($line = <>) { chomp($line); if ($line =~ /{/) { $out = ""} elsif ($line =~ /}/) { print "$out\n" } else { $out .= "," if (length($out) != 0); ($field,$value) = split(" ",$line,2); if ($value =~ /,/) { $out .= "\"$value\"" } else { $out .= $value } } }- uni
Altocumulus
finally got the formatting right - gratlmichael_22
Nimbostratus
Has anyone the script ready for the export the performance data to csv? mem usage, packets, ssl transactions, http,.. Thanks!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com