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
1=== modified file 'utilities/report-database-stats.py'
2--- utilities/report-database-stats.py 2010-05-20 10:34:29 +0000
3+++ utilities/report-database-stats.py 2010-06-08 09:20:45 +0000
4@@ -72,12 +72,22 @@
5
6
7 def get_cpu_stats(cur, options):
8+ # This query calculates the averate cpu utilization from the
9+ # samples. It assumes samples are taken at regular intervals over
10+ # the period.
11 query = """
12- SELECT avg(cpu), username FROM DatabaseCpuStats
13+ SELECT (
14+ CAST(SUM(cpu) AS float) / (
15+ SELECT COUNT(DISTINCT date_created) FROM DatabaseCpuStats
16+ WHERE
17+ date_created >= (CURRENT_TIMESTAMP AT TIME ZONE 'UTC')
18+ - CAST (%s AS interval))
19+ ) AS avg_cpu, username
20+ FROM DatabaseCpuStats
21 WHERE date_created >= (CURRENT_TIMESTAMP AT TIME ZONE 'UTC'
22 - CAST(%s AS interval))
23 GROUP BY username
24- """ % sqlvalues(options.since_interval)
25+ """ % sqlvalues(options.since_interval, options.since_interval)
26
27 cur.execute(query)
28
29@@ -107,7 +117,7 @@
30 tables = get_table_stats(cur, options)
31 arbitrary_table = list(tables)[0]
32 interval = arbitrary_table.date_end - arbitrary_table.date_start
33- per_minute = interval.days * 24 * 60 + interval.seconds / 60.0
34+ per_second = float(interval.days * 24 * 60 * 60 + interval.seconds)
35
36 print "== Most Read Tables =="
37 print
38@@ -119,8 +129,8 @@
39 most_read_tables = sorted(
40 tables, key=attrgetter(*tables_sort), reverse=True)
41 for table in most_read_tables[:options.limit]:
42- print "%40s || %10.2f tuples/min" % (
43- table.relname, table.total_tup_read / per_minute)
44+ print "%40s || %10.2f tuples/sec" % (
45+ table.relname, table.total_tup_read / per_second)
46 print
47
48 print "== Most Written Tables =="
49@@ -130,15 +140,15 @@
50 most_written_tables = sorted(
51 tables, key=attrgetter(*tables_sort), reverse=True)
52 for table in most_written_tables[:options.limit]:
53- print "%40s || %10.2f tuples/min" % (
54- table.relname, table.total_tup_written / per_minute)
55+ print "%40s || %10.2f tuples/sec" % (
56+ table.relname, table.total_tup_written / per_second)
57 print
58
59 user_cpu = get_cpu_stats(cur, options)
60 print "== Most Active Users =="
61 print
62 for cpu, username in sorted(user_cpu, reverse=True)[:options.limit]:
63- print "%40s || %6.2f%% CPU" % (username, float(cpu) / 100)
64+ print "%40s || %10.2f%% CPU" % (username, float(cpu) / 10)
65
66
67 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches

to status/vote changes: