Skip to content

leeyoshinari/performance_monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

performace_monitor

中文文档

Introduction

Completed functions

  1. Monitoring the CPU usage, IO wait, Memory, Disk IO, Network, and TCP connections of the server.
  2. Monitoring the CPU usage, Context switching, Memory, Disk read and write, and TCP connections of the specified port.
  3. For Java applications, monitoring size of JVM and Garbage collection; when the frequency of Full GC is too high, an email alert will be sent.
  4. When the Server CPU usage is too high, or free memory is too low, an email alert will be sent; And can clear the cache automatically.
  5. Start or Stop monitoring specified port at any time.
  6. When the port restarts, it can automatically re-monitor.
  7. Support Operational monitoring, when the port stopped, an email alert will be sent.
  8. Stopping the Agent directly on the Server.
  9. Monitoring data can be visualized according to the specified time period.
  10. Calculate the percentiles of the CPU, Disk IO, and Network.
  11. Monitoring data sampling frequency is up to about 1 time/sec, and any frequency can be set.
  12. The real-time usage of server(CPU, Memory, and Disk) can be viewed directly on the page.
  13. A Server can manager multiple Agents at the same time.
  14. If Server is stopped, it doesn't affect the monitoring of Agent.

Implement

  1. Framework: aiohttp.
  2. Template rendering: jinja2.
  3. Visualization: echarts.
  4. Thread pool and queue to monitor.
  5. Database: InfluxDB.
  6. In order to ensure the accuracy of the monitoring data, use Linux's commands to get data directly, and there is no curve fitting during visualization.

Usage

  1. Clone performance_monitor

    git clone https://github.com/leeyoshinari/performance_monitor.git

    The server folder is the Server, and only one needs to be deployed; the agent folder is Agent, and deployed on the servers that need to be monitored.

  2. Deploy InfluxDB2, the latest version is recommended.

  3. Respectively modify the configuration files config.ini in the server and agent folders.

  4. Install packages

    pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
  5. Check the version of sysstat. Respectively use commands iostat -V and pidstat -V, the version of 12.4.0 has been tested, if not, please click me to download it.

  6. Respectively run server.py in server and agent folders.

    nohup python3 server.py &
  7. Visit pages
    (1) After Agent is started, visit http://ip:port, you can see the server's data(CPU, Meeory, Disk, Network, etc.).
    agent home

    (2) After server is started, visit http://ip:port/'context', you can see some informations about Agents.
    server home

    (3) Click MonitorList tab to see the monitoring page. Select server and enter the port, then click the startMonitor button to start monitoring the port on the selected server; click the stopMonitor button to stop monitoring the port on the selected server.
    startMonitor

    (4) Click Visualize tab to see the visualization page. Select server, type, disk, startTime and endTime, then click the Visualize button to visualize the monitoring data.
    Visualize

Package

Using pyinstaller to package python code. After packaging, it can be quickly deployed agent on other Agents without installing python3.7+ and third-party packages.
Before packaging, you must ensure that the python code can run normally.

  1. Package server
    (1) Enter the server folder, run:

    pyinstaller -F server.py -p draw_performance.py -p config.py -p Email.py -p logger.py -p process.py -p request.py -p __init__.py --hidden-import draw_performance --hidden-import config --hidden-import logger --hidden-import Email --hidden-import process --hidden-import request
    

    (2) Enter dist folder, find the executable file server,
    (3) Copy config.ini to the dist folder,
    (4) Copy templates and static to the dist folder,
    (5) Start server

    nohup ./server &
  2. Package agent
    (1) Enter agent folder, run:

    pyinstaller -F server.py -p performance_monitor.py -p logger.py -p config.py -p common.py -p __init__.py --hidden-import logger --hidden-import performance_monitor --hidden-import common --hidden-import config

    (2) Enter dist folder, find the executable file server,
    (3) Copy config.ini to the dist folder,
    (4) Copy the dist folder to other servers, and start server

    nohup ./server &

    NOTE: Since the agent needs to run on the server to be monitored, the executable file packaged on the server of the CentOS system X86 architecture can only run on the server of the CentOS system X86 architecture; servers of other system and architecture need to be repackaged agent.

Note

  1. The server must support the following commands: ps, jstat, iostat, pidstat and netstat, if not, please install them.

  2. The network card of server must be in full duplex mode, if not, the network usage will be incorrect.

  3. The version of sysstat must be 12+, the 12 version has been tested, other versions have not been tested, and using old version may cause data abnormalities; please click me to download the latest version.

  4. The code can be run on almost any linux system that can run python. The tested systems have CentOS, Ubuntu, KylinOS, NeoKylin, support X86_64 and ARM architecture.