Sponsored Content
Top Forums Shell Programming and Scripting Suggestions for Inserting Missing Timestamps Post 302395066 by durden_tyler on Sunday 14th of February 2010 06:37:41 PM
Old 02-14-2010
Quote:
Originally Posted by st33lz
...
I need to insert each missing second and a zero for the request.

I'm really not sure how to go about doing that. I guess create a loop that would create a time stamp for each second of the 24 hour period (84600 seconds) and then grep the file for that second.
...
Here's a Perl solution that generates such data for today. A slight variation though. To grep a file for every second in the day would not be too efficient.

Instead, this program goes through the file first and populates a hash that has the timestamp as the key and number of requests as its value.

Thereafter, it generates the loop for all seconds for today and either prints the number of requests, if it exists in the hash, or 0 if not.

Code:
$ 
$ # display the contents of the log file
$ # I've added boundary values to ensure the loop works as expected
$ cat apache.log
00:00:00 997
00:00:01 998
00:00:02 999
00:00:03 1000
03:04:01 3
03:04:03 2
03:04:04 1
03:04:05 1
03:04:07 2
23:59:56 997
23:59:57 998
23:59:58 999
23:59:59 9999
$ 
$ # show the Perl program
$ cat -n apache.pl
     1  #!/usr/bin/perl -w
     2  use Date::Calc qw(Today Add_Delta_DHMS);
     3
     4  # first, go through the log file and fill up the hash %requests
     5  $logfile="apache.log";
     6  open (LOG, $logfile) or die "Can't open $logfile: $!";
     7  while (<LOG>) {
     8    chomp(@x = split);
     9    $requests{$x[0]} = $x[1];
    10  }
    11  close (LOG) or die "Can't close $logfile: $!";
    12
    13  # now generate the loop for today, and print the 
    14  # key value if present in the hash, or 0 otherwise
    15  ($year,$month,$day) = Today;
    16  $hour = $min = $sec = 0;
    17  foreach (1..24*60*60) {
    18    $hms = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
    19    $reqnum = defined ($requests{$hms}) ? $requests{$hms} : 0;
    20    printf("%02d/%02d/%04d %02d:%02d:%02d %s\n",$month,$day,$year,$hour,$min,$sec,$reqnum);
    21    ($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS($year,$month,$day,$hour,$min,$sec,0,0,0,1);
    22  }
    23
$
$ # now run the program
$ # I've snipped most of the output to save storage space, and
$ # to keep forum members from thinking I've lost my mind. ;)
$ # You may want to redirect the output to a file.
$
$ perl apache.pl
02/14/2010 00:00:00 997
02/14/2010 00:00:01 998
02/14/2010 00:00:02 999
02/14/2010 00:00:03 1000
02/14/2010 00:00:04 0
02/14/2010 00:00:05 0
02/14/2010 00:00:06 0
...
...
02/14/2010 03:04:00 0
02/14/2010 03:04:01 3
02/14/2010 03:04:02 0
02/14/2010 03:04:03 2
02/14/2010 03:04:04 1
02/14/2010 03:04:05 1
02/14/2010 03:04:06 0
02/14/2010 03:04:07 2
02/14/2010 03:04:08 0
...
...
02/14/2010 23:59:54 0
02/14/2010 23:59:55 0
02/14/2010 23:59:56 997
02/14/2010 23:59:57 998
02/14/2010 23:59:58 999
02/14/2010 23:59:59 9999
$ 
$

HTH,
tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix timestamps

Can someone help me with a Unix or perl script to convert the unix timestamps to human readable format? Any help will be highly appreciated... (3 Replies)
Discussion started by: hamsasal
3 Replies

2. Solaris

Difference between two timestamps

I'm writting a script to find the difference between two timestamp. One field i get on delivery time of the file like 07:17 AM and other is my SLA time 06:30 AM I need to find the difference between these two time (time exceeded to meet SLA). Need some suggestions. (8 Replies)
Discussion started by: raman1605
8 Replies

3. Shell Programming and Scripting

timestamps

Hello! I have the following problem. I read a file using perl, each line of this file has the fllowing format. 14/4/2008 8:42:03 πμ|10800|306973223399|4917622951117|1||1259|1|126|492|433||19774859454$ Th first field is the timestamp and the second field is the offset in seconds. How can... (1 Reply)
Discussion started by: chriss_58
1 Replies

4. Shell Programming and Scripting

Compare Timestamps

Hi! Long time reader first time registered user and poster. I've picked up some times and tricks and I'm at a dead end... I've parsed a log file for duplicates and printed only the two fields I need (duplicate entry and time stamp). My question is, with this output, how would I script... (2 Replies)
Discussion started by: rexpokinghorn
2 Replies

5. Shell Programming and Scripting

Help with touch and timestamps

Hello fellow Unix geeks, I have been given a very urgent assignment in my office on writing a particular Shell script but I'm very much new to it.I would appreciate any help from you on solving this problem--which might seem very trivial to you. The Unix flavour is a Sun Solaris one..(not... (6 Replies)
Discussion started by: Digjoy83
6 Replies

6. Shell Programming and Scripting

Comparing two timestamps

Hi all!!, I'm using Ksh and working on Linux. I want to compare two timestamps, timestamp1 and timestamp2. Until, timestamp1 is lesser than timestamp2, i want to do something, lets say print something. The code i have written is: a=`date +%H:%M:%S` b=`date +%H:%M:%S -d" 1... (1 Reply)
Discussion started by: Jayaraman
1 Replies

7. SuSE

How to resolve missing missing dependencies with opensuse 11.3 and 12.3?

Hello, This is a programming question as well as a suse question, so let me know if you think I should post this in programming. I have an application that I compiled under opensuse 12.2 using g77-3.3/g++3.3. The program compiles and runs just fine. I gave the application to a colleague who... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

8. Red Hat

Yum - resolving missing dependencies that are not missing

I am trying to install VirtualBox on RHEL 5 but I need the 32 bit version for 32 bit Windows. When I run yum I get the following: sudo yum localinstall /auto/spvtg-it/spvss-migration/Software/VirtualBox-4.3-4.3.2_90405_el6-1.i686.rpm Loaded plugins: fastestmirror Setting up Local Package... (13 Replies)
Discussion started by: gw1500se
13 Replies

9. Shell Programming and Scripting

Write with a look for timestamps

hello i'm using SOX to generate a spectrogram from a wave file with the command : #sox file.wav -n spectrogram is there a way to create a spectrogram using the same command but reading file timestamps instead of the namefile.wav , since name is changing every 4 hours? (it's saved with... (2 Replies)
Discussion started by: Board27
2 Replies

10. Shell Programming and Scripting

Merging multiple lines to columns with awk, while inserting commas for missing lines

Hello all, I have a large csv file where there are four types of rows I need to merge into one row per person, where there is a column for each possible code / type of row, even if that code/row isn't there for that person. In the csv, a person may be listed from one to four times... (9 Replies)
Discussion started by: RalphNY
9 Replies
PMDAAPACHE(1)						      General Commands Manual						     PMDAAPACHE(1)

NAME
pmdaapache - Apache2 web server performance metrics domain agent (PMDA) SYNOPSIS
$PCP_PMDAS_DIR/apache/pmdaapache [-d domain] [-l logfile] [-U username] [-S server] [-P port] [-L location] DESCRIPTION
pmdaapache is a Performance Metrics Domain Agent (PMDA) which extracts performance metrics describing the state of an Apache web server. The apache PMDA exports metrics that measure the request rate, cumulative request sizes, uptime and various connection states for active clients. This information is obtained by performing a HTTP request to the server status URL, which must be enabled in the httpd.conf configuration file. ExtendedStatus on <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from localhost </Location> A brief description of the pmdaapache command line options follows: -d It is absolutely crucial that the performance metrics domain number specified here is unique and consistent. That is, domain should be different for every PMDA on the one host, and the same domain number should be used for the same PMDA on all hosts. -l Location of the log file. By default, a log file named apache.log is written in the current directory of pmcd(1) when pmdaapache is started, i.e. $PCP_LOG_DIR/pmcd . If the log file cannot be created or is not writable, output is written to the standard error instead. -S Query the Apache status information from the named server rather than the local host. -P Query the Apache status information from the given port rather than the default (80). -L Specify an alternative location for finding the server-status page. -U User account under which to run the agent. The default is the unprivileged "pcp" account in current versions of PCP, but in older versions the superuser account ("root") was used by default. INSTALLATION
If you want access to the names, help text and values for the apache performance metrics, do the following as root: # cd $PCP_PMDAS_DIR/apache # ./Install If you want to undo the installation, do the following as root: # cd $PCP_PMDAS_DIR/apache # ./Remove pmdaapache is launched by pmcd(1) and should never be executed directly. The Install and Remove scripts notify pmcd(1) when the agent is installed or removed. FILES
$PCP_PMCDCONF_PATH command line options used to launch pmdaapache $PCP_PMDAS_DIR/apache/help default help text file for the apache metrics $PCP_PMDAS_DIR/apache/Install installation script for the pmdaapache agent $PCP_PMDAS_DIR/apache/Remove undo installation script for the pmdaapache agent $PCP_LOG_DIR/pmcd/apache.log default log file for error messages and other information from pmdaapache PCP ENVIRONMENT
Environment variables with the prefix PCP_ are used to parameterize the file and directory names used by PCP. On each installation, the file /etc/pcp.conf contains the local values for these variables. The $PCP_CONF variable may be used to specify an alternative configura- tion file, as described in pcp.conf(5). SEE ALSO
PCPIntro(1), httpd(8), pmcd(1), pcp.conf(5) and pcp.env(5). Performance Co-Pilot PCP PMDAAPACHE(1)
All times are GMT -4. The time now is 02:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy