Sum from successive lines following date header to create data for graphing connections


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sum from successive lines following date header to create data for graphing connections
# 1  
Old 12-19-2012
Sum from successive lines following date header to create data for graphing connections

Hi,
I have a log file created from a load balancer showing connections to each member of a two member pool with the following format (where first field is source IP, second field is load balanced IP address and third field is destination member. I need to plot a graph by date/time and number of connections to each pool member (third IP address). By about yesterday lunchtime...

Please would someone be able to point me at the best way of parsing this file to get output similar to:
date IP1 numconnections IP2 numconnections? I'm imagining awk, but just can't get my head round how to start at the moment.

Sorry to appear dumb and really, really grateful for any helpful replies! Smilie
Code:
Mon Dec 17 15:07:16 GMT 2012
10.96.244.4:4901 <-> 10.18.1.212:32150 <-> 10.18.1.229:32150 tcp
10.96.244.4:4902 <-> 10.18.1.212:32150 <-> 10.18.1.229:32150 tcp.
10.18.0.148:33257 <-> 10.18.1.212:32150 <-> 10.18.1.230:32150 tcp
Mon Dec 17 15:07:46 GMT 2012
10.96.244.4:4903 <-> 10.18.1.212:32150 <-> 10.18.1.229:32150 tcp
10.96.244.4:4904 <-> 10.18.1.212:32150 <-> 10.18.1.229:32150 tcp.
10.18.0.148:33258 <-> 10.18.1.212:32150 <-> 10.18.1.230:32150 tcp
10.18.0.148:33259 <-> 10.18.1.212:32150 <-> 10.18.1.230:32150 tcp
10.18.0.148:33260 <-> 10.18.1.212:32150 <-> 10.18.1.230:32150 tcp


Last edited by Franklin52; 12-19-2012 at 03:22 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 12-19-2012
You could use bash, with "while read -a FLDS;do ... done", stashing your stats in an associative array until the date changes or EOF. You might want to add a trailer line to the input stream for the latter behavior, perhaps just a fake high date line echo'd in to the stream inside "(...)|".

If you need more speed: C, C++, JAVA, PERL or a different flavor of shell script that pulls out dates, then pulls out each date's IPs using sed to a stream to '|sort|uniq -c'.

One thing that makes such an app cumbersome/odd is stacking many IPs on one line. Usually, you want RDBMS friendly tuples/rows, one per day and IP, on lines.
# 3  
Old 12-19-2012
Yes - thanks for the reply. That's pretty much what I did. Very clumsy and slow on a 3MB sized text file but it didn't take too much thought! I'm sure there're more elegant ways of doing it but I'll leave that for when I have a little more time...

The reasons I created it in the form that I did were:

1) It needed to be done by the previous lunchtime
2) I needed to be able to track who the connections were from.

A little more forethought and I would have created a second log file tracking purely the number of connections! Smilie

Thanks again Smilie
# 4  
Old 12-19-2012
Stick the data in an RDBMS and sum it there in SQL with simple web page reports.
# 5  
Old 12-19-2012
Quote:
Stick the data in an RDBMS and sum it there in SQL with simple web page reports.
Smilie

I had a pretty interesting time trying to use data points in a chart in MS Excel too - I didn't realise it was limited to 255 points!
# 6  
Old 12-19-2012
Sometimes it pays to get your graphing tool independent of your storage and loading. Tools that do many things often only do them "well enough". You can hook an RDBMS to Excel and let it graph stuff. You just need to keep your queries/views small. Maybe libreOffice spreadsheets or Google docs will do more? A nice tool would allow drill down on an abstracted graph.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. Shell Programming and Scripting

[sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern

I have a file like below. 2018.07.01, Sunday 09:27 some text 123456789 0 21 0.06 0.07 0.00 2018.07.02, Monday 09:31 some text 123456789 1 41 0.26 0.32 0.00 09:39 some text 456789012 1 0.07 0.09 0.09 09:45 some text 932469494 1 55 0.29 0.36 0.00 16:49 some text 123456789 0 48 0.12 0.15 0.00... (9 Replies)
Discussion started by: father_7
9 Replies

3. Shell Programming and Scripting

Please help, need to create script to remove lines by date in file

Please Help (novice to PERL and SHELL scripting)…. Need to create a script which removes all lines in $filename = "cycle_calendar_ftp_out" older than current date – a variable which will be a number of days passed to script. For Ex it will look at the end date which is the last field (4) and... (2 Replies)
Discussion started by: m3pwr
2 Replies

4. Shell Programming and Scripting

Graphing data with awk/while loop

I need to graph data that's in a file. however, i only know of a way to graph data as it comes (meaning, as it is spat out by whatever process or job). i dont know how to graph data in a file. im using rrdtool to graph data. and i was wondering if anyone know of a way to pass a file (the... (3 Replies)
Discussion started by: SkySmart
3 Replies

5. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum

Hi friends, This is sed & awk type question. It is slightly different from my previous question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers (but no more than 10 numbers in series) whenever i find it and produce an output file with the... (4 Replies)
Discussion started by: kaaliakahn
4 Replies

6. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

7. Shell Programming and Scripting

How to create DB2 Connections in While loop using shell script

Hi , I have to create a db2 connection for the while loop in shell scripting. Below is the connection for DB2 I have to establish connect to TABLESCHENMA user $USERID using $PASSWORD Below is the while loop. while read TABLE; do db2 LOAD CLIENT FROM $DIRECTORY/$TABLE.ixf OF ixf INSERT... (1 Reply)
Discussion started by: vikyalex4
1 Replies

8. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

9. Shell Programming and Scripting

Extract date from file header and prefix it to all lines

Hello All, I have a file in the following format. I want to extract the date(020090930, 020090929) in the string "STPAGE020090930" and "STPAGE020090929" and prefix it to all lines below them. The output must be put into a new file. STPAGE020090930 xyzz aalc... (3 Replies)
Discussion started by: john2022
3 Replies

10. UNIX for Dummies Questions & Answers

Extract specific lines for graphing

Hello, I have a very large text file with about 2 million lines. Each of the lines starts like.. SNP_12345678 A 1212, 121, 343, ... SNP_12345678 B 4567, 567, 454, ... and so on. I want to extract specific SNPs and plot them by GNUplot or excel. The file is too large to be opened by text... (1 Reply)
Discussion started by: genehunter
1 Replies
Login or Register to Ask a Question