gpt4 book ai didi

php - 如何使用 PHP 脚本测试 logstash

转载 作者:行者123 更新时间:2023-11-28 21:11:55 25 4
gpt4 key购买 nike

我刚刚安装了 logstash,用输入、过滤器和输出配置了它的配置文件,最后运行了它。是否可以通过编写一些PHP脚本来测试logstash是否推送日志数据?有人可以给我一些可以捕获日志数据的 php 脚本,从 logstash 发送吗?

最佳答案

运行以下命令以获取 elasticsearch 索引中的日志列表:

    $date = date("Y.m.d");
$host = "127.0.0.1";
$port = "9200";
$index = "logstash-".$date;
$type = "*";


$log = array();
$query = '{"query":{"match_all":{}}}';

$curl = curl_init();
if ($curl) {
curl_setopt($curl,CURLOPT_URL, $host."/".$index."/".$type."/_search");
curl_setopt($curl, CURLOPT_PORT, $port);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if (curl_errno($curl)) {
echo curl_error($curl); //error
}

curl_close($curl);

if (!$result) {
//error
}
$arr=(json_decode($result, true));
$logs = $arr['hits']['hits'];
// If any logs were found
if (count($logs)>0) {
foreach ($logs as $q) {
// load the data in the $data array
$log[] = $q["_source"];
echo "<pre>";
print_r($log);
echo "</pre>";
}
}
}
?>

干杯。

关于php - 如何使用 PHP 脚本测试 logstash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22218452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com