typecho结合宝塔API查看服务器信息
可以通过宝塔给出的API接口,在网站上直接看到服务器当前的信息状态
打开宝塔面板的面板设置-api接口,如图
这里提到的开启API后,必需在IP白名单列表中的IP才能访问面板API接口,除了必须要填入127.0.0.1之外,还有一个ip就是你当前访问服务器的ip,比如如果你是电脑的软件,那就是电脑的ip地址,如果是网站,那就是网站的ip地址
宝塔api说明手册pdf地址:https://www.bt.cn/api-doc.pdf
typecho主题里面,设置了获取宝塔路径和接口密钥
通过ECharts.js插件展示,下面代码为functions.php里面的执行函数
/* 获取服务器状态 */
function _getServerStatus($archive)
{
$archive->response->setStatus(200);
$api_panel = Helper::options()->BTPanel;
$api_sk = Helper::options()->BTKey;
if (!$api_panel) return $archive->response->throwJson([
"code" => 0,
"data" => "宝塔面板地址未填写!"
]);
if (!$api_sk) return $archive->response->throwJson([
"code" => 0,
"data" => "宝塔接口密钥未填写!"
]);
$request_time = time();
$request_token = md5($request_time . '' . md5($api_sk));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_panel . '/system?action=GetNetWork');
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 3000);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 3000);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("request_time" => $request_time, "request_token" => $request_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
$archive->response->throwJson(array(
/* 状态 */
"status" => $response ? true : false,
/* 信息提示 */
"message" => $response['msg'],
/* 上行流量KB */
"up" => $response["up"] ? $response["up"] : 0,
/* 下行流量KB */
"down" => $response["down"] ? $response["down"] : 0,
/* 总发送(字节数) */
"upTotal" => $response["upTotal"] ? $response["upTotal"] : 0,
/* 总接收(字节数) */
"downTotal" => $response["downTotal"] ? $response["downTotal"] : 0,
/* 内存占用 */
"memory" => $response["mem"] ? $response["mem"] : ["memBuffers" => 0, "memCached" => 0, "memFree" => 0, "memRealUsed" => 0, "memTotal" => 0],
/* CPU */
"cpu" => $response["cpu"] ? $response["cpu"] : [0, 0, [0], 0, 0, 0],
/* 系统负载 */
"load" => $response["load"] ? $response["load"] : ["fifteen" => 0, "five" => 0, "limit" => 0, "max" => 0, "one" => 0, "safe" => 0],
));
}
以上为部分代码展示,仅作为参考研究,提示:typecho程序里面的Joe主题内置有这个功能,喜欢的朋友可以去找找这款主题
以下为typecho结合宝塔API查看服务器信息的图片展示
发表评论
仅有一条评论
热门文章
Spimes主题专为博客、自媒体、资讯类的网站设计....
一款个人简历主题,可以简单搭建一下,具体也比较简单....
用于作品展示、资源下载,行业垂直性网站、个人博客,....
仿制主题,Typecho博客主题,昼夜双版设计,可....
热评文章
最新评论
Debbyhu888
4月8日
https://www.itsallaboutblogsonline.com
In order to get the best results out of these links, you need to obtain relevant links from related websites and articles as well links from websites that are already perceived to have high authority. Here is our list of strategies to increase the amount of quality links coming into your site so that you don’t get penalized by Google during the next algorithm update.
:笑眼:感谢小灯泡分享这么好的功能