采用Opserver来监控你的ASP.NET项目系列(3、监控你的服务器状态)

以前有过2篇关于如何监控ASP.NET core项目的文章,有兴趣的也能够看看.html

 

今天咱们主要来介绍一下,如何使用Opserver监控咱们的服务器状态.node

Opserver的功能其实很强大,他能够用于链接任何支持Bosun, Orion, or direct WMI监控数据。sql

大概效果以下:docker

 

 

正文

1.经过Windows自带的WMI监控服务器

首先,咱们找到相关的配置文件,修改配置文件的名称 DashboardSettings.json.example 为 DashboardSettings.jsonjson

而后修改DashboardSettings.json设置链接地址 providers,这里咱们以WMI为例,以下:windows

{
  "providers": {
    "wmi": {
      "nodes": [ "USER-20170316IW" ], // List of nodes to monitor
      "staticDataTimeoutSeconds": 300, // (Optional) How long to cache static data (node name, hardware, etc.) - defaults to 5 minutes
      "dynamicDataTimeoutSeconds": 5, // (Optional) How long to cache dynamic data (utilizations, etc.) - defaults to 30 seconds
      "historyHours": 2, // (Optional) How long to retain data (in memory) - defaults to 24 hours
      "username": "Administrator"
    }
}

 

解释一下参数说明:缓存

  • nodes 能够有多台,能够填 服务器名称 或是 IP地址
  • StaticDataTimeoutSeconds 缓存静态数据(节点名称、硬件等)要多长时间-默认为5分钟
  • DynamicDataTimeoutSeconds 缓存动态数据(CPU,加载时间等)要多长时间-默认为30秒
  • HistoryHours 保留记录的时长,默认为 2 小时
  • Username 远程服务器的帐户名
  • Password 远程服务器的密码(PS,我这里由于链接的是本机 因此就不须要了.)

设置完链接以后,咱们能够设置咱们的警惕值,以下:服务器

設定警惕值ide

key 說明
cpuWarningPercent cpu 用量警惕(黄色)
cpuCriticalPercent cpu 用量危险(红色)
memoryWarningPercent 内存用量警惕(黄色)
memoryCriticalPercent 内存用量危险(红色)
diskWarningPercent 磁盘空间 用量警惕(黄色)
diskCriticalPercent 磁盘空间 用量危险(红色)

JSON配置直接添加在providers节点下便可.网站

以下:

{
"providers":{
 "cpuWarningPercent": 50,
  "cpuCriticalPercent": 60,
  "memoryWarningPercent": 90,
  "memoryCriticalPercent": 95, 
  "diskWarningPercent": 85,
  "diskCriticalPercent": 95
}
}

多台服务器的状况下,服务器的配置不必定相同,因此须要根据服务器配置 单独设置报警值,咱们能够添加categories节点,并配置以下:

"categories": [
    {
     "name": "第一台", // Name for this group of servers
     "pattern": "-sql",
     "cpuWarningPercent": 20, 
     "cpuCriticalPercent": 60,
      "memoryWarningPercent": 98, 
     "memoryCriticalPercent": 99.2
 },
     "name": "第二台", 
     "pattern": "-sql", 
     "cpuWarningPercent": 20, 
     "cpuCriticalPercent": 60,
      "memoryWarningPercent": 98,
     "memoryCriticalPercent": 99.2
 }
]

 

这样,咱们就完成了咱们使用WMI采集信息,并展现在OpServer上的所有工做.

固然,官方推荐的是使用bosun +scollector+OpServer的形式来采集和显示

因此,咱们下面就来说讲(不过我本人并无实践..资源实在有限)

2.经过bosun +scollector监控服务器

一、bosun 快速安装(固然,也有不使用Docker的..不过说实话..太复杂了..也许就是由于太复杂了,才放到容器里简化安装了吧)

  •      安装docker

      ..具体我就不说了,直接移步安装步骤官网:https://docs.docker.com/engine/installation/

  •      在docker中安装bosun

     使用命令“docker run -d -p 4242:4242 -p 8070:8070 stackexchange/bosun”,安装bosun,文件大概200多M,等待完成便可。

  •      检查是否安装成功

     访问网站http://docker-server-ip:8070,显示bosun界面,即安装成功。此时,本机监控数据已经被采集,能够查看相应数据。

 

二、服务器agent数据采集器(scollector)

   能够到 http://bosun.org/scollector/   下载scollector.

    以windows 为例,下载“scollector-windows-amd64.exe"后,用管理员身份运行”cmd.exe"。cd 到文件目录,在命令窗口输入“scollector-windows-amd64 -h  docker-server-ip:8070"

    显示以下信息,表示与bosun服务创建链接。命令以下:

C:\>scollector-windows-amd64 -h 192.168.1.101:8070
2016/11/18 15:59:19 info: main.go:213: OpenTSDB host: http://192.168.1.101:8070

而后可在bosun items 界面看到此服务器信息。

写在最后

至此咱们就完成了监控服务器的全部操做.喜欢的请关注一下,~以为不错的能够点个推荐,固然也欢迎大神批评指正.~