Skip to content

Commit 4b497c0

Browse files
committed
Merge branch 'dev'
2 parents 0e0fa53 + 68ddb51 commit 4b497c0

16 files changed

+252
-183
lines changed

Diff for: github-actions-tests/sources/agent_3.5.0.conf

+83-95
Original file line numberDiff line numberDiff line change
@@ -78,112 +78,112 @@ format = [%(levelname)s] %(asctime)s - %(name)s - %(message)s
7878
# below listed all available parameters for each plugin to modify.
7979

8080
[health]
81-
max_memory_usage = 41943040
82-
interval = 15
81+
interval = 60
8382

84-
[bgwriter]
85-
interval = 15
83+
[archivecommand]
84+
interval = 60
8685

8786
# Besides standard autovacuum workers count, mamonsu also counts autovacuum utilization.
8887
# But this metric is instantaneous, so recommended to run this plugin frequently
8988
# to get a complete picture of autovacuum utilization.
9089
[autovacuum]
9190
interval = 30
9291

92+
[bgwriter]
93+
interval = 60
94+
95+
[cfs]
96+
force_enable = False
97+
interval = 60
98+
99+
[checkpoint]
100+
interval = 300
101+
93102
[connections]
94-
percent_connections_tr = 90
95-
interval = 15
103+
interval = 60
96104

97105
[databases]
98-
bloat_scale = 0.2
99-
min_rows = 50
100-
interval = 15
106+
interval = 300
101107

102108
[pghealth]
103-
uptime = 600
104-
cache = 80
105-
interval = 15
109+
interval = 60
106110

107111
[instance]
108-
interval = 15
112+
interval = 60
109113

110-
[xlog]
111-
lag_more_than_in_sec = 300
114+
# This plugin allows detects possible memory leaks while working with PostgreSQL using /proc/pid/status and /proc/pid/statm
115+
# We use RES and SHR difference to calculate approximate volume of private anonymous backend memory.
116+
# If it exceeds private_anon_mem_threshold then that pid will be added to a message. An example is presented below
117+
# statm - 'pid: {pid}, RES {RES} - SHR {SHR} more then {private_anon_mem_threshold}\n'
118+
# Since Linux 4.5 RssAnon, RssFile and RssShmem have been added.
119+
# They allows to distinguish types of memory such as private anonymous, file-backed, and shared anonymous memory.
120+
# We are interested in RssAnon. If its value exceeds private_anon_mem_threshold then that pid will also be added to a message.
121+
# By default this plugin disabled. To enable this plugin - set bellow "enabled = False"
122+
# #interval - (onitoring frequency in seconds. 60 seconds by default
123+
# private_anon_mem_threshold - memory volume threshold after which we need an investigation about memory leak. 1GB by default.
124+
# Possible values MB, GB, TB. For example 1GB
125+
[memoryleakdiagnostic]
126+
enabled = True
112127
interval = 15
128+
private_anon_mem_threshold = 1GB
113129

114-
[statements]
115-
interval = 15
130+
[oldest]
131+
interval = 60
116132

117133
[pgbuffercache]
118-
interval = 15
119-
120-
[waitsampling]
121-
interval = 15
122-
123-
[checkpoint]
124-
max_checkpoint_by_wal_in_hour = 12
125-
interval = 15
126-
127-
[oldest]
128-
max_xid_age = 18000000
129-
max_query_time = 18000
130-
interval = 15
134+
interval = 60
131135

132136
[pglocks]
133-
interval = 15
134-
135-
[cfs]
136-
force_enable = False
137-
interval = 15
137+
interval = 60
138138

139-
[archivecommand]
140-
max_count_files = 2
141-
interval = 15
139+
# Get age (in seconds) of the oldest running prepared transaction and number of all prepared transactions for two-phase commit.
140+
# https://www.postgresql.org/docs/current/sql-prepare-transaction.html
141+
# https://www.postgresql.org/docs/12/view-pg-prepared-xacts.html
142+
# max_prepared_transaction_time - age of prepared transaction in seconds.
143+
# If pgsql.prepared.oldest exceeds max_prepared_transaction_time the trigger fires.
144+
[preparedtransaction]
145+
interval = 60
142146

143-
[procstat]
147+
# Get size of relations defined in this section
148+
# Relations - comma separated list of objects - tables and endexes (database_name.schema.relation) used to calculate relations size.
149+
# Example:
150+
# relations=postgres.pg_catalog.pg_class,postgres.pg_catalog.pg_user
151+
# If the relation is blocked by some process such as vacuum full or create index, the result will be -1
152+
# by default this plugin disabled. To enable this plugin - set bellow "enabled = False" and define a list of relations.
153+
[relationssize]
154+
enabled = True
155+
relations=postgres.pg_catalog.pg_class,mamonsu_test_db.mamonsu.config
144156
interval = 15
145157

146-
[diskstats]
147-
interval = 15
158+
[replication]
159+
interval = 60
148160

149-
[disksizes]
150-
vfs_percent_free = 10
151-
vfs_inode_percent_free = 10
152-
interval = 15
161+
[statstatements]
162+
interval = 60
153163

154-
[memory]
155-
interval = 15
164+
[waitsampling]
165+
interval = 60
156166

157-
[systemuptime]
158-
up_time = 300
159-
interval = 15
167+
[wal]
168+
interval = 60
160169

161-
[openfiles]
162-
interval = 15
170+
[disksizes]
171+
interval = 60
163172

164-
[net]
165-
interval = 15
173+
[diskstats]
174+
interval = 60
166175

167176
[la]
168-
interval = 15
169-
170-
[zbxsender]
171-
interval = 10
177+
interval = 60
172178

173-
[logsender]
174-
interval = 2
179+
[memory]
180+
interval = 60
175181

176-
[agentapi]
177-
interval = 15
182+
[net]
183+
interval = 60
178184

179-
# Get age (in seconds) of the oldest running prepared transaction and number of all prepared transactions for two-phase commit.
180-
# https://www.postgresql.org/docs/current/sql-prepare-transaction.html
181-
# https://www.postgresql.org/docs/12/view-pg-prepared-xacts.html
182-
# max_prepared_transaction_time - age of prepared transaction in seconds.
183-
# If pgsql.prepared.oldest exceeds max_prepared_transaction_time the trigger fires.
184-
[preparedtransaction]
185-
max_prepared_transaction_time = 60
186-
interval = 15
185+
[openfiles]
186+
interval = 60
187187

188188
# Get size of backup catalogs stroring all WAL and backup files using pg_probackup
189189
# (https://github.com/postgrespro/pg_probackup)
@@ -194,29 +194,17 @@ interval = 300
194194
backup_dirs = /backup_dir1,/backup_dir2
195195
pg_probackup_path = /usr/bin/pg_probackup-11
196196

197-
# Get size of relations defined in this section
198-
# Relations - comma separated list of objects - tables and endexes (database_name.schema.relation) used to calculate relations size.
199-
# Example:
200-
# relations=postgres.pg_catalog.pg_class,postgres.pg_catalog.pg_user
201-
# If the relation is blocked by some process such as vacuum full or create index, the result will be -1
202-
# by default this plugin disabled. To enable this plugin - set bellow "enabled = False" and define a list of relations.
203-
[relationssize]
204-
enabled = True
205-
relations=postgres.pg_catalog.pg_class,mamonsu_test_db.mamonsu.config
206-
interval = 15
197+
[procstat]
198+
interval = 60
207199

208-
# This plugin allows detects possible memory leaks while working with PostgreSQL using /proc/pid/status and /proc/pid/statm
209-
# We use RES and SHR difference to calculate approximate volume of private anonymous backend memory.
210-
# If it exceeds private_anon_mem_threshold then that pid will be added to a message. An example is presented below
211-
# statm - 'pid: {pid}, RES {RES} - SHR {SHR} more then {private_anon_mem_threshold}\n'
212-
# Since Linux 4.5 RssAnon, RssFile and RssShmem have been added.
213-
# They allows to distinguish types of memory such as private anonymous, file-backed, and shared anonymous memory.
214-
# We are interested in RssAnon. If its value exceeds private_anon_mem_threshold then that pid will also be added to a message.
215-
# By default this plugin disabled. To enable this plugin - set bellow "enabled = False"
216-
# #interval - (onitoring frequency in seconds. 60 seconds by default
217-
# private_anon_mem_threshold - memory volume threshold after which we need an investigation about memory leak. 1GB by default.
218-
# Possible values MB, GB, TB. For example 1GB
219-
[memoryleakdiagnostic]
220-
enabled = True
221-
interval = 15
222-
private_anon_mem_threshold = 1GB
200+
[systemuptime]
201+
interval = 60
202+
203+
[agentapi]
204+
interval = 60
205+
206+
[logsender]
207+
interval = 2
208+
209+
[zbxsender]
210+
interval = 10

Diff for: mamonsu/lib/plugin.py

+3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def items(self, template, dashboard=False):
148148
def graphs(self, template, dashboard=False):
149149
return None
150150

151+
def macros(self, template, dashboard=False):
152+
return None
153+
151154
def triggers(self, template, dashboard=False):
152155
return None
153156

Diff for: mamonsu/lib/sender.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def send(self, key, value, delta=None, host=None, clock=None, only_positive_spee
4141
last_value, last_time = self._last_values[hash_key]
4242
self._last_values[hash_key] = (value, clock)
4343
if delta == Plugin.DELTA.speed_per_second:
44-
value = float(value - last_value) / (clock - last_time)
44+
if last_time == clock:
45+
pass
46+
else:
47+
value = float(value - last_value) / (clock - last_time)
4548
if delta == Plugin.DELTA.simple_change:
4649
value = float(value - last_value)
4750
else:

Diff for: mamonsu/lib/zbx_template.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class ZbxTemplate(object):
3232
</applications>
3333
<items>{items}</items>
3434
<discovery_rules>{discovery_rules}</discovery_rules>
35-
<screens>{screens}</screens>
3635
<macros>{macros}</macros>
36+
<screens>{screens}</screens>
3737
</template>
3838
</templates>
3939
<triggers>{triggers}</triggers>
@@ -172,15 +172,14 @@ def xml(self, plg_type, plugins=None):
172172
self.plg_type = plg_type
173173
# create template
174174
template_data = {'template': self.Template, 'application': self.Application}
175-
if Plugin.Type == 'agent':
176-
template_data['macros'] = self._macro()
177-
else:
178-
template_data['macros'] = ""
179-
template_data['triggers'] = self._get_all('triggers', plugins)
180175
template_data['items'] = self._get_all('items', plugins)
181-
template_data['graphs'] = self._get_all('graphs', plugins)
182176
template_data['discovery_rules'] = self._get_all('discovery_rules', plugins)
177+
if Plugin.Type == 'agent':
178+
template_data['macros'] = self.agent_macro()
179+
template_data['macros'] = self._get_all('macros', plugins)
183180
template_data['screens'] = self.screen(plugins)
181+
template_data['triggers'] = self._get_all('triggers', plugins)
182+
template_data['graphs'] = self._get_all('graphs', plugins)
184183
output_xml = self.mainTemplate.format(**template_data)
185184
if Plugin.Type == 'agent':
186185
output_xml = ZbxTemplate.turn_agent_type(self, output_xml)
@@ -300,14 +299,21 @@ def screen(self, plugins=None, xml_key='screen'):
300299
xml_key)
301300
return result
302301

303-
def _macro(self, xml_key='macro'):
302+
def agent_macro(self, xml_key='macro'):
304303
result = ''
305304
value = {'value': '-qAt -p 5433 -U postgres ', 'macro': "{$PG_CONNINFO}"}
306305
result += '<{1}>{0}</{1}>'.format(self._format_args(self.macro_defaults, value), xml_key)
307306
value = {'value': '/opt/pgpro/std-10/bin/psql', 'macro': "{$PG_PATH}"}
308307
result += '<{1}>{0}</{1}>'.format(self._format_args(self.macro_defaults, value), xml_key)
309308
return result
310309

310+
def mamonsu_macro(self, args=None, xml_key='macro', defaults=None):
311+
if args is None:
312+
args = {}
313+
if defaults is None:
314+
defaults = self.macro_defaults
315+
return '<{1}>{0}</{1}>'.format(self._format_args(defaults, args), xml_key)
316+
311317
def item(self, args=None, xml_key='item', prototype=False):
312318
if args is None:
313319
args = {}

Diff for: mamonsu/plugins/common/health.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class Health(Plugin):
99

1010
AgentPluginType = "sys"
1111

12-
DEFAULT_CONFIG = {
13-
"max_memory_usage": str(40 * 1024 * 1024)
12+
# key: (macro, value)
13+
plugin_macros = {
14+
"mamonsu_max_memory_usage": [("macro", "{$MAMONSU_MAX_MEMORY_USAGE}"), ("value", 40 * 1024 * 1024)]
1415
}
1516

1617
counter = 0
@@ -52,6 +53,15 @@ def items(self, template, dashboard=False):
5253
else:
5354
return []
5455

56+
def macros(self, template, dashboard=False):
57+
result = ""
58+
for macro in self.plugin_macros.keys():
59+
result += template.mamonsu_macro(defaults=self.plugin_macros[macro])
60+
if not dashboard:
61+
return result
62+
else:
63+
return []
64+
5565
def triggers(self, template, dashboard=False):
5666
if self.Type == "mamonsu":
5767
result = template.trigger({
@@ -64,8 +74,7 @@ def triggers(self, template, dashboard=False):
6474
if platform.LINUX:
6575
result += template.trigger({
6676
"name": "Mamonsu health: agent memory usage alert on {HOSTNAME}: {ITEM.LASTVALUE} bytes",
67-
"expression": "{#TEMPLATE:mamonsu.memory.rss[max].last()}&gt;" + self.plugin_config(
68-
"max_memory_usage")
77+
"expression": "{#TEMPLATE:mamonsu.memory.rss[max].last()}&gt;" + self.plugin_macros["mamonsu_max_memory_usage"][0][1]
6978
})
7079
else:
7180
result = template.trigger({

Diff for: mamonsu/plugins/pgsql/archive_command.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
class ArchiveCommand(Plugin):
1111
AgentPluginType = "pg"
12-
DEFAULT_CONFIG = {
13-
"max_count_files": str(2)
14-
}
1512
Interval = 60
1613

14+
# key: (macro, value)
15+
plugin_macros = {
16+
"archive_queue_files": [("macro", "{$ARCHIVE_QUEUE_FILES}"), ("value", 2)]
17+
}
18+
1719
# if streaming replication is on, archive queue length and size will always be 0 for replicas
1820
query_agent_count_files = """
1921
WITH values AS (
@@ -177,12 +179,20 @@ def graphs(self, template, dashboard=False):
177179
"position": 1}
178180
}]
179181

182+
def macros(self, template, dashboard=False):
183+
result = ""
184+
for macro in self.plugin_macros.keys():
185+
result += template.mamonsu_macro(defaults=self.plugin_macros[macro])
186+
if not dashboard:
187+
return result
188+
else:
189+
return []
190+
180191
def triggers(self, template, dashboard=False):
181192
return template.trigger({
182193
"name": "PostgreSQL Archiver: count files need to archive on {HOSTNAME} more than 2",
183194
"expression": "{#TEMPLATE:" + self.right_type(self.key,
184-
self.Items[0][0]) + ".last()}&gt;" + self.plugin_config(
185-
"max_count_files")
195+
self.Items[0][0]) + ".last()}&gt;" + self.plugin_macros["archive_queue_files"][0][1]
186196
})
187197

188198
def keys_and_queries(self, template_zabbix):

0 commit comments

Comments
 (0)