项目作者: toxmc

项目描述 :
一个运用php与swoole实现的统计监控系统
高级语言: PHP
项目地址: git://github.com/toxmc/statistics.git


statistics

一个运用php与swoole实现的统计监控系统

如果有使用laravel 的朋友,推荐另外一个项目fast-laravel。欢迎使用,喜欢的话给个star鼓励下。谢谢各位

界面截图

Swoole statistics screenshot one

Swoole statistics screenshot two

Swoole statistics screenshot three

Swoole statistics screenshot four

说明

  • 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扩展

  1. Install swoole extension from pecl

    1. pecl install swoole
  2. Install swoole extension from source

    1. sudo apt-get install php5-dev
    2. git clone https://github.com/swoole/swoole-src.git
    3. cd swoole-src
    4. phpize
    5. ./configure
    6. make && make install

安装

1. 下载 Swoole statistics

linux shell Clone the git repo:

  1. git clone https://github.com/smalleyes/statistics.git

linux wget the zip file:

  1. wget https://github.com/smalleyes/statistics/archive/master.zip
  2. unzip master.zip

2. 安全

  1. 管理员用户名密码默认都为admin
  2. 如果不需要登录验证,在applications/Statistics/Config/Config.php里面设置管理员密码留空。
  3. 请自行做好安全相关的限制.

运行

  • 配置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。

客户端使用方法

  1. <?php
  2. /**
  3. * examples
  4. * @author xmc
  5. */
  6. class User {
  7. public static function getInfo()
  8. {
  9. $res = array();
  10. $res = array('name'=>'xmc','password'=>'123456');
  11. return $res;
  12. }
  13. public static function addInfo()
  14. {
  15. $res = array();
  16. $res = array('name'=>'xmc','password'=>'123456');
  17. return $res;
  18. }
  19. public static function getErrCode()
  20. {
  21. $errcode = 10001;
  22. return $errcode;
  23. }
  24. public static function getErrMsg()
  25. {
  26. $errmsg = '添加用户失败';
  27. return $errmsg;
  28. }
  29. }
  30. include 'StatisticClient.php';
  31. // 统计开始
  32. StatisticClient::tick("User", 'addInfo');
  33. // 统计的产生,接口调用是否成功、错误码、错误日志
  34. $success = true; $code = 0; $msg = '';
  35. // 假如有个User::getInfo方法要监控
  36. $user_info = User::addInfo();
  37. if(!$user_info){
  38. // 标记失败
  39. $success = false;
  40. // 获取错误码,假如getErrCode()获得
  41. $code = User::getErrCode();
  42. // 获取错误日志,假如getErrMsg()获得
  43. $msg = User::getErrMsg();
  44. }
  45. // 上报结果
  46. $res = StatisticClient::report('User', 'addInfo', $success, $code, $msg);
  47. echo "done over...\n";
  48. var_dump($user_info,$res);