【速记】将 OceanBase Sql Plan Monitor 服务化

OceanBase Sql Plan Monitor 对于大查询性能诊断非常好用,之前为了推广,整理了一个离线版。但最终还是觉得差点意思。

能不能类似阿里的“扁鹊”服务,将其服务化呢?使用者只需要登录网页,填写一些基本信息就能一键获得报告?稍微折腾了一下,居然是很简单的。

Web-Service

背景

这个 WebService 最终是通过 lighttpd+php+python 完成

  • sql plan monitor 是用 python 写的;
  • python 做Web动态脚本非常费事
  • PHP 做Web动态脚本非常方便
  • nginx 太麻烦,lighttpd 安装部署很省事

方案

lighttpd 作为 http 服务器,下载安装 lighttpd-fastcgi 模块,安装 php-cgi(一般默认已经有)。稍微配置一下即可。配置文件如下:

[xiaochu.yh /ob/xiaochu.yh/share/monitor_web] $cat lighttpd.php.conf
server.modules += ( "mod_fastcgi" )

server.document-root = "/ob/xiaochu.yh/share/monitor_web/"

server.port = 8080
server.dir-listing = "disable"

mimetype.assign = (
  ".html" => "text/html",
  ".htm" => "text/html",
  ".js"  => "application/javascript",
  ".css" => "text/css",
  ".txt" => "text/plain",
  ".log" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png",
  ".ico" => "image/x-icon"
)

fastcgi.server = ( ".php" =>
  ((
    "socket" => "/tmp/php.socket",
    "bin-path" => "/usr/bin/php-cgi",
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "16",
      "PHP_FCGI_MAX_REQUESTS" => "10000"
    ),
    "min-procs" => 1,
    "max-procs" => 1,
    "idle-timeout" => 100
  ))
)

重启 lighttpd 服务即可

lighttpd -f lighttpd.php.conf

服务化脚本

<?php
$IP = $_GET['info-ip'];
$PORT = $_GET['info-port'];
$USER = $_GET['info-user'];
$PWD = $_GET['info-pass'];
$DB = $_GET['info-db'];
$TRACEID = $_GET['info-traceid'];

if (empty($PWD)) {
  $cmd = "sh mon.sh   -h $IP -P $PORT -u $USER -D $DB --trace-id='$TRACEID' -o report.$TRACEID.html";
} else {
  $cmd = "sh mon.sh   -h $IP -P $PORT -u $USER -D $DB -p $PWD --trace-id='$TRACEID' -o report.$TRACEID.html";
}

$result = shell_exec($cmd);
$rule = "/Report File Generate OK: (report.*\.html)/i";
preg_match($rule, $result, $m);
if (count($m) == 2) {
  header('location:' . $m[1]);
} else {
  echo "<p><a href='javascript:history.go(-1)'>Wrong Parameters. Go Back!</a></p>";
}
?>

总结

理论上,任何内部的小工具都可以基于这种方式做简单的服务化。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值