Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 860352 Details for
Bug 1062467
Problems in python-pcp time API wrapper implementation
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
Trivial python implementation of uptime(1) using PCP
uptime.py (text/x-python), 3.03 KB, created by
Nathan Scott
on 2014-02-07 00:55:53 UTC
(
hide
)
Description:
Trivial python implementation of uptime(1) using PCP
Filename:
MIME Type:
Creator:
Nathan Scott
Created:
2014-02-07 00:55:53 UTC
Size:
3.03 KB
patch
obsolete
>#!/usr/bin/python ># ># Copyright (C) 2014 Red Hat. ># ># This program is free software; you can redistribute it and/or modify it ># under the terms of the GNU General Public License as published by the ># Free Software Foundation; either version 2 of the License, or (at your ># option) any later version. ># ># This program is distributed in the hope that it will be useful, but ># WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ># or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ># for more details. ># > >""" Tell how long the system has been running > >uptime.py gives a one line display of the following information: > The current time; > How long the system has been running; > How many users are currently logged on; and > The system load averages for the past 1, 5, and 15 minutes. >""" > >from pcp import pmapi >from cpmapi import PM_TYPE_U32, PM_TYPE_FLOAT > >def print_timestamp(stamp): > """ Report the sample time (struct tm) in HH:MM:SS form """ > print " %02d:%02d:%02d" % (stamp.tm_hour, stamp.tm_min, stamp.tm_sec), > >def print_uptime(seconds): > """ Report on system up-time in days, hours and minutes """ > days = seconds / (60 * 60 * 24) > minutes = seconds / 60 > hours = minutes / 60 > hours = hours % 24 > minutes = minutes % 60 > print "up", > if days > 1: > print "%d days," % days, > elif days != 0: > print "1 day,", > if hours != 0: > print '%2d:%02d,' % (hours, minutes), > else: > print '%d min,' % minutes, > >def print_users(nusers): > """ Report the number of logged in users at sample time """ > if nusers == 1: > print '1 user, ' > else: > print '%2d users, ' % nusers, > >def print_load(one, five, fifteen): > """ Report 1, 5, 15 minute load averages at sample time """ > print 'load average: %.2f, %.2f, %.2f' % (one, five, fifteen), > >def uptime(): > """ Create a PMAPI context (could be either host or archive), > fetch and report a fixed set of values related to uptime. > """ > context = pmapi.pmContext() > metrics = ('kernel.all.uptime', 'kernel.all.nusers', 'kernel.all.load') > pmids = context.pmLookupName(metrics) > descs = context.pmLookupDescs(pmids) > result = context.pmFetch(pmids) > > sample_time = result.contents.timestamp.tv_sec > time_struct = context.pmLocaltime(sample_time) > print_timestamp(time_struct) > > atom = context.pmExtractValue( > result.contents.get_valfmt(0), > result.contents.get_vlist(0, 0), > descs[0].contents.type, PM_TYPE_U32) > print_uptime(atom.ul) > > atom = context.pmExtractValue( > result.contents.get_valfmt(1), > result.contents.get_vlist(1, 0), > descs[1].contents.type, PM_TYPE_U32) > print_users(atom.ul) > > averages = [1, 5, 15] > for instance in xrange(3): > averages[instance] = context.pmExtractValue( > result.contents.get_valfmt(2), > result.contents.get_vlist(2, instance), > descs[2].contents.type, PM_TYPE_FLOAT) > print_load(averages[0].f, averages[1].f, averages[2].f) > > context.pmFreeResult(result) > >if __name__ == '__main__': > uptime()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1062467
: 860352