一個運用php與swoole實現的統計監控系統
一個運用php與swoole實現的統計監控系統
界面截圖
說明
- statistics是一個以swoole作為服務器容器的統計監控系統。
- statisitcs使用PHP開發,無需安裝Mysql等數據庫,無需安裝php-fpm等軟件。
- statistics包含了客戶端和服務端,客戶端是一個類庫,通過函數調用的方式以UDP協議上報數據給服務端。
- statistics服務端接收上報數據然后匯總展示。
- statistics以曲線圖、餅圖和表格的方式展示請求量、耗時、成功率、錯誤日志等。
- workerman版本實現statistics https://github.com/walkor/workerman-statistics
依賴
- PHP 5.3+
- Swoole 1.7.18
- Linux, OS X and basic Windows support (Thanks to cygwin)
安裝 Swoole擴展
-
Install swoole extension from pecl
pecl install swoole
-
Install swoole extension from source
sudo apt-get install php5-dev git clone https://github.com/swoole/swoole-src.git cd swoole-src phpize ./configure make && make install
安裝
1. 下載 Swoole statistics
linux shell Clone the git repo:
git clone https://github.com/smalleyes/statistics.git
linux wget the zip file:
wget https://github.com/smalleyes/statistics/archive/master.zip unzip master.zip
2. 安全
管理員用戶名密碼默認都為admin。 如果不需要登錄驗證,在applications/Statistics/Config/Config.php里面設置管理員密碼留空。 請自行做好安全相關的限制.
運行
- 配置NGINX虛擬主機
- 配置文件位于doc/statistics.conf
- 復制文件statistics.conf到nginx,虛擬主機配置文件目錄下(默認為nginx/conf.d目錄下)
- 重啟nginx或重新加載nginx配置文件(nginx -s reload)
- 配置hoshs文件,綁定ip域名對應關系
- 使用swoole需要啟動服務,php web.php與php worker.php再打開瀏覽器訪問綁定的域名。
- 配置信息都在Config目錄下。
- 開啟守護進程模式,請修改配置Config/Server.php的daemonize選項為TRUE。
客戶端使用方法
<?php /** * examples * @author xmc */ class User { public static function getInfo() { $res = array(); $res = array('name'=>'xmc','password'=>'123456'); return $res; } public static function addInfo() { $res = array(); $res = array('name'=>'xmc','password'=>'123456'); return $res; } public static function getErrCode() { $errcode = 10001; return $errcode; } public static function getErrMsg() { $errmsg = '添加用戶失敗'; return $errmsg; } } include 'StatisticClient.php'; // 統計開始 StatisticClient::tick("User", 'addInfo'); // 統計的產生,接口調用是否成功、錯誤碼、錯誤日志 $success = true; $code = 0; $msg = ''; // 假如有個User::getInfo方法要監控 $user_info = User::addInfo(); if(!$user_info){ // 標記失敗 $success = false; // 獲取錯誤碼,假如getErrCode()獲得 $code = User::getErrCode(); // 獲取錯誤日志,假如getErrMsg()獲得 $msg = User::getErrMsg(); } // 上報結果 $res = StatisticClient::report('User', 'addInfo', $success, $code, $msg); echo "done over...\n"; var_dump($user_info,$res);
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!