GithubHelp home page GithubHelp logo

toxmc / statistics Goto Github PK

View Code? Open in Web Editor NEW
443.0 34.0 104.0 659 KB

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

License: MIT License

PHP 98.07% CSS 0.24% Hack 1.69%
php-swoole statistics-swoole swoole-extension linux

statistics's Introduction

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

    pecl install swoole
    
  2. 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);
    

statistics's People

Contributors

jwcn avatar toxmc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

statistics's Issues

看到这个项目,感觉很不错

github上说,是通过客户端udp上报的方式去发送数据,在example中也看到了。发送至55656端口
而在配置文件中,又看到是通过udp发送广播,然后tcp去拉取统计数据。

在管理页面,也发现了“无法从以下数据源获取数据:192.168.0.188::55858 ”
请问有相关的文档去对这个项目进行一些解释么

没看明白server和web是靠什么打通数据的?

server端把数据收集到了statisticData里
web端从\Statistics\Lib\Cache::$statisticDataCache['statistic']里读数据,
问题是statisticData和\Statistics\Lib\Cache::$statisticDataCache['statistic']是在哪里打通数据的?

样式加载不出来

您好,样式加载不出来是什么情况哇?
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://192.168.88.2:55655/css/bootstrap.min.css".
192.168.88.2/:16 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://192.168.88.2:55655/css/style.css".
jquery.min.js:1 Uncaught SyntaxError: Unexpected token <
bootstrap.min.js:1 Uncaught SyntaxError: Unexpected token <
scripts.js:1 Uncaught SyntaxError: Unexpected token <
jquery.min.js:1 Uncaught SyntaxError: Unexpected token <
highcharts.js:1 Uncaught SyntaxError: Unexpected token <
?date=2015-10-25&:95 Uncaught ReferenceError: Highcharts is not defined

关于collectStatistics在多worker并发操作$this->statisticData时的疑问

protected function collectStatistics($module, $interface, $cost_time, $success, $ip, $code, $msg)
{
// 统计相关信息
if (! isset($this->statisticData[$ip])) {
$this->statisticData[$ip] = array();
}
if (! isset($this->statisticData[$ip][$module])) {
$this->statisticData[$ip][$module] = array();
}
if (! isset($this->statisticData[$ip][$module][$interface])) {
$this->statisticData[$ip][$module][$interface] = array(
'code' => array(),
'suc_cost_time' => 0,
'fail_cost_time' => 0,
'suc_count' => 0,
'fail_count' => 0
);
}
if (! isset($this->statisticData[$ip][$module][$interface]['code'][$code])) {
$this->statisticData[$ip][$module][$interface]['code'][$code] = 0;
}
$this->statisticData[$ip][$module][$interface]['code'][$code] ++;
if ($success) {
$this->statisticData[$ip][$module][$interface]['suc_cost_time'] += $cost_time;
$this->statisticData[$ip][$module][$interface]['suc_count'] ++;
} else {
$this->statisticData[$ip][$module][$interface]['fail_cost_time'] += $cost_time;
$this->statisticData[$ip][$module][$interface]['fail_count'] ++;
}
}

请问并发时是如何保证$this->statisticData不会产生多个worker同时操作此变量的

建议各位朋友使用任务队列,减少对业务代码的侵入性。

这个项目我喜欢的是,错误码分布情况的统计,
以前侧重在接口请求耗时统计,这个工具提供了不一样的视角。

但是,在使用的过程中发现,
需要在每一个想统计的地方加代码,
如果统计系统出问题,必然影响业务,
概率应该比较低,但是没人会专门维护这个。

所以
建议各位朋友使用任务队列,
比如readme.md中的当添加用户失败,扔一个统计任务到队列,然后由队列的消费者,上报统计数据
即使上报失败对业务也没有影响,错误码上报的并没有很高的实时性要求。
这样可以减少统计功能对业务代码的侵入性。

Tips:你要对消息队列或者任务队列熟悉才可以哦。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.