# website_monitor **Repository Path**: ad-py3/website_monitor ## Basic Information - **Project Name**: website_monitor - **Description**: 请求公网地址,数据打入到 prometheus, grafana展示 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-06 - **Last Updated**: 2024-07-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### 请求公网地址,数据打入到 prometheus, grafana展示 ### python编写exporter监控接口访问数量+错误率+响应时间 ```angular2html yum install gcc gcc-c++ git libyaml-devel zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel python3-devel.x86_64 python-devel.x86_64 libcurl-devel -y pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt ``` ###修改配置文件增加数据收集 vi prometheus.yml 然后再grafana上配置数据源 ```angular2html # 增加监听的 IP 端口,稍后用Python起一个http服务 - job_name: 'business_data_panel_monitor' scrape_interval: 60s metrics_path: /metrics static_configs: - targets: ['180.76.52.138:9521'] ~ ``` 修改玩配置文件,重新加载 ```angular2html curl -XPOST http://127.0.0.1:9090/-/reload ``` ```angular2html pip3 uninstall pycurl Cannot uninstall requirement pycurl, not installed [root@ecs-prod-prometheus-arch-0006 website_monitor]# export PYCURL_SSL_LIBRARY=nss [root@ecs-prod-prometheus-arch-0006 website_monitor]# pip3 install pycurl ``` ###显示期望时间的比例,比如只显示小于1秒,占总次数的比例 ``` delta(url_http_request_time_total{le='1'}[1m]) / on(url) group_left delta(http_request_total[1m]) ``` ###http code的每分钟增长率,如果出现5xx,就说明有问题了 ```angular2html Metrics irate(url_http_code_total[1m]) Legend {{url}}:{{code}} ``` ```angular2html curl -XPOST http://10.94.12.250:9090/-/reload curl -X POST -g 'http://xxx.com/prometheus/api/v1/admin/tsdb/delete_series?match[]={wanip="12.0.0.1:9085"} ```