10637.3.15
by Guilherme Salgado
update the shebang lines of a few scripts that still had python2.5 hard-coded |
1 |
#!/usr/bin/python -S
|
7675.686.4
by Stuart Bishop
Add script to populate DatabaseTableStats |
2 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
3 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
4 |
||
7675.686.10
by Stuart Bishop
Tidy and database table comments |
5 |
"""Populate the DatabaseTableStats and DatabaseCpuStats tables."""
|
7675.686.4
by Stuart Bishop
Add script to populate DatabaseTableStats |
6 |
|
7 |
__metaclass__ = type |
|
8 |
||
9 |
import _pythonpath |
|
10 |
||
11 |
from zope.component import getUtility |
|
12 |
||
14565.2.15
by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts. |
13 |
from lp.services.scripts import db_options |
14612.2.8
by William Grant
cronscripts |
14 |
from lp.services.scripts.base import LaunchpadCronScript |
14600.2.2
by Curtis Hovey
Moved webapp to lp.services. |
15 |
from lp.services.webapp.interfaces import ( |
14612.2.8
by William Grant
cronscripts |
16 |
IStoreSelector, |
17 |
MAIN_STORE, |
|
18 |
MASTER_FLAVOR, |
|
19 |
)
|
|
7675.686.4
by Stuart Bishop
Add script to populate DatabaseTableStats |
20 |
|
7675.686.10
by Stuart Bishop
Tidy and database table comments |
21 |
|
7675.686.8
by Stuart Bishop
Add database user cpu utilization stats too |
22 |
class UpdateDatabaseStats(LaunchpadCronScript): |
7675.686.10
by Stuart Bishop
Tidy and database table comments |
23 |
"""Populate the DatabaseTableStats and DatabaseCpuStats tables."""
|
7675.686.4
by Stuart Bishop
Add script to populate DatabaseTableStats |
24 |
|
25 |
def main(self): |
|
26 |
"Run UpdateDatabaseTableStats."""
|
|
27 |
store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR) |
|
7675.686.8
by Stuart Bishop
Add database user cpu utilization stats too |
28 |
|
29 |
# The logic is in a stored procedure because we want to run
|
|
30 |
# ps(1) on the database server rather than the host this script
|
|
31 |
# is running on.
|
|
32 |
self.logger.debug("Invoking update_database_stats()") |
|
33 |
store.execute("SELECT update_database_stats()", noresult=True) |
|
34 |
||
35 |
self.logger.debug("Committing") |
|
7675.686.4
by Stuart Bishop
Add script to populate DatabaseTableStats |
36 |
store.commit() |
37 |
||
38 |
def add_my_options(self): |
|
39 |
"""Add standard database command line options."""
|
|
40 |
db_options(self.parser) |
|
41 |
||
42 |
if __name__ == '__main__': |
|
7675.686.8
by Stuart Bishop
Add database user cpu utilization stats too |
43 |
script = UpdateDatabaseStats( |
44 |
'update-database-stats', dbuser='database_stats_update') |
|
7675.686.4
by Stuart Bishop
Add script to populate DatabaseTableStats |
45 |
script.lock_and_run() |
46 |