pcp
[Top] [All Lists]

Re: [pcp] Help with Python API

To: David Smith <dsmith@xxxxxxxxxx>, Ken McDonell <kenj@xxxxxxxxxxxxxxxx>, pcp@xxxxxxxxxxx
Subject: Re: [pcp] Help with Python API
From: Rohan Arora <rarora2012@xxxxxxxxx>
Date: Wed, 08 Jul 2015 13:59:34 +0000
Delivered-to: pcp@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-type; bh=bVnbpPl+2pyux0Dknu0w4Acf/zkZu3kxpnekVTClb5U=; b=KxXUEByDr3j9OYxf3vFu0a9/1LKtuX+oR3hYGnk8+ppavxbOydQayIvIOWdUqvHENd wf2S6ECXZ6/xxSl6Mgm6xSLK1Oizg5SH+yabGGf8FzR1MUjZjHQjKFUQFDOVp9X62JK9 6SW3RgYB6t2TqUPktXCGOiTzVfo4+W88pMqmu8twBEfiOsFs6OVgbXj66oA1oaXJJBH5 lN3j3yWGz31cJ++FRZtwGMEUQXCSj7oEimkBYZ06IHFKlv321pPMIEJabEFYDXMQlbOJ MCBOhPKuL9Kp1d3Ytekoi4pvd5YQYHqh3us/4kfKWcflyLWdJkP+StJJAKi+rTghH+vB SSrA==
In-reply-to: <CANbxzdUYTi9w9s59Y=7CZ-W7OEc-D9XTZgavf9wysLpCvg1dkw@xxxxxxxxxxxxxx>
References: <CANbxzdXmsRFyF_J_7c93uBuKWJHZikoRs6xmSPQC91rALtZbNA@xxxxxxxxxxxxxx> <CANbxzdXVmBE1qRoHQQTy9VvbAt4rqppwEL-xizSUH7cKOswNzQ@xxxxxxxxxxxxxx> <CANbxzdV7Vndvczvo9OLgc8CpQ20wBK=YUD6v87ewVBa6yrTXKQ@xxxxxxxxxxxxxx> <CANbxzdXcqg=sRYa0JwETB+RHChw42uAeZE-n+bABUjV-FD9TDg@xxxxxxxxxxxxxx> <587447889.27462536.1435530714712.JavaMail.zimbra@xxxxxxxxxx> <CANbxzdX_4yDiOBqU954wjfbKOFOXnB8SJ_uiRsKEBdUk-hxF1w@xxxxxxxxxxxxxx> <CANbxzdUHygK=0NuO7L3pV+FERXa-LRL59=sumY5TznT0xzonxg@xxxxxxxxxxxxxx> <337532723.28653925.1435618315696.JavaMail.zimbra@xxxxxxxxxx> <CANbxzdVqbstVAue-GKW5moDkkKJKeg5pvtRdg1eHNET_7dHxeQ@xxxxxxxxxxxxxx> <559466FE.8090107@xxxxxxxxxxxxxxxx> <CANbxzdXqUj3i-MR2xF_NrTkYV11MMLBCX0B-+Btt45JQa77NQA@xxxxxxxxxxxxxx> <CANbxzdUn0Q8BkJUm-KAuTGxQAhQTz0CmSLdXEHKLT8UVKuBx4A@xxxxxxxxxxxxxx> <559AF629.5090609@xxxxxxxxxxxxxxxx> <CANbxzdWWozajgdEWpzX-MbndB=4EeLM-8p3QZRytJHhw+rrakQ@xxxxxxxxxxxxxx> <CANbxzdUnXsG3dJrSWnsET3mxAbxuYGP9XpG9+isXtBqH_LwTeQ@xxxxxxxxxxxxxx> <559C4A31.2030106@xxxxxxxxxx> <CANbxzdUYTi9w9s59Y=7CZ-W7OEc-D9XTZgavf9wysLpCvg1dkw@xxxxxxxxxxxxxx>
From what I can tell, the information in that tv_sec and tv_usec only contain the information for the month, day, and year. For the time I simply get midnight, or 12:00AM. Is that correct, or am I missing something? For example, when converting the timestamps for metrics gathered yesterday 07/07/2015, I get the following results for the timestamp:

  Â07/07/2015 00:00:00 for tv_sec
  Â01/07/1970 00:00:00 for tv_usec

The code I used to extract that is:

  Âdatetime.date.fromtimestamp(result.contents.timestamp.tv_usec).strftime("%m/%d/%Y %H:%M:%S")

Thanks,
Rohan

On Wed, Jul 8, 2015 at 9:43 AM Rohan Arora <rarora2012@xxxxxxxxx> wrote:
Whoops, sorry, I didn't realize that it was just a generic timestamp like that, I don't have much experience with time libraries honestly. Thanks for the help!

Best,
Rohan

On Tue, Jul 7, 2015 at 5:52 PM David Smith <dsmith@xxxxxxxxxx> wrote:
On 07/07/2015 09:47 AM, Rohan Arora wrote:
> I am able to get the tv_sec and tv_usec properties from the result using
> "result.contents.timestamp.tv_sec", but I don't know how to convert that
> back into an actual timestamp with format, say, "MM/dd/yyy HH:mm:ss". Is
> there a way to do this?

That's a generic python question, not really pcp related.

Basically, use datetime.fromtimestamp() to convert the tv_sec/tv_usec
values to a python datetime object, then use the strftime() function to
format it however you want.

<https://stackoverflow.com/questions/15649942/python-convert-epoch-time-with-nanoseconds-to-human-readable>
<https://stackoverflow.com/questions/10611328/format-nanoseconds-in-python>

--
David Smith
dsmith@xxxxxxxxxx
Red Hat
http://www.redhat.com
256.217.0141 (direct)
256.837.0057 (fax)
<Prev in Thread] Current Thread [Next in Thread>