Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f16c95e

Browse files
committedAug 17, 2020
Merge branch 'dev'
2 parents 55ae1e0 + 6ea90f6 commit f16c95e

File tree

14 files changed

+1756
-1501
lines changed

14 files changed

+1756
-1501
lines changed
 

‎mamonsu/lib/zbx_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class ZbxTemplate(object):
88
plg_type = 'all'
9-
mainTemplate = u"""<?xml version="1.0" encoding="UTF-8"?>
9+
mainTemplate = """<?xml version="1.0" encoding="UTF-8"?>
1010
<zabbix_export>
1111
<version>2.0</version>
1212
<groups>

‎mamonsu/plugins/pgsql/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
__all__ += ['checkpoint', 'oldest', 'pg_locks']
55
__all__ += ['cfs']
66
__all__ += ['archive_command']
7-
__all__ += ['relations_size']
87
__all__ += ['prepared_transaction']
98

109
from . import *

‎mamonsu/plugins/pgsql/driver/pg8000/__init__.py

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
from .core import (
2-
Warning, DataError, DatabaseError, InterfaceError, ProgrammingError,
3-
Error, OperationalError, IntegrityError, InternalError, NotSupportedError,
4-
ArrayContentNotHomogenousError, ArrayDimensionsNotConsistentError,
5-
ArrayContentNotSupportedError, Connection, Cursor, Binary, Date,
6-
DateFromTicks, Time, TimeFromTicks, Timestamp, TimestampFromTicks, BINARY,
7-
Interval, PGEnum, PGJson, PGJsonb, PGTsvector, PGText, PGVarchar)
1+
from .converters import (
2+
BIGINTEGER, BINARY, BOOLEAN, BOOLEAN_ARRAY, BYTES, Binary, CHAR,
3+
CHAR_ARRAY, DATE, DATETIME, DECIMAL, DECIMAL_ARRAY, Date, DateFromTicks,
4+
FLOAT, FLOAT_ARRAY, INET, INT2VECTOR, INTEGER, INTEGER_ARRAY, INTERVAL,
5+
JSON, JSONB, MACADDR, NAME, NAME_ARRAY, NULLTYPE, NUMBER, OID, PGEnum,
6+
PGInterval, PGJson, PGJsonb, PGText, PGTsvector, PGVarchar, ROWID, STRING,
7+
TEXT, TEXT_ARRAY, TIME, TIMEDELTA, TIMESTAMP, TIMESTAMPTZ, Time,
8+
TimeFromTicks, Timestamp, TimestampFromTicks, UNKNOWN, UUID_TYPE, VARCHAR,
9+
VARCHAR_ARRAY, XID)
10+
from .core import Connection, Cursor
11+
from .exceptions import (
12+
DataError, DatabaseError, Error, IntegrityError, InterfaceError,
13+
InternalError, NotSupportedError, OperationalError, ProgrammingError,
14+
Warning)
15+
816
from ._version import get_versions
917
__version__ = get_versions()['version']
1018
del get_versions
@@ -43,16 +51,13 @@
4351
def connect(
4452
user, host='localhost', database=None, port=5432, password=None,
4553
source_address=None, unix_sock=None, ssl_context=None, timeout=None,
46-
max_prepared_statements=1000, tcp_keepalive=True,
47-
application_name=None, replication=None):
54+
tcp_keepalive=True, application_name=None, replication=None):
4855

4956
return Connection(
5057
user, host=host, database=database, port=port, password=password,
5158
source_address=source_address, unix_sock=unix_sock,
52-
ssl_context=ssl_context, timeout=timeout,
53-
max_prepared_statements=max_prepared_statements,
54-
tcp_keepalive=tcp_keepalive, application_name=application_name,
55-
replication=replication)
59+
ssl_context=ssl_context, timeout=timeout, tcp_keepalive=tcp_keepalive,
60+
application_name=application_name, replication=replication)
5661

5762

5863
apilevel = "2.0"
@@ -74,34 +79,16 @@ def connect(
7479

7580
paramstyle = 'format'
7681

77-
# I have no idea what this would be used for by a client app. Should it be
78-
# TEXT, VARCHAR, CHAR? It will only compare against row_description's
79-
# type_code if it is this one type. It is the varchar type oid for now, this
80-
# appears to match expectations in the DB API 2.0 compliance test suite.
81-
82-
STRING = 1043
83-
"""String type oid."""
84-
85-
86-
NUMBER = 1700
87-
"""Numeric type oid"""
88-
89-
DATETIME = 1114
90-
"""Timestamp type oid"""
91-
92-
ROWID = 26
93-
"""ROWID type oid"""
9482

9583
__all__ = [
9684
Warning, DataError, DatabaseError, connect, InterfaceError,
9785
ProgrammingError, Error, OperationalError, IntegrityError, InternalError,
98-
NotSupportedError, ArrayContentNotHomogenousError,
99-
ArrayDimensionsNotConsistentError, ArrayContentNotSupportedError,
100-
Connection, Cursor, Binary, Date, DateFromTicks, Time, TimeFromTicks,
101-
Timestamp, TimestampFromTicks, BINARY, Interval, PGEnum, PGJson, PGJsonb,
102-
PGTsvector, PGText, PGVarchar]
103-
104-
"""Version string for pg8000.
105-
106-
.. versionadded:: 1.9.11
107-
"""
86+
NotSupportedError, Connection, Cursor, Binary, Date, DateFromTicks, Time,
87+
TimeFromTicks, Timestamp, TimestampFromTicks, BINARY, PGInterval, PGEnum,
88+
PGJson, PGJsonb, PGTsvector, PGText, PGVarchar, STRING, NUMBER, DATETIME,
89+
TIME, BOOLEAN, INTEGER, BIGINTEGER, INTERVAL, JSON, JSONB, UNKNOWN,
90+
NULLTYPE, ROWID, BOOLEAN_ARRAY, BYTES, CHAR, CHAR_ARRAY, DATE, DECIMAL,
91+
DECIMAL_ARRAY, FLOAT, FLOAT_ARRAY, INET, INT2VECTOR, INTEGER_ARRAY,
92+
MACADDR, NAME, NAME_ARRAY, OID, TEXT, TEXT_ARRAY, TIMEDELTA, TIMESTAMP,
93+
TIMESTAMPTZ, UUID_TYPE, VARCHAR, VARCHAR_ARRAY, XID
94+
]

‎mamonsu/plugins/pgsql/driver/pg8000/_version.py

Lines changed: 453 additions & 14 deletions
Large diffs are not rendered by default.

‎mamonsu/plugins/pgsql/driver/pg8000/converters.py

Lines changed: 744 additions & 0 deletions
Large diffs are not rendered by default.

‎mamonsu/plugins/pgsql/driver/pg8000/core.py

Lines changed: 398 additions & 1204 deletions
Large diffs are not rendered by default.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
class Warning(Exception):
2+
"""Generic exception raised for important database warnings like data
3+
truncations. This exception is not currently used by pg8000.
4+
5+
This exception is part of the `DBAPI 2.0 specification
6+
<http://www.python.org/dev/peps/pep-0249/>`_.
7+
"""
8+
pass
9+
10+
11+
class Error(Exception):
12+
"""Generic exception that is the base exception of all other error
13+
exceptions.
14+
15+
This exception is part of the `DBAPI 2.0 specification
16+
<http://www.python.org/dev/peps/pep-0249/>`_.
17+
"""
18+
pass
19+
20+
21+
class InterfaceError(Error):
22+
"""Generic exception raised for errors that are related to the database
23+
interface rather than the database itself. For example, if the interface
24+
attempts to use an SSL connection but the server refuses, an InterfaceError
25+
will be raised.
26+
27+
This exception is part of the `DBAPI 2.0 specification
28+
<http://www.python.org/dev/peps/pep-0249/>`_.
29+
"""
30+
pass
31+
32+
33+
class DatabaseError(Error):
34+
"""Generic exception raised for errors that are related to the database.
35+
This exception is currently never raised by pg8000.
36+
37+
This exception is part of the `DBAPI 2.0 specification
38+
<http://www.python.org/dev/peps/pep-0249/>`_.
39+
"""
40+
pass
41+
42+
43+
class DataError(DatabaseError):
44+
"""Generic exception raised for errors that are due to problems with the
45+
processed data. This exception is not currently raised by pg8000.
46+
47+
This exception is part of the `DBAPI 2.0 specification
48+
<http://www.python.org/dev/peps/pep-0249/>`_.
49+
"""
50+
pass
51+
52+
53+
class OperationalError(DatabaseError):
54+
"""
55+
Generic exception raised for errors that are related to the database's
56+
operation and not necessarily under the control of the programmer. This
57+
exception is currently never raised by pg8000.
58+
59+
This exception is part of the `DBAPI 2.0 specification
60+
<http://www.python.org/dev/peps/pep-0249/>`_.
61+
"""
62+
pass
63+
64+
65+
class IntegrityError(DatabaseError):
66+
"""
67+
Generic exception raised when the relational integrity of the database is
68+
affected. This exception is not currently raised by pg8000.
69+
70+
This exception is part of the `DBAPI 2.0 specification
71+
<http://www.python.org/dev/peps/pep-0249/>`_.
72+
"""
73+
pass
74+
75+
76+
class InternalError(DatabaseError):
77+
"""Generic exception raised when the database encounters an internal error.
78+
This is currently only raised when unexpected state occurs in the pg8000
79+
interface itself, and is typically the result of a interface bug.
80+
81+
This exception is part of the `DBAPI 2.0 specification
82+
<http://www.python.org/dev/peps/pep-0249/>`_.
83+
"""
84+
pass
85+
86+
87+
class ProgrammingError(DatabaseError):
88+
"""Generic exception raised for programming errors. For example, this
89+
exception is raised if more parameter fields are in a query string than
90+
there are available parameters.
91+
92+
This exception is part of the `DBAPI 2.0 specification
93+
<http://www.python.org/dev/peps/pep-0249/>`_.
94+
"""
95+
pass
96+
97+
98+
class NotSupportedError(DatabaseError):
99+
"""Generic exception raised in case a method or database API was used which
100+
is not supported by the database.
101+
102+
This exception is part of the `DBAPI 2.0 specification
103+
<http://www.python.org/dev/peps/pep-0249/>`_.
104+
"""
105+
pass
106+
107+
108+
class ArrayContentNotSupportedError(NotSupportedError):
109+
"""
110+
Raised when attempting to transmit an array where the base type is not
111+
supported for binary data transfer by the interface.
112+
"""
113+
pass

‎mamonsu/plugins/pgsql/prepared_transaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PreparedTransaction(Plugin):
1616
key_prepared = {
1717
'state': 'oldest_prepared',
1818
'key': 'pgsql.prepared.oldest',
19-
'name': 'PostgreSQL: oldest prepared transaction running time in sec',
19+
'name': 'PostgreSQL: oldest prepared transaction time in sec',
2020
'color': '0000BB',
2121
'yaxisside': 1,
2222
}
@@ -71,7 +71,7 @@ def graphs(self, template):
7171

7272
def triggers(self, template):
7373
result = template.trigger({
74-
'name': 'PostgreSQL prepared transaction running is too old on {HOSTNAME}',
74+
'name': 'PostgreSQL prepared transaction is too old on {HOSTNAME}',
7575
'expression': '{#TEMPLATE:' + self.key_prepared['key'] +
7676
'.last()}&gt;' + self.plugin_config('max_prepared_transaction_time')
7777
})

‎mamonsu/plugins/pgsql/relations_size.py

Lines changed: 0 additions & 120 deletions
This file was deleted.

‎mamonsu/plugins/system/linux/pg_probackup.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def run(self, zbx):
5656
dir_size = self.dir_size(_dir)
5757
if self.os_walk_error:
5858
self.log.error(
59-
"Error in count size backup catalog: {backup_catalog}. Error: {error}".format(
59+
"Error in count size pg_probackup dir: {backup_catalog}. Error: {error}".format(
6060
backup_catalog=_dir, error=str(self.os_walk_error)))
6161
else:
6262
zbx.send(self.key_dir_size.format('[' + _dir + ']'), dir_size)
@@ -78,17 +78,20 @@ def run(self, zbx):
7878
except Exception as e:
7979
self.log.error('Error in convert data: {stdout} \n {e}'.format(stdout=stdout, e=e))
8080
continue
81-
81+
no_error= True
8282
for instance in result:
8383
for backup in instance.get('backups', []):
8484
status = backup['status']
8585
if status in ['ERROR', 'CORRUPT', 'ORPHAN']:
86-
error = 'Backup with id: {backup_id} in instance: {instance_name} in backup catalog: ' \
86+
error = 'Backup with id: {backup_id} in instance: {instance_name} in pg_probackup dir: ' \
8787
'{backup_catalog} has status: {status}.'.format(backup_id=backup['id'],
8888
instance_name=instance['instance'],
8989
status=status, backup_catalog=_dir)
9090
self.log.info(error)
91+
no_error = False
9192
zbx.send(self.key_dir_error.format('[' + _dir + ']'), error)
93+
if no_error:
94+
zbx.send(self.key_dir_error.format('[' + _dir + ']'), 'ok')
9295

9396
zbx.send(self.key_main.format('[]'), zbx.json({'data': dirs}))
9497
del dirs
@@ -114,12 +117,12 @@ def discovery_rules(self, template):
114117
]
115118
items = [
116119
{'key': self.right_type(self.key_dir_size, var_discovery="{#BACKUPDIR},"),
117-
'name': 'Pg_probackup catalog {#BACKUPDIR}: size',
120+
'name': 'Pg_probackup dir {#BACKUPDIR}: size',
118121
'units': Plugin.UNITS.bytes,
119122
'value_type': Plugin.VALUE_TYPE.numeric_unsigned,
120123
'delay': self.plugin_config('interval')},
121124
{'key': self.right_type(self.key_dir_error, var_discovery="{#BACKUPDIR},"),
122-
'name': 'Pg_probackup catalog {#BACKUPDIR}: error',
125+
'name': 'Pg_probackup dir {#BACKUPDIR}: error',
123126
'value_type': Plugin.VALUE_TYPE.text,
124127
'delay': self.plugin_config('interval')},
125128
]
@@ -133,8 +136,8 @@ def discovery_rules(self, template):
133136
},
134137
]
135138
triggers = [{
136-
'name': 'Error in backup dir '
139+
'name': 'Error in pg_probackup dir '
137140
'{#BACKUPDIR} (hostname={HOSTNAME} value={ITEM.LASTVALUE})',
138-
'expression': '{#TEMPLATE:pg_probackup.dir.error[{#BACKUPDIR}].strlen()}&gt;1'}
141+
'expression': '{#TEMPLATE:pg_probackup.dir.error[{#BACKUPDIR}].str(ok)}&lt;&gt;1'}
139142
]
140143
return template.discovery_rule(rule=rule, conditions=conditions, items=items, graphs=graphs, triggers=triggers)

‎mamonsu/tools/agent/agent.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
22
from mamonsu.lib.plugin import Plugin
3-
43
from mamonsu.lib.const import API
54

65
from urllib.parse import urlparse as parse
76
from urllib.parse import parse_qs
87
from http.server import BaseHTTPRequestHandler, HTTPServer
8+
import logging
99

1010

1111
class AgentApi(Plugin):
@@ -36,8 +36,13 @@ class AgentApiHandler(BaseHTTPRequestHandler):
3636

3737
def __init__(self, config, *args):
3838
self.sender = config.sender
39+
self.log = logging.getLogger('AGENTAPI')
3940
BaseHTTPRequestHandler.__init__(self, *args)
4041

42+
# rewrite log_message method of http lib to avoid getting log messages in console
43+
def log_message(self, format, *args):
44+
self.log.info(format, *args)
45+
4146
def _set_header(self):
4247
self.send_response(200)
4348
self.send_header("Content-type", "text/html")

‎mamonsu/tools/agent/start.py.bak

Lines changed: 0 additions & 92 deletions
This file was deleted.

‎packaging/conf/example.conf

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,6 @@ interval = 2
167167
[agentapi]
168168
interval = 60
169169

170-
# Get size of relations defined in this section
171-
# Relations - comma separated list of objects - tables and endexes (schema.relation) to calculate relations size.
172-
# Example:
173-
# relations=pg_catalog.pg_class,pg_catalog.pg_user
174-
# If the relation is blocked by some process such as vacuum full or create index, the result will be -1
175-
# by default this plugin disabled. To enable this plugin - set bellow "enabled = False" and define a list of relations.
176-
[relationssize]
177-
enabled = False
178-
relations=pg_catalog.pg_class,pg_catalog.pg_user
179-
interval = 500
180-
181170
# Get age (in seconds) of the oldest running prepared transaction and number of all prepared transactions for two-phase commit.
182171
# https://www.postgresql.org/docs/current/sql-prepare-transaction.html
183172
# https://www.postgresql.org/docs/12/view-pg-prepared-xacts.html
@@ -188,10 +177,10 @@ max_prepared_transaction_time = 60
188177
interval = 60
189178

190179
# Get size of backup catalogs stroring all WAL and backup files using pg_probackup
191-
# S(https://github.com/postgrespro/pg_probackup)
180+
# (https://github.com/postgrespro/pg_probackup)
192181
# Trigger fires if some backup has bad status e.g. (ERROR,CORRUPT,ORPHAN).
193182
[pgprobackup]
194-
enabled = false
183+
enabled = False
195184
interval = 300
196185
backup_dirs = /backup_dir1,/backup_dir2
197186
pg_probackup_path = /usr/bin/pg_probackup-11

‎tests/check.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,6 @@ directory = /tmp
169169
file = /var/log/mamonsu/agent.log
170170
level = DEBUG
171171
172-
[relationssize]
173-
enabled = True
174-
relations=pg_catalog.pg_class,pg_catalog.pg_user
175-
interval = 60
176-
177172
[preparedtransaction]
178173
max_prepared_transaction_time = 60
179174
interval = 60
@@ -194,7 +189,6 @@ mamonsu agent -c /etc/mamonsu/agent.conf metric-list | grep system
194189
## metric log
195190
grep utilization /tmp/localhost.log || exit 7
196191
grep 'pgsql\.uptime' /tmp/localhost.log || exit 7
197-
grep 'pgsql\.relation\.size' /tmp/localhost.log || exit 7
198192
grep 'pgsql\.prepared\.count' /tmp/localhost.log || exit 7
199193
grep 'pgsql\.prepared\.oldest' /tmp/localhost.log || exit 7
200194

0 commit comments

Comments
 (0)
Please sign in to comment.