~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to utilities/report-database-stats.py

  • Committer: Julian Edwards
  • Date: 2011-07-28 20:46:18 UTC
  • mfrom: (13553 devel)
  • mto: This revision was merged to the branch mainline in revision 13555.
  • Revision ID: julian.edwards@canonical.com-20110728204618-tivj2wx2oa9s32bx
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -S
2
 
# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
 
2
# Copyright 2010 Canonical Ltd.  This software is licensed under the
3
3
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
 
5
5
"""Generate the database statistics report."""
6
6
 
7
7
__metaclass__ = type
8
8
 
 
9
import _pythonpath
 
10
 
9
11
from datetime import datetime
10
12
from operator import attrgetter
11
13
from textwrap import (
13
15
    fill,
14
16
    )
15
17
 
16
 
import _pythonpath
17
 
 
18
 
from canonical.database.sqlbase import (
19
 
    connect,
20
 
    sqlvalues,
21
 
    )
22
 
from lp.services.scripts import db_options
 
18
from canonical.database.sqlbase import connect, sqlvalues
 
19
from canonical.launchpad.scripts import db_options
23
20
from lp.scripts.helpers import LPOptionParser
24
21
from lp.services.database.namedrow import named_fetchall
25
22
 
232
229
    parser.add_option(
233
230
        "-i", "--interval", dest="interval", type=str,
234
231
        default=None, metavar="INTERVAL",
235
 
        help=(
 
232
        help=
236
233
            "Use statistics collected over the last INTERVAL period. "
237
234
            "INTERVAL is a string parsable by PostgreSQL "
238
 
            "such as '5 minutes'."))
 
235
            "such as '5 minutes'.")
239
236
    parser.add_option(
240
237
        "-n", "--limit", dest="limit", type=int,
241
238
        default=15, metavar="NUM",
255
252
        parser.error(
256
253
            "Only two of --from, --until and --interval may be specified.")
257
254
 
258
 
    con = connect()
 
255
    con = connect(options.dbuser)
259
256
    cur = con.cursor()
260
257
 
261
258
    tables = list(get_table_stats(cur, options))