Opserver 初探一《Opserver的搭建》

Opserver 是Stack Overflow 的开源监控产品。stackoverflow网站是基于asp.net开发的,具体采用的软硬件配置可以查看《StackOverflow 这么大,究竟用在什么硬件设备》。我们可以了解到stackoverflow的大致运行环境:

数据库:sql server

缓存服务器:redis

web服务器:windows server/IIS

搜索服务器:ElasticSearch

标签服务器:未知

负载均衡:HAProxy

 

so, opserver 直接提供的可监控服务是sql server ,redis,ElasticSearch,HAProxy,exception等。

 

1、Opserver 监控搭建

     可以到https://github.com/opserver/Opserver,下载Opserver 源码,里面包含 Opserver监控网站和Opserver.Core两个项目。

     直接编译启动,会报没有设置SecuritySettings.config错误。查看web.config ,默认指定了文件在Config\SecuritySettings.config

<SecuritySettings configSource="Config\SecuritySettings.config" />

     监控配置设置在“Config\”下的json文件。
   

    找到config文件夹,我们可以看到多个以"*.example"结尾的文件,如:

CloudFlareSettings.json.example      //CloudFlare监控配置
DashboardSettings.json.example       //仪表盘配置
ElasticSettings.json.example         //ElasticSearch监控配置
ExceptionsSettings.json.example //Exceptions异常数据监控配置 HAProxySettings.json.example //HAProxy监控配置 JiraSettings.json.example //Jira问题配置 PagerDutySettings.json.example // PollingSettings.json.example // RedisSettings.json.example //Redis监控配置 SecuritySettings.config.example //Security安全设置 SQLSettings.json.example //sql server配置


查看github opserver介绍和SecuritySettings.config.example,”SecuritySettings.config“为opserver网站的安全配置,example中启用的默认配置为AD("ad")认证登入,其他还有“alladmin",view all。因环境中没有AD服务,这里使用"alladmin"配置登录opserver网站(即所有人都已管理员身份登录)。

<SecuritySettings provider="alladmin" />

启动网站,用户名和密码可输也可以不输,点击登录,可以直接进入网站。此时网站显示可以没有配置任何监控项。

Uh no! No Configuration found! 

No configuration data was found. This means no Opserver sections are configured/enabled or you have no roles assigned to you. 

See the Readme.txt in /config and *.example files for examples of a basic JSON configuration...or you can implement your own provider to get settings from anywhere. 

If you are using AD authentication, set the ViewGroups or AdminGroups settings in the web.config or in the section-specific configuration. 

You can also browse to /about to see how you have been authenticated and what monitors have been enabled. 

 

2、配置redis监控

从redissetting.json.example上看,配置分“allservers",和”servers"节点,allservers是servers节点的子集,即可以认为allservers等同于是servers的某一个子节点。通过阅读代码Opserver.Core项目Setting文件夹下的RedisSettings.cs文件,确定了这一点,allservers是单个Server,servers是List<server>。redis监控数据实例的加载可以查看Opserver.Core项目data/Redis文件夹下的RedisModule.cs

   private static List<RedisConnectionInfo> LoadRedisConnections()
        {
            var result = new List<RedisConnectionInfo>();
            var defaultServerInstances = Current.Settings.Redis.Defaults.Instances;
            var allServerInstances = Current.Settings.Redis.AllServers.Instances;

            foreach (var s in Current.Settings.Redis.Servers)
            {
                var count = result.Count;
                // Add instances that belong to any servers
                allServerInstances?.ForEach(gi => result.Add(new RedisConnectionInfo(s.Name, gi)));

                // Add instances defined on this server
                if (s.Instances.Any())
                    s.Instances.ForEach(i => result.Add(new RedisConnectionInfo(s.Name, i)));

                // If we have no instances added at this point, defaults it is!
                if (defaultServerInstances != null && count == result.Count)
                    defaultServerInstances.ForEach(gi => result.Add(new RedisConnectionInfo(s.Name, gi)));
            }
            return result;
        }

 从中可以看出,allservers和default下的实例配置,会影响servers下的配置,allservers和default的实例被添加到servers的各个节点,可以理解allservers和default的配置为通用配置,另外如果allservers,servers下有实例 ,default下实例不起作用。如果要自定义实例加载,可以修改这段代码。实际配置中我们只要配置servers就可以了。如:

{
    "Servers": [
       
        {
          "name": "192.168.1.100",
          "instances": [ { "name": "is not cluster Redis", "port": "6379" } ]
        },

        {
          "name": "192.168.1.101",
          "instances": [
          {
              "name": "cluster master",
              "port": "6379",
              "password": "*******"
           }]
        },
       {
          "name": "192.168.1.102",
          "instances": [
          {
              "name": "cluster slave",
              "port": "6379",
              "password": "*******"
           }]
        }
    ]
}


3、SQL SERVER监控

 从SQLSettings.json.example文件中,可以看出sql 配置比较简单,主要分集群cluster和单实例instance配置,注意所有的name都指网络机器名,可以用IP代替。具体的配置细节可以查看Opserver.Core项目下setting文件夹的,sqlsetting.cs文件。示例:

{
    "defaultConnectionString": "Data Source=$ServerName$;User ID=sa;Password=*****;Initial Catalog=master;",
    "clusters": [
        {
            "name": "192.168.1.120",
            "refreshIntervalSeconds": 20,
            "nodes": [
                { "name": "192.168.1.121" },
                { "name": "192.168.1.122" },
                { "name": "192.168.1.123" },
            ]
        }
    ],
    "instances": [
        { 
            "name": "192.168.1.131",
            "connectionString":"Data Source=192.168.1.131;User ID=sa;Password=*********;Initial Catalog=master;"
        }
    ]
}

 注意:defaultConnectionString 默认情况下节点不能删除,值可以为空。集群和实例必须存在其一,不然SQL监控页面不呈现。

posted @ 2016-11-16 15:35  hobinly  阅读(4929)  评论(1编辑  收藏  举报