Skip to content

Commit d03ca77

Browse files
committed
BUILD: for windows , PGPRO-4091
1 parent 6ea90f6 commit d03ca77

File tree

10 files changed

+321
-7
lines changed

10 files changed

+321
-7
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Build win32 exe: (worked with python v3.{4,5}: py2exe v0.9.2.2 and pywin32 v220
7878
$ c:\mamonsu\service_win32.exe -install
7979
$ net start mamonsu
8080
81+
or
82+
$ pyinstaller --onefile mamonsu_win32.spec
83+
$ pyinstaller --onefile service_win32.spec
84+
8185
Build nsis installer:
8286

8387
.. code-block:: bash

agent_win32.conf

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# This is a configuration file for mamonsu
2+
# To get more information about mamonsu, visit https://postgrespro.ru/docs/postgrespro/12/mamonsu
3+
4+
######### Connection parameters sections ##############
5+
6+
# specify connection parameters for the Postgres cluster
7+
# in the user, password, and database fields, you must specify the mamonsu_user, mamonsu_password,
8+
# and the mamonsu_database used for bootstrap, respectively.
9+
# if you skipped the bootstrap, specify a superuser credentials and the database to connect to.
10+
11+
[postgres]
12+
enabled = True
13+
user = postgres
14+
password = None
15+
database = postgres
16+
host = localhost
17+
port = 5432
18+
application_name = mamonsu
19+
query_timeout = 10
20+
21+
# the address field must point to the running Zabbix server, while the client field must provide the name of
22+
# the Zabbix host. You can find the list of hosts available for your account in the Zabbix web
23+
# interface under Configuration > Hosts.
24+
25+
[zabbix]
26+
enabled = True
27+
client = localhost
28+
address = 127.0.0.1
29+
port = 10051
30+
31+
######### General parameters sections ############
32+
33+
# enable or disable collection of system metrics.
34+
35+
[system]
36+
enabled = True
37+
38+
# control the queue size of the data to be sent to the Zabbix server
39+
40+
[sender]
41+
queue = 2048
42+
43+
# specify the location of mamonsu and whether it is allowed to access metrics from the command line
44+
45+
[agent]
46+
enabled = True
47+
host = 127.0.0.1
48+
port = 10052
49+
50+
# specify custom plugins to be added for metrics collection
51+
52+
[plugins]
53+
enabled = False
54+
directory = c:\mamonsu\plugins
55+
56+
# enable storing the collected metric data in text files locally.
57+
58+
[metric_log]
59+
enabled = False
60+
directory = c:\mamonsu\log
61+
max_size_mb = 1024
62+
63+
# specify logging settings for mamonsu
64+
65+
[log]
66+
file = c:\mamonsu\log\agent.log
67+
level = INFO
68+
format = [%(levelname)s] %(asctime)s - %(name)s - %(message)s
69+
70+
######### Individual Plugin Sections ############
71+
72+
# to disable any plugin set the enabled option to False.
73+
# modify collection interval for each plugin in the interval field.
74+
# set customer parameters for some plugins in the individual section.
75+
# below listed all available parameters for each plugin to modify.
76+
77+
[health]
78+
max_memory_usage = 41943040
79+
interval = 60
80+
81+
[bgwriter]
82+
interval = 60
83+
84+
[connections]
85+
percent_connections_tr = 90
86+
interval = 60
87+
88+
[databases]
89+
bloat_scale = 0.2
90+
min_rows = 50
91+
interval = 300
92+
93+
[pghealth]
94+
uptime = 600
95+
cache = 80
96+
interval = 60
97+
98+
[instance]
99+
interval = 60
100+
101+
[xlog]
102+
lag_more_then_in_sec = 300
103+
interval = 60
104+
105+
[pgstatstatement]
106+
interval = 60
107+
108+
[pgbuffercache]
109+
interval = 60
110+
111+
[pgwaitsampling]
112+
interval = 60
113+
114+
[checkpoint]
115+
max_checkpoint_by_wal_in_hour = 12
116+
interval = 300
117+
118+
[oldest]
119+
max_xid_age = 18000000
120+
max_query_time = 18000
121+
interval = 60
122+
123+
[pglocks]
124+
interval = 60
125+
126+
[cfs]
127+
force_enable = False
128+
interval = 60
129+
130+
[archivecommand]
131+
max_count_files = 2
132+
interval = 60
133+
134+
[procstat]
135+
interval = 60
136+
137+
[diskstats]
138+
interval = 60
139+
140+
[disksizes]
141+
vfs_percent_free = 10
142+
vfs_inode_percent_free = 10
143+
interval = 60
144+
145+
[memory]
146+
enabled = False
147+
interval = 60
148+
149+
[systemuptime]
150+
up_time = 300
151+
interval = 60
152+
153+
[openfiles]
154+
interval = 60
155+
156+
[net]
157+
interval = 60
158+
159+
[la]
160+
interval = 60
161+
162+
[zbxsender]
163+
interval = 10
164+
165+
[logsender]
166+
interval = 2
167+
168+
[agentapi]
169+
interval = 60
170+
171+
# Get age (in seconds) of the oldest running prepared transaction and number of all prepared transactions for two-phase commit.
172+
# https://www.postgresql.org/docs/current/sql-prepare-transaction.html
173+
# https://www.postgresql.org/docs/12/view-pg-prepared-xacts.html
174+
# max_prepared_transaction_time - age of prepared transaction in seconds.
175+
# If pgsql.prepared.oldest exceeds max_prepared_transaction_time the trigger fires.
176+
[preparedtransaction]
177+
max_prepared_transaction_time = 60
178+
interval = 60
179+
180+
# Get size of backup catalogs stroring all WAL and backup files using pg_probackup
181+
# (https://github.com/postgrespro/pg_probackup)
182+
# Trigger fires if some backup has bad status e.g. (ERROR,CORRUPT,ORPHAN).
183+
#[pgprobackup]
184+
#enabled = False
185+
#interval = 300
186+
#backup_dirs = /backup_dir1,/backup_dir2
187+
#pg_probackup_path = /usr/bin/pg_probackup-11

mamonsu/lib/default_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class DefaultConfig(PgsqlConfig):
5050
def default_config_path():
5151
if platform.LINUX:
5252
return '/etc/mamonsu/agent.conf'
53+
elif platform.WINDOWS:
54+
return 'C:\\mamonsu\\agent_win32.conf'
5355

5456
@staticmethod
5557
def get_logger_level(level):

mamonsu/lib/parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from mamonsu import __version__
44
from optparse import OptionParser, BadOptionError
55
import mamonsu.lib.platform as platform
6+
from mamonsu.lib.default_config import DefaultConfig
67

78
usage_msg = """
89
Options:
910
-a, --add-plugins <directory>
1011
-c, --config <file>
1112
-p, --pid <pid-file>
12-
-d daemonize
13+
-d daemonize (this functional do not support in windows)
1314
--version output version information, then exit
1415
--help show this help, then exit
1516
@@ -20,7 +21,7 @@
2021
Options:
2122
--add-plugins <directory>
2223
23-
Export zabbix keys for native zabbix-agent:
24+
Export zabbix keys for native zabbix-agent (this functional do not support in windows):
2425
Command: export zabbix-parameters
2526
Examples:
2627
{prog} export zabbix-parameters <file>
@@ -32,7 +33,7 @@
3233
HINT: Supported version numbers are 12, 10, 11, 9.6, 9.5
3334
3435
35-
Export template for native zabbix agent:
36+
Export template for native zabbix agent (this functional do not support in windows):
3637
Command: export zabbix-template
3738
Examples:
3839
{prog} export zabbix-template [options] <file>
@@ -248,7 +249,7 @@ def parse_args():
248249
usage=usage_msg,
249250
version='%prog {0}'.format(__version__))
250251
parser.add_option(
251-
'-c', '--config', dest='config_file', default='/etc/mamonsu/agent.conf')
252+
'-c', '--config', dest='config_file', default=DefaultConfig.default_config_path())
252253
# pid
253254
parser.add_option(
254255
'-p', '--pid', dest='pid', default=None)

mamonsu/lib/runner.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from mamonsu.lib.plugin import Plugin
1414
from mamonsu.lib.zbx_template import ZbxTemplate
1515
from mamonsu.lib.get_keys import GetKeys
16-
from mamonsu.plugins.system.linux.scripts import Scripts
16+
17+
if platform.LINUX:
18+
from mamonsu.plugins.system.linux.scripts import Scripts
1719

1820

1921
def start():
@@ -79,6 +81,9 @@ def quit_handler(_signo=None, _stack_frame=None):
7981
if not len(commands) == 2 and not len(commands) == 3:
8082
print_total_help()
8183
if commands[1] == 'zabbix-parameters':
84+
if platform.WINDOWS:
85+
print("This functional do not support in windows")
86+
sys.exit(10)
8287
# zabbix agent keys generation
8388
Plugin.Type = 'agent' # change plugin type for template generator
8489
plugins = []
@@ -149,6 +154,9 @@ def quit_handler(_signo=None, _stack_frame=None):
149154
print(" {0} ".format(e))
150155
sys.exit(2)
151156
elif commands[1] == 'zabbix-template':
157+
if platform.WINDOWS:
158+
print("This functional do not support in windows")
159+
sys.exit(10)
152160
Plugin.Type = 'agent' # change plugin type for template generator
153161
if len(commands) == 2:
154162
commands.append('postgrespro_agent.xml')

mamonsu/tools/agent/start.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import urllib.request as urllib
1111
from urllib.error import URLError, HTTPError
12+
from mamonsu.lib.default_config import DefaultConfig
1213

1314

1415
def run_agent():
@@ -32,7 +33,7 @@ def print_help():
3233
usage=usage_msg,
3334
version='%prog agent {0}'.format(__version__))
3435
parser.add_option(
35-
'-c', '--config', dest='config', default='/etc/mamonsu/agent.conf',
36+
'-c', '--config', dest='config', default=DefaultConfig.default_config_path(),
3637
help=optparse.SUPPRESS_HELP)
3738
args, commands = parser.parse_args()
3839

mamonsu_win32.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
3+
from mamonsu.lib.runner import start
4+
5+
if __name__ == '__main__':
6+
start()

mamonsu_win32.spec

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
block_cipher = None
4+
5+
6+
a = Analysis(['mamonsu_win32.py'],
7+
pathex=['C:\\Projects\\Extensions\\mamonsu'],
8+
binaries=[],
9+
datas=[],
10+
hiddenimports=[
11+
'mamonsu.plugins.pgsql.archive_command',
12+
'mamonsu.plugins.pgsql.bgwriter',
13+
'mamonsu.plugins.pgsql.cfs',
14+
'mamonsu.plugins.pgsql.checkpoint',
15+
'mamonsu.plugins.pgsql.connections',
16+
'mamonsu.plugins.pgsql.databases',
17+
'mamonsu.plugins.pgsql.health',
18+
'mamonsu.plugins.pgsql.instance',
19+
'mamonsu.plugins.pgsql.oldest',
20+
'mamonsu.plugins.pgsql.pg_buffercache',
21+
'mamonsu.plugins.pgsql.pg_locks',
22+
'mamonsu.plugins.pgsql.pg_stat_statement',
23+
'mamonsu.plugins.pgsql.pg_wait_sampling',
24+
'mamonsu.plugins.pgsql.plugin',
25+
'mamonsu.plugins.pgsql.pool',
26+
'mamonsu.plugins.pgsql.prepared_transaction',
27+
'mamonsu.plugins.pgsql.relations_size',
28+
'mamonsu.plugins.pgsql.xlog',
29+
'mamonsu.plugins.system.windows.cpu',
30+
'mamonsu.plugins.system.windows.disk_stats',
31+
'mamonsu.plugins.system.windows.helpers',
32+
'mamonsu.plugins.system.windows.memory',
33+
'mamonsu.plugins.system.windows.network',
34+
'mamonsu.lib.senders.log',
35+
'mamonsu.lib.senders.zbx',
36+
'mamonsu.tools.agent.agent',
37+
'mamonsu.tools.agent.start',
38+
'mamonsu',
39+
'mamonsu.plugins',
40+
'mamonsu.plugins.pgsql',
41+
'mamonsu.plugins.system.windows',
42+
'mamonsu.tools.agent',
43+
'mamonsu.tools.bootstrap',
44+
'mamonsu.tools.report',
45+
'mamonsu.tools.sysinfo',
46+
'mamonsu.tools.tune',
47+
'mamonsu.tools.zabbix_cli',
48+
'mamonsu.plugins.common.health'
49+
],
50+
hookspath=[],
51+
runtime_hooks=[],
52+
excludes=[],
53+
win_no_prefer_redirects=False,
54+
win_private_assemblies=False,
55+
cipher=block_cipher,
56+
noarchive=False)
57+
pyz = PYZ(a.pure, a.zipped_data,
58+
cipher=block_cipher)
59+
exe = EXE(pyz,
60+
a.scripts,
61+
a.binaries,
62+
a.zipfiles,
63+
a.datas,
64+
[],
65+
name='mamonsu',
66+
debug=False,
67+
bootloader_ignore_signals=False,
68+
strip=False,
69+
upx=True,
70+
upx_exclude=[],
71+
runtime_tmpdir=None,
72+
console=True )

service_win32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def SvcDoRun(self):
3838
servicemanager.EVENTLOG_INFORMATION_TYPE,
3939
(self._svc_name_, ''))
4040

41-
config_file = os.path.join(exe_dir, 'agent.conf')
41+
config_file = os.path.join(exe_dir, 'agent_win32.conf')
4242
config = Config(config_file)
4343

4444
supervisor = Supervisor(config)

0 commit comments

Comments
 (0)