帮助手册

使用 DLL 编写 Windows 插件

使用动态链接库(DLL)编写插件,按需监控数据。您也可以使用 Batch、PowerShell 和 VB 脚本编写插件。

前提条件

  • 我们 Windows 服务器监控代理的最新版本
  • 插件必须使用 C# 编写(.NET framework 3.0 及以上版本)

编写插件

  1. 下载并安装 服务器上最新版本的 Windows 代理
  2. 打开 Visual Studio 编辑器 > 创建项目 > 选择语言 Visual C# > 类库(用于创建 C# 类库)> 确定 
  3. 为创建的项目添加引用。进入项目菜单 > 添加引用,从代理安装文件夹 C:\Program files (x86)\Site24x7\WinAgent\monitoring\Plugins\PluginsReference 中选择 Site24x7Plugin.Monitor.dll
    注意

    'Site24x7Plugin.Monitor.dll' 包含 IPlugin 接口,其中包含应在创建的项目 C# 类文件中实现的强制变量和方法。 

  4. 在项目的 C# 类文件中,添加命名空间 using Site24x7Plugin.Monitor 并使用 IPlugin 接口实现类。
  5. 类中必须包含的强制变量
    • Version:插件脚本文件的任何变更都需要更新插件版本。默认值为 1。每次对现有插件进行更改后,用户必须将版本号加 1。版本号必须为整数,例如 1、2、3。
  6. 实现 DataCollect() 方法,并编写获取实际数据的逻辑。此方法应返回包含键值对的 Dictionary<string, object>,其中键为指标名称。
  7. 类中可选的变量
    • Heartbeat:当 Site24x7 数据中心未收到插件数据时,将插件告警为宕机。Heartbeat 的值应为 true 或 false,默认值为 true。
    • DisplayName:在 Web 客户端中显示的监视器名称。例如:如果您创建了一个名为 "Site24x7Plugin" 的插件,则插件类的 DisplayName 返回值必须为 "Site24x7Plugin"。
    • msg:将 DataCollect() 方法执行期间捕获的错误消息赋值给此变量 
    • Version、Displayname 和 Heartbeat 属性均返回字符串对象
  8. 类中可选的方法
    • Units() 方法应返回包含键值对的 Directory<string, object>,键为要监控的属性名称,值为相应的单位。 
  9. 依次进入 Visual Studio > 生成菜单 > 生成解决方案,构建项目。 系统将创建一个 .dll 文件。 
  10. 代理安装目录/Monitoring/Plugins下创建文件夹,并将 .dll 文件复制到该文件夹中。
    注意

    请确保文件名和文件夹名称完全相同。 例如,如果您为 Apache 编写插件,文件夹名称应为 Apache,插件脚本文件应命名为 apache.dll

  11. 我们的代理将开始收集数据,五分钟内用户即可在 Web 客户端中查看统计数据。成功添加插件后的后续步骤是什么?
注意

所有插件日志将记录在 [安装目录]\monitoring\logs\Details 下的 PluginLog.log 和 PluginRegisterLog.log 文件中

插件文件示例

using System;
using System.Collections.Generic;
using System.Text;
using Site24x7Plugin.Monitor;

namespace Plugin
{
public class test : IPlugins
{
public string DisplayName
{
get{ return "File system performance"; }
}
public string Version
{
get { return "1"; }
}
public string Heartbeat
{
get { return "True"; }
}
public object Units()
{
IDictionary<String, object> sample = new Dictionary<String, object>();
sample.Add("File Control Bytes Per Second", "Bytes/sec");
sample.Add("File Control Operations Per Second", "operations/sec");
sample.Add("File Data Operations Per Second", "Bytes/sec");
sample.Add("File Read Bytes Per Second", "Bytes/sec");
return sample;
}
public object DataCollect()
{
Random r = new Random();
IDictionary<String, object> sample = new Dictionary<String, object>();
sample.Add("File Control Bytes Per Second", 10);
sample.Add("File Control Operations Per Second", 4);
sample.Add("File Data Operations Per Second", 1.2);
sample.Add("File Read Bytes Per Second", 87);
return sample;
}
}
}

JSON 输出:

 {

"data":{"File Control Operations Per Second":4,"File Data Operations Per Second":1.2,"File Read Bytes Per Second":87,"File Control Bytes Per Second":10},

"units":{"File Control Operations Per Second":"operations/sec","File Data Operations Per Second":"Bytes/sec","File Read Bytes Per Second":"Bytes/sec","File Control Bytes Per Second":"Bytes/sec"},

"type":"Plugin.dll",

"version":"1",

"availability":"1"

}

数据在 Site24x7 Web 客户端中的显示方式:

故障排除提示

本文档对您有帮助吗?

您愿意帮助我们改进文档吗?请告诉我们哪些方面可以做得更好。


很抱歉本文档未能让您满意。我们希望了解可以从哪些方面改进您的体验。


感谢您抽出时间分享反馈。我们将利用您的反馈来改进在线帮助资源。

短链接已复制!