Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 802e811

Browse files
committed
Use Python 3
1 parent 3f52668 commit 802e811

File tree

9 files changed

+18
-18
lines changed

9 files changed

+18
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ a pull-request with missing prerequisites, if you test and confirm
2828
postgresql-metrics to work on other versions of the mentioned
2929
technologies.
3030

31-
* Python 2.7
31+
* Python 3.5 or later
3232
* PostgreSQL 9.3 or later
3333
* Debian based distribution with systemd (packaging requirement only)
3434

debian/control

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ Section: non-free/net
33
Priority: extra
44
Maintainer: Hannu Varjoranta <hannu.varjoranta@spotify.com>
55
Build-Depends:
6-
python (>= 2.7),
7-
libpq-dev (<<9.7),
6+
python3 (>= 3.5),
7+
libpq-dev,
88
debhelper (>= 9),
99
dh-virtualenv (>= 1.0),
1010
Standards-Version: 3.9.5
11-
X-Python-Version: >= 2.7
11+
X-Python-Version: >= 3.5
1212

1313
Package: postgresql-metrics
1414
Architecture: any
15-
Depends: ${misc:Depends}
15+
Pre-Depends: dpkg (>= 1.16.1), python3 (>= 3.5), ${misc:Pre-Depends}
1616
Description: Simple service to provide metrics for your PostgreSQL database

debian/postgresql-metrics.triggers

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
interest-noawait /usr/bin/python3

debian/rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/make -f
22

33
%:
4-
dh $@ --with python-virtualenv
4+
dh $@ --with python-virtualenv --python python3 --preinstall=no-manylinux1

postgresql_metrics/common.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"""
1717

1818
import os
19-
import types
2019

2120
import logbook
2221
import yaml
@@ -27,7 +26,7 @@ def get_logger(logger_name="postgresql-metrics"):
2726

2827

2928
def figure_out_log_level(given_level):
30-
if isinstance(given_level, types.StringTypes):
29+
if isinstance(given_level, str):
3130
return logbook.lookup_level(given_level.strip().upper())
3231
else:
3332
return given_level
@@ -83,7 +82,7 @@ def merge_configs(to_be_merged, default):
8382
['get_stats_seconds_since_last_vacuum_per_table', 60]]
8483
"""
8584
if isinstance(to_be_merged, dict) and isinstance(default, dict):
86-
for k, v in default.iteritems():
85+
for k, v in default.items():
8786
if k not in to_be_merged:
8887
to_be_merged[k] = v
8988
else:
@@ -113,7 +112,7 @@ def find_and_parse_config(config_path):
113112
for config_dir in (default_root, config_root):
114113
current_path = os.path.join(config_dir, config_filename)
115114
if os.path.isfile(current_path):
116-
with file(current_path, 'r') as f:
115+
with open(current_path, 'r') as f:
117116
read_config_dict = yaml.load(f)
118117
config_dict = merge_configs(read_config_dict, config_dict)
119118
return config_dict

postgresql_metrics/metrics_gatherer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_stats_heap_hit_statistics(db_connection):
106106
def get_stats_lock_statistics(db_connection):
107107
locks_by_type, [total_locks_waiting, total_locks_granted] = get_lock_statistics(db_connection)
108108
metrics = []
109-
for lock_type, [locks_waiting, locks_granted] in locks_by_type.iteritems():
109+
for lock_type, [locks_waiting, locks_granted] in locks_by_type.items():
110110
metrics.append(metric_locks_granted(lock_type, locks_granted))
111111
metrics.append(metric_locks_waiting(lock_type, locks_waiting))
112112
metrics.append(metric_locks_granted("total", total_locks_granted))

postgresql_metrics/metrics_logic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import socket
2828
import time
2929

30-
import metrics_gatherer
30+
from postgresql_metrics import metrics_gatherer
3131
from postgresql_metrics.postgres_queries import (
3232
get_db_name_from_connection,
3333
get_db_connection,
@@ -62,7 +62,7 @@ def push_to_ffwd(metric_dicts, ffwd_addr, data_formatter=json.dumps):
6262
for metric in metric_dicts:
6363
data = data_formatter(metric)
6464
LOG.debug('send UDP packet to {} with data:\n{}', ffwd_addr, data)
65-
s.sendto(data, ffwd_addr)
65+
s.sendto(bytes(data, 'UTF-8'), ffwd_addr)
6666
finally:
6767
s.close()
6868

@@ -283,10 +283,10 @@ def main():
283283
init_logging_stderr(log_level)
284284
db_connections = get_db_connections_with_conf(conf)
285285
get_all_metrics_now(db_connections, conf)
286-
print "# sleep 5 s to get diffs on derivative metrics"
286+
print("# sleep 5 s to get diffs on derivative metrics")
287287
time.sleep(5.0)
288288
for metric in get_all_metrics_now(db_connections, conf):
289-
print metric
289+
print(metric)
290290

291291
elif args.command == 'long-running-ffwd':
292292
if conf['log']['log_to_stderr'] is True:

postgresql_metrics/prepare_db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737

3838

3939
def query_user_for_superuser_credentials():
40-
username = raw_input("Provide a Postgres role name with superuser privileges "
41-
"in the configured cluster: ")
40+
username = input("Provide a Postgres role name with superuser privileges "
41+
"in the configured cluster: ")
4242
password = getpass.getpass("Give the password: ")
4343
return username, password
4444

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
psycopg2>=2.6.1
1+
psycopg2-binary>=2.6.1
22
logbook>=0.10.1
33
pip>=1.5.4
44
pyyaml>=3.11

0 commit comments

Comments
 (0)