十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
我们提供的服务有:成都做网站、成都网站制作、成都外贸网站建设、微信公众号开发、网站优化、网站认证、双河ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的双河网站制作公司
error_reporting( E_ALL&~E_NOTICE );
define('ELK_QUERY_RR_QUERY', '{
"query": {
"filtered": {
"query": {
"query_string": {
"analyze_wildcard": true,
"query": "type:phptestkv AND report_type:\"passport.login\""
}
},
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "now-15m"
}
}
}
],
"must_not": []
}
}
}
},
"size": 0,
"aggs": {
"1": {
"terms": {
"field": "success",
"size": 5,
"order": {
"_count": "desc"
}
}
}
}
}
}');
define('ELK_QUERY_RR_URL', 'http://localhost:9200/logstash-phptest-*/_search?search_type=count&pretty');
function curl_post($url, $content, $header=''){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($curl);
if (curl_errno($curl))
{
print("[error] CURL ERROR: ".curl_error($curl)."\r\n");
}
curl_close($curl);
return $tmpInfo;
}
function Query_Curl(){
$request_params_rr_query = ELK_QUERY_RR_QUERY;
$rr_target =curl_post(ELK_QUERY_RR_URL, $request_params_rr_query, 'Authorization:Basic bmVpZ291OjE5dkpDYzdCUUltbw==');
return get_rr_value($rr_target);
}
function get_rr_value($results){
$results_object = json_decode($results, true);
return $results_object;
}
function query(){
$result=Query_Curl();
$doc_count=$result['aggregations']['1']['buckets'][0]['doc_count'];
$total=$result['hits']['total'];
$ratio=0;
if($total>=10){
if($doc_count && $total){
$ratio=round($doc_count/$total, 2);
}
if($result['aggregations']['1']['buckets'][0]['key']==1){
if($ratio){
$ratio=1-($ratio);
}
}
}
return $ratio;
}
$ratio=query();
echo $ratio;
?>