0

I know that there are a lot of datetime parsing questions here and, of course, there are many docs out there on the web but even with all that I'm still scratching my head on the best way to do this after hours of reading, trial and error (and, boy, have there been errors).

So, I need to parse SAR memory logs under linux over a range of days, returning data in JSON format for presentation in graphical format in a browser.

I'm just about there - it looks great in Chrome but I need to improve the output date format to maximise x-browser capability.

So, to do this I need to work with two things

  1. A datetime object that is set to the date of the sar log I'm reading
  2. A string from the log entry in the form '10:01:30 PM'

I want to be able to combine these into a string formatted as 'YYYY-MM-DDT22:01:30'

The bodge I'm using at the moment is

jDict['timestamp'] = d.strftime("%Y-%m-%d") + " " + timeStr

where d is my datetime object and timeStr is the time string from the log entry. Chrome is letting me get into bad habits and is happy to parse that format, but FF is stricter.

EDIT @dawg below has asked for a sample of input and output

Example sar log format:

05:15:01 PM   2797588  13671876     83.01    228048   8276332   8249908     39.92
05:25:01 PM   2791396  13678068     83.05    228048   8276572   8455572     40.92
05:35:01 PM   2786104  13683360     83.08    228048   8282040   8249852     39.92

Current Output format:

 [
 {"timestamp": "2014-02-03 01:35:01 PM", "memtot": 16469464, "memused": 15747980}, 
 {"timestamp": "2014-02-03 01:45:01 PM", "memtot": 16469464, "memused": 15791088}, 
 {"timestamp": "2014-02-03 01:55:01 PM", "memtot": 16469464, "memused": 15690408}
 ]

Obviously I've not matched times and dates here - just some random lines

PerryW
  • 1,426
  • 1
  • 15
  • 25

1 Answers1

0

Or just give up and use moment.js in the browser - that's what I went for in the end. Downside is another library to load but it does just make the problem go away

PerryW
  • 1,426
  • 1
  • 15
  • 25