Merge lp:~stub/launchpad/db-stats into lp:launchpad/db-devel

Proposed by Stuart Bishop
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 9436
Proposed branch: lp:~stub/launchpad/db-stats
Merge into: lp:launchpad/db-devel
Diff against target: 67 lines (+18/-8)
1 file modified
utilities/report-database-stats.py (+18/-8)
To merge this branch: bzr merge lp:~stub/launchpad/db-stats
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+27026@code.launchpad.net

Description of the change

Tweaks to the db-stats report, fixing the bogus CPU report (Bug #590684), adding a few comments and output formatting niceness. Working fine against production, per https://pastebin.canonical.com/33123/

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'utilities/report-database-stats.py'
--- utilities/report-database-stats.py 2010-05-20 10:34:29 +0000
+++ utilities/report-database-stats.py 2010-06-08 09:20:45 +0000
@@ -72,12 +72,22 @@
7272
7373
74def get_cpu_stats(cur, options):74def get_cpu_stats(cur, options):
75 # This query calculates the averate cpu utilization from the
76 # samples. It assumes samples are taken at regular intervals over
77 # the period.
75 query = """78 query = """
76 SELECT avg(cpu), username FROM DatabaseCpuStats79 SELECT (
80 CAST(SUM(cpu) AS float) / (
81 SELECT COUNT(DISTINCT date_created) FROM DatabaseCpuStats
82 WHERE
83 date_created >= (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
84 - CAST (%s AS interval))
85 ) AS avg_cpu, username
86 FROM DatabaseCpuStats
77 WHERE date_created >= (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'87 WHERE date_created >= (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
78 - CAST(%s AS interval))88 - CAST(%s AS interval))
79 GROUP BY username89 GROUP BY username
80 """ % sqlvalues(options.since_interval)90 """ % sqlvalues(options.since_interval, options.since_interval)
8191
82 cur.execute(query)92 cur.execute(query)
8393
@@ -107,7 +117,7 @@
107 tables = get_table_stats(cur, options)117 tables = get_table_stats(cur, options)
108 arbitrary_table = list(tables)[0]118 arbitrary_table = list(tables)[0]
109 interval = arbitrary_table.date_end - arbitrary_table.date_start119 interval = arbitrary_table.date_end - arbitrary_table.date_start
110 per_minute = interval.days * 24 * 60 + interval.seconds / 60.0120 per_second = float(interval.days * 24 * 60 * 60 + interval.seconds)
111121
112 print "== Most Read Tables =="122 print "== Most Read Tables =="
113 print123 print
@@ -119,8 +129,8 @@
119 most_read_tables = sorted(129 most_read_tables = sorted(
120 tables, key=attrgetter(*tables_sort), reverse=True)130 tables, key=attrgetter(*tables_sort), reverse=True)
121 for table in most_read_tables[:options.limit]:131 for table in most_read_tables[:options.limit]:
122 print "%40s || %10.2f tuples/min" % (132 print "%40s || %10.2f tuples/sec" % (
123 table.relname, table.total_tup_read / per_minute)133 table.relname, table.total_tup_read / per_second)
124 print134 print
125135
126 print "== Most Written Tables =="136 print "== Most Written Tables =="
@@ -130,15 +140,15 @@
130 most_written_tables = sorted(140 most_written_tables = sorted(
131 tables, key=attrgetter(*tables_sort), reverse=True)141 tables, key=attrgetter(*tables_sort), reverse=True)
132 for table in most_written_tables[:options.limit]:142 for table in most_written_tables[:options.limit]:
133 print "%40s || %10.2f tuples/min" % (143 print "%40s || %10.2f tuples/sec" % (
134 table.relname, table.total_tup_written / per_minute)144 table.relname, table.total_tup_written / per_second)
135 print145 print
136146
137 user_cpu = get_cpu_stats(cur, options)147 user_cpu = get_cpu_stats(cur, options)
138 print "== Most Active Users =="148 print "== Most Active Users =="
139 print149 print
140 for cpu, username in sorted(user_cpu, reverse=True)[:options.limit]:150 for cpu, username in sorted(user_cpu, reverse=True)[:options.limit]:
141 print "%40s || %6.2f%% CPU" % (username, float(cpu) / 100)151 print "%40s || %10.2f%% CPU" % (username, float(cpu) / 10)
142152
143153
144if __name__ == '__main__':154if __name__ == '__main__':

Subscribers

People subscribed via source and target branches

to status/vote changes: