Tuesday, February 10, 2009
a free alternative to wireshark's pilot
I am using the tcptrace program to read the log files from wireshark, and Ploticus to pipe the data to a graph. tcptrace can create graphs, but not of tcp ports/percentages. So Im in the process of whipping up a bash/awk script that takes the output from tcptrace's port information dump, cleans up and drops it into a file that ploticus can read, in megabytes.
The really quick and dirty way to get the top 10 TCP port usage in bytes is as follows:
tcptrace -xtraffic <.cap file>
#this outputs a file called traffic_byport.dat)
sort -nr -k 4 traffic_byport.dat | awk 'NR==2,NR==11' > TCPtop10
#this numerically & reverse sorts column 4 of traffic_byport.dat (the bytes data),
# then it prints out lines 2-11 (line 1 has title data, don't need it for the script)
# after awking, it prints out the top 10 TCP port usage, in bytes.
I have also spit out a very rough and dirty way to transform the bytes to megabytes with a .00 decimal place in order to graph the data properly. But Im going to look into a better way to merge columns in awk before I post anything.
Debugging a shell script
sh -x script.sh
the -x switch echo's everything in the script line by line until there is an error in the script. the errors are printed out next to the line that errored out. VERY VERY useful! Instead of writing 50+ lines of scripts and spending all day debugging it, the -x does all my work for me. i have used strace
Monday, February 9, 2009
Print queue check script
Needless to say, I wrote the script anyway. Im sure I can pilfer bits and pieces of it for another quick script later.
#!/bin/bash
### Removes Print jobs from the print queue
### Command:
#Query printer for print queue, then drop data to jobid file
lpq -P $1 awk '{print $3}' > jobid
# remove all print jobs from specified printer
cat jobid xargs lprm
# Query printer queue again and let admin know that the jobs have been removed
lpq -P $1
echo 'Print jobs removed'
# remove temp file
rm -rf jobid
Thursday, February 5, 2009
nagiosgraph & windows clients
So, 3 days into searching just about everything on the web for nagiosgrapher and windows server map files, I finally found a website that guided me in the right direction.
http://nerhood.wordpress.com/2004/09/22/nagiosgraph-with-windows-support/
As you can see, the article is over 4 years old, but yet I couldn't find anything else on the web with nagiosgrapher and nsclient++. So, just in case I will post parts of my nagiosgraph/maps file in case someone else comes across this blog looking for nagiosgraphing and nsclient++ integration.
By the way, it's AWESOME! Nagiosgrapher has already caught a few problems that we had suspected, and provides a visual tool for sys admins looking back at historical data.
/nagiosgraph/map
# Service type: memory
# check command: check_nt -H Address -v MEMUSE -w 50 -c 90
#output: Memory usage: tootal:2467.75 Mb - used: 510.38 Mb (21%) - free: 1957.37 Mb (79%)
/perfdata:Memory usage=([.0-9])+Mb;([.0-9+);([.0-9+);([.0-9+);([.0-9]+)/
and push @s, [ntmem,
[memused, GAUGE, $1*1024**2 ]
];
# Service type: ntload
# Check command: check_nt -H Address -v CPULOAD -l1,70,90,5,70,90,30,70,90
# output: CPU Load 9% (5 min average) 11% (30 min average)
#perfdata: '5 min avg Load'=9%;70;80;0;100 '30 min avg Load'=11%;70;90;0;100
/output:.*?(\d+)% .*?(\d+)% /
and push @s, [ ntload,
[ avg05min, GAUGE, $1 ],
[avg30min, GAUGE, $2 ] ];
# Service type: ntdisk
# check command: check_nt -H Address -v USEDDISKSPACE -lc -w 75 -c 90
# output: c:\ - total: 25.87 Gb - used: 4.10 Gb (16%) - free 21.77 Gb (84%)
# perfdata: c:\ Used Space=4.10Gb;19.40;23.28;0.00;25.87
/perfdata:.*Space=([.0-9]+)Gb;([.0-9]+);([.0-9]+);([.0-9]+);([.0-9]+)/
and push @s, [ ntdisk,
[ diskused, GAUGE, $1*1024**3 ],
[ diskwarn, GAUGE, $2*1024**3 ],
[ diskcrit, GAUGE, $3*1024**3 ],
[ diskmaxi, GAUGE, $5*1024**3 ] ];
Alas! Blogger seems to put a .5 space between the code, o'well, at least one can tell where the code begins and ends. So once the map file has been populated, you can check your syntax with:
perl -c map
output should be: map syntax OK. From there, .rrd files should start generating in the hosts file under /rrd (or wherever one has setup their /rrd directory).
Wednesday, February 4, 2009
First Post - Intro & Linux Memory tips
As stated earlier, I have been a linux systems admin off-and-on since 1997, both as a Sys Admin, Linux Sys Admin Instructor for a computer consulting company, and even a Sun Solaris Systems Engineer for a large web tool development company. Currently I am the Linux Systems Administrator for a company out in the midwest.
So, from time to time I will be posting various sys-admin scripts that I have written during the week, tips and tricks on how to get things functional in a Mixed OS environment (such as Samba w/ Active Directory Sync, SQUID & Active Directory, etc).
These posts follow what pit-falls that I ran into for the day, and how I solved each one with whatever script, how-to, etc.
So, today is nice and quick (slow day at work).
I was asked by one of the developers how to check swap space in linux:
free -t -m (shows total memory and in megabytes)
also:
vmstat (reports virtual memory statistics, -s for counter & mem stats, -s m for summary in megabytes)