Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52516

Re: Reading log and saving data to DB

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <marduk@python.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'init': 0.07; 'received:internal': 0.09; 'python': 0.11; 'chunks': 0.16; 'eof': 0.16; 'expecting': 0.16; 'frameworks?': 0.16; 'irrespective': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'rarely': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'simplest': 0.16; 'subject:Reading': 0.16; 'subject:log': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'all,': 0.19; 'file,': 0.19; 'server,': 0.19; 'aug': 0.22; 'install': 0.23; 'this?': 0.23; 'byte': 0.24; 'script.': 0.24; 'question': 0.24; 'script': 0.25; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; 'lines': 0.31; 'run': 0.32; 'running': 0.33; 'received:66': 0.35; 'but': 0.35; 'add': 0.35; '14,': 0.36; 'achieving': 0.36; 'set.': 0.36; 'subject:data': 0.36; 'ubuntu': 0.36; 'similar': 0.36; 'should': 0.36; 'behind': 0.37; 'received:10': 0.37; 'server': 0.38; 'writes': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'does': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'read': 0.60; 'course.': 0.60; 'guy': 0.60; 'logs': 0.60; 'worry': 0.60; 'customized': 0.61; 'new': 0.61; 'simple': 0.61; 'save': 0.62; 'header:Message-Id:1': 0.63; 'minutes': 0.67; 'reads': 0.68; 'reading,': 0.84; '2013,': 0.91
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=7tCDiTd6IwyBe81PZ2jklW97Lh4=; b=BQO Kq34mw+j8Ikg3+A/4/XP4AtraxL2yYuoooLNAQX4v6qWEosYhW0khiYqai93V+ts X3LprZ3AkGxoahAMjDp2AdkMENVF4CcJGkZZ34ly69kKxBsqNSQkqJbyBufEk8CM wHLwFKtoEiK+YBCZAGBVMiCYd4pLl3Rddls8AV14=
X-Sasl-Enc pDRX8EzBNZHxxQU6obFlNMuCxASyZka98yH5AzIx0H9i 1376487969
From "marduk@python.net" <marduk@python.net>
To python-list@python.org
MIME-Version 1.0
Content-Transfer-Encoding 7bit
Content-Type text/plain
X-Mailer MessagingEngine.com Webmail Interface - ajax-d9f253bf
In-Reply-To <4de52359-d352-4e35-afed-73df672c945c@googlegroups.com>
References <4de52359-d352-4e35-afed-73df672c945c@googlegroups.com>
Subject Re: Reading log and saving data to DB
Date Wed, 14 Aug 2013 09:46:09 -0400
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.576.1376487972.1251.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376487972 news.xs4all.nl 15873 [2001:888:2000:d::a6]:57416
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52516

Show key headers only | View raw



On Wed, Aug 14, 2013, at 09:18 AM, Guy Tamir wrote:
> Hi all,
> 
> I have a Ubuntu server running NGINX that logs data for me.
> I want to write a python script that reads my customized logs and after 
> a little rearrangement save the new data into my DB (postgresql).
> 
> The process should run about every 5 minutes and i'm expecting large
> chunks of data on several 5 minute windows..
> 
> My plan for achieving this is to install python on the server, write a
> script and add it to cron.
> 
> My question is what the simplest way to do this? 
> should i use any python frameworks? 

Rarely do I put "framework" and "simplest way" in the same set.

I would do 1 of 2 things:

* Write a simple script that reads lines from stdin, and writes to the
db.  Make sure it gets run in init before nginx does and tail -F -n 0 to
that script.  Don't worry about the 5-minute cron.

* Similar to above but if you want to use cron also store in the db the
offset of the last byte read in the file, then when the cron job kicks
off again seek to that position + 1 and begin reading, at EOF write the
offset again.

This is irrespective of any log rotating that is going on behind the
scenes, of course.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Reading log and saving data to DB Guy Tamir <guytamir1@gmail.com> - 2013-08-14 06:18 -0700
  Re: Reading log and saving data to DB "marduk@python.net" <marduk@python.net> - 2013-08-14 09:46 -0400
    Re: Reading log and saving data to DB Guy Tamir <guytamir1@gmail.com> - 2013-08-15 00:23 -0700
  Re: Reading log and saving data to DB Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-14 18:34 -0400
    Re: Reading log and saving data to DB Guy Tamir <guytamir1@gmail.com> - 2013-08-15 00:16 -0700

csiph-web