api1024/urlmoniti

v1.0.2 2017-03-19 12:13 UTC

This package is not auto-updated.

Last update: 2020-04-22 18:54:12 UTC


README

composer require api1024/urlmoniti

启动一个本地的测试Server

cd vendor/api1024/urlmoniti/tests
php -S localhost:8000 .

添加一些监控的url

use api1024\urlmoniti\core\Api;
function print_sms($mobile, $sms) {
    print_r($mobile.$sms);
}
#默认10s算超时
$api = new Api(
    ['192.168.10.122', 3306, 'root', '123456', 'url_moniti'], #mysql
    ['192.168.10.122', 6379, '', ''], #redis
    'print_sms'
    );
$my_urls = [
    'http://localhost:8000/http200.php',
    'http://localhost:8000/http404.php',
    'http://localhost:8000/http403.php',
    'http://localhost:8000/http500.php',
    'http://localhost:8000/http503.php',
    'http://localhost:8000/timeout.php',
    'http://localhost:8000/sleep1.php',
    'http://localhost:8000/random.php',
    'http://domain.notexist',
];
#添加url
foreach ($my_urls as $url) {
    # code...
    print_r("URL:" . $url ."\n");
    $r = $api->new_user_url($url, '18911490124', '18911490124,18911490125');
    print_r(($r==1)?"true":"fail");
    print_r("\n");

}

写个程序开始实时监控 crontab 1分钟执行一次

use api1024\urlmoniti\core\Api;

##这里修改监控报警程序
function print_sms($mobile, $sms) {
    print_r($mobile.$sms."\n");
}

$api = new Api(
    ['192.168.10.122', 3306, 'root', '123456', 'url_moniti'], #mysql
    ['192.168.10.122', 6379, '', ''], #redis
    'print_sms'
    );
$page = 1;
$limit = 1000;

while(1) {
    $all_urls_1000 = ($api->get_all_urls($page, $limit));
    if(empty($all_urls_1000)) break;

    $page++;
    array_walk($all_urls_1000 , 'check_url');
}

function check_url($url) {
    global $api;
    $api->check_url_and_filter_status($url);
}

查看url状态

use api1024\urlmoniti\core\Api;
function print_sms($mobile, $sms) {
    print_r($mobile.$sms);
}
#默认10s算超时
$api = new Api(
    ['192.168.10.122', 3306, 'root', '123456', 'url_moniti'], #mysql
    ['192.168.10.122', 6379, '', ''], #redis
    'print_sms'
);
$my_urls = [
    'http://localhost:8000/http200.php',
    'http://localhost:8000/http404.php',
    'http://localhost:8000/http403.php',
    'http://localhost:8000/http500.php',
    'http://localhost:8000/http503.php',
    'http://localhost:8000/timeout.php',
    'http://localhost:8000/sleep1.php',
    'http://localhost:8000/random.php',
    'http://domain.notexist',
];
foreach ($my_urls as $url) {
    # code...
    print_r("URL:" . $url ."\n");
    $status = $api->get_url_active_man($url);
    print_r($status);
    print_r("\n");
}