提交 4beb5867 作者: martin

格式化代码

上级 fa63448f
('C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\windows_process_exporter.pkg',
{'BINARY': True,
'DATA': True,
'EXECUTABLE': True,
'EXTENSION': True,
'PYMODULE': True,
'PYSOURCE': True,
'PYZ': False,
'SPLASH': True,
'SYMLINK': False},
[('pyi-contents-directory _internal', '', 'OPTION'),
('PYZ-00.pyz',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\PYZ-00.pyz',
'PYZ'),
('struct',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\localpycs\\struct.pyc',
'PYMODULE'),
('pyimod01_archive',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\localpycs\\pyimod01_archive.pyc',
'PYMODULE'),
('pyimod02_importers',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\localpycs\\pyimod02_importers.pyc',
'PYMODULE'),
('pyimod03_ctypes',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\localpycs\\pyimod03_ctypes.pyc',
'PYMODULE'),
('pyimod04_pywin32',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\localpycs\\pyimod04_pywin32.pyc',
'PYMODULE'),
('pyiboot01_bootstrap',
'C:\\Python312\\Lib\\site-packages\\PyInstaller\\loader\\pyiboot01_bootstrap.py',
'PYSOURCE'),
('pyi_rth_inspect',
'C:\\Python312\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py',
'PYSOURCE'),
('windows_process_exporter',
'C:\\pyproject\\yunwei\\process_status_exporter\\windows_process_exporter.py',
'PYSOURCE'),
('python312.dll', 'C:\\Python312\\python312.dll', 'BINARY'),
('_decimal.pyd', 'C:\\Python312\\DLLs\\_decimal.pyd', 'EXTENSION'),
('_hashlib.pyd', 'C:\\Python312\\DLLs\\_hashlib.pyd', 'EXTENSION'),
('_lzma.pyd', 'C:\\Python312\\DLLs\\_lzma.pyd', 'EXTENSION'),
('_bz2.pyd', 'C:\\Python312\\DLLs\\_bz2.pyd', 'EXTENSION'),
('unicodedata.pyd', 'C:\\Python312\\DLLs\\unicodedata.pyd', 'EXTENSION'),
('select.pyd', 'C:\\Python312\\DLLs\\select.pyd', 'EXTENSION'),
('_socket.pyd', 'C:\\Python312\\DLLs\\_socket.pyd', 'EXTENSION'),
('_wmi.pyd', 'C:\\Python312\\DLLs\\_wmi.pyd', 'EXTENSION'),
('_ssl.pyd', 'C:\\Python312\\DLLs\\_ssl.pyd', 'EXTENSION'),
('api-ms-win-crt-conio-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-conio-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-string-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-string-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-environment-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-environment-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-math-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-math-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-locale-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-locale-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-filesystem-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-filesystem-l1-1-0.dll',
'BINARY'),
('VCRUNTIME140.dll', 'C:\\Python312\\VCRUNTIME140.dll', 'BINARY'),
('api-ms-win-crt-process-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-process-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-convert-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-convert-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-time-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-time-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-runtime-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-runtime-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-heap-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-heap-l1-1-0.dll',
'BINARY'),
('api-ms-win-crt-stdio-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-stdio-l1-1-0.dll',
'BINARY'),
('libcrypto-3.dll', 'C:\\Python312\\DLLs\\libcrypto-3.dll', 'BINARY'),
('libssl-3.dll', 'C:\\Python312\\DLLs\\libssl-3.dll', 'BINARY'),
('ucrtbase.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\ucrtbase.dll',
'BINARY'),
('api-ms-win-crt-utility-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-crt-utility-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-datetime-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-datetime-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-interlocked-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-interlocked-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-file-l1-2-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-file-l1-2-0.dll',
'BINARY'),
('api-ms-win-core-handle-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-handle-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-profile-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-profile-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-util-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-util-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-file-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-file-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-file-l2-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-file-l2-1-0.dll',
'BINARY'),
('api-ms-win-core-rtlsupport-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-rtlsupport-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-console-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-console-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-synch-l1-2-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-synch-l1-2-0.dll',
'BINARY'),
('api-ms-win-core-timezone-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-timezone-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-synch-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-synch-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-processthreads-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-processthreads-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-localization-l1-2-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-localization-l1-2-0.dll',
'BINARY'),
('api-ms-win-core-memory-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-memory-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-processenvironment-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-processenvironment-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-errorhandling-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-errorhandling-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-libraryloader-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-libraryloader-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-string-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-string-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-namedpipe-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-namedpipe-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-heap-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-heap-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-sysinfo-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-sysinfo-l1-1-0.dll',
'BINARY'),
('api-ms-win-core-processthreads-l1-1-1.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-processthreads-l1-1-1.dll',
'BINARY'),
('api-ms-win-core-debug-l1-1-0.dll',
'C:\\Program Files (x86)\\Windows Kits\\10\\Windows Performance '
'Toolkit\\api-ms-win-core-debug-l1-1-0.dll',
'BINARY'),
('base_library.zip',
'C:\\pyproject\\yunwei\\process_status_exporter\\build\\windows_process_exporter\\base_library.zip',
'DATA')],
'python312.dll',
False,
False,
False,
[],
None,
None,
None)
This file lists modules PyInstaller was not able to find. This does not
necessarily mean this module is required for running your program. Python and
Python 3rd-party packages include a lot of conditional or optional modules. For
example the module 'ntpath' only exists on Windows, whereas the module
'posixpath' only exists on Posix systems.
Types if import:
* top-level: imported at the top-level - look at these first
* conditional: imported within an if-statement
* delayed: imported within a function
* optional: imported within a try-except-statement
IMPORTANT: Do NOT post this list to the issue-tracker. Use it as a basis for
tracking down the missing module yourself. Thanks!
missing module named _sha512 - imported by random (optional)
missing module named pwd - imported by posixpath (delayed, conditional, optional), shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional), http.server (delayed, optional), netrc (delayed, conditional), getpass (delayed)
missing module named grp - imported by shutil (delayed, optional), tarfile (optional), pathlib (delayed, optional), subprocess (delayed, conditional, optional)
missing module named posix - imported by os (conditional, optional), shutil (conditional), importlib._bootstrap_external (conditional), posixpath (optional)
missing module named resource - imported by posix (top-level), prometheus_client.process_collector (optional)
missing module named _frozen_importlib_external - imported by importlib._bootstrap (delayed), importlib (optional), importlib.abc (optional)
excluded module named _frozen_importlib - imported by importlib (optional), importlib.abc (optional)
missing module named vms_lib - imported by platform (delayed, optional)
missing module named 'java.lang' - imported by platform (delayed, optional)
missing module named java - imported by platform (delayed)
missing module named _winreg - imported by platform (delayed, optional)
missing module named _scproxy - imported by urllib.request (conditional)
missing module named termios - imported by getpass (optional)
missing module named _posixsubprocess - imported by subprocess (conditional)
missing module named fcntl - imported by subprocess (optional)
This source diff could not be displayed because it is too large. You can view the blob instead.
"""
功能描述:
本脚本主要实现通过执行windows系统的tasklist命令,来返回每个进程的信息
起监听端口,并将进程信息返回,实现exporter的功能
使用方法:
可以直接在有python环境的windows服务器上执行,也可以通过pyinstaller工具打包成exe文件,直接双击运行。
打包命令参考如下:
pyinstaller.exe -F ./windows_process_exporter.py
"""
from subprocess import check_output from subprocess import check_output
from time import sleep from time import sleep
from prometheus_client import start_http_server, Gauge from prometheus_client import start_http_server, Gauge
...@@ -25,7 +34,7 @@ if __name__ == '__main__': ...@@ -25,7 +34,7 @@ if __name__ == '__main__':
print('*' * 20, "Windows process exporter For Prometheus", '*' * 20) print('*' * 20, "Windows process exporter For Prometheus", '*' * 20)
print("You can directly start to use default port 8760,\nor add --port port_num as a start args to use port_num") print("You can directly start to use default port 8760,\nor add --port port_num as a start args to use port_num")
# 创建一个Gauge指标 # 创建一个Gauge指标
window_memory_used_by_process = Gauge('window_memory_used_by_process', 'Window process Memory Used', windows_memory_used_by_process = Gauge('window_memory_used_by_process', 'Window process Memory Used',
['title', 'pid', 'image']) ['title', 'pid', 'image'])
# 解析命令行参数 # 解析命令行参数
...@@ -42,9 +51,9 @@ if __name__ == '__main__': ...@@ -42,9 +51,9 @@ if __name__ == '__main__':
cmd_window_info = get_cmd_window_info() cmd_window_info = get_cmd_window_info()
# 更新指标的值 # 更新指标的值
window_memory_used_by_process._metrics.clear() windows_memory_used_by_process._metrics.clear()
for info in cmd_window_info: for info in cmd_window_info:
window_memory_used_by_process.labels(title=info['title'], pid=str(info['pid']), windows_memory_used_by_process.labels(title=info['title'], pid=str(info['pid']),
image=str(info['image'])).set( image=str(info['image'])).set(
info['mem_use']) info['mem_use'])
......
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['windows_process_exporter.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='windows_process_exporter',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
2024-03-02 16:38:59 - werkzeug - INFO - _internal:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. 2024-03-02 16:45:59 - werkzeug - INFO - _internal:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:7777 * Running on http://127.0.0.1:7777
2024-03-02 16:38:59 - werkzeug - INFO - _internal:Press CTRL+C to quit 2024-03-02 16:45:59 - werkzeug - INFO - _internal:Press CTRL+C to quit
2024-03-02 16:39:54 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:39:54] "GET / HTTP/1.1" 200 - 2024-03-02 16:46:10 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:46:10] "GET /status HTTP/1.1" 200 -
2024-03-02 16:39:56 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:39:56] "GET / HTTP/1.1" 200 - 2024-03-02 16:46:21 - urllib3.connectionpool - DEBUG - connectionpool:Starting new HTTP connection (1): 127.0.0.1:8760
2024-03-02 16:39:57 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:39:57] "GET / HTTP/1.1" 200 - 2024-03-02 16:46:21 - urllib3.connectionpool - DEBUG - connectionpool:http://127.0.0.1:8760 "GET / HTTP/1.1" 200 5344
2024-03-02 16:40:00 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:40:00] "GET /status HTTP/1.1" 200 - 2024-03-02 16:46:22 - root - INFO - logging_flask_test:200
2024-03-02 16:40:10 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:40:10] "GET /statu HTTP/1.1" 404 -
2024-03-02 16:40:16 - urllib3.connectionpool - DEBUG - connectionpool:Starting new HTTP connection (1): 127.0.0.1:8760
2024-03-02 16:40:16 - urllib3.connectionpool - DEBUG - connectionpool:http://127.0.0.1:8760 "GET / HTTP/1.1" 200 5402
2024-03-02 16:40:16 - root - INFO - pjzx_service_monitor:200
2024-03-02 16:41:47 - werkzeug - INFO - _internal:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:7777
2024-03-02 16:41:47 - werkzeug - INFO - _internal:Press CTRL+C to quit
2024-03-02 16:41:51 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:41:51] "GET /statu HTTP/1.1" 404 -
2024-03-02 16:41:53 - werkzeug - INFO - _internal:127.0.0.1 - - [02/Mar/2024 16:41:53] "GET /status HTTP/1.1" 200 -
2024-03-02 16:41:59 - urllib3.connectionpool - DEBUG - connectionpool:Starting new HTTP connection (1): 127.0.0.1:8760
2024-03-02 16:41:59 - urllib3.connectionpool - DEBUG - connectionpool:http://127.0.0.1:8760 "GET / HTTP/1.1" 200 5324
2024-03-02 16:41:59 - root - INFO - logging_flask_test:200
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论