|
@@ -9,6 +9,8 @@ using VeloeMonitorDataCollector.DatabaseConnectors;
|
|
|
using VeloeMonitorDataCollector.Models;
|
|
|
using Serilog;
|
|
|
using VeloeMonitorDataCollector.Dependencies;
|
|
|
+using System.Globalization;
|
|
|
+using System.Net;
|
|
|
|
|
|
namespace VeloeMonitorDataCollector
|
|
|
{
|
|
@@ -248,10 +250,10 @@ namespace VeloeMonitorDataCollector
|
|
|
interval = 1;
|
|
|
}
|
|
|
|
|
|
- BuildUpdater(section.Path,
|
|
|
- section["Ip"],
|
|
|
- Int32.Parse(section["Port"]),
|
|
|
- section["Type"], interval);
|
|
|
+ BuildUpdater(section.Path,
|
|
|
+ section["Ip"],
|
|
|
+ Int32.Parse(section["Port"]),
|
|
|
+ section["Type"], interval);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -312,27 +314,6 @@ namespace VeloeMonitorDataCollector
|
|
|
|
|
|
StreamWriter sw = File.AppendText("sysinfo.txt");
|
|
|
|
|
|
- if (OperatingSystem.IsLinux())
|
|
|
- {
|
|
|
- var cpuLine = File
|
|
|
- .ReadAllLines("/proc/stat")
|
|
|
- .First()
|
|
|
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
|
|
- .Skip(1)
|
|
|
- .Select(float.Parse)
|
|
|
- .ToArray();
|
|
|
-
|
|
|
- var idle = cpuLine[3];
|
|
|
- var total = cpuLine.Sum();
|
|
|
-
|
|
|
- var percent = 100 * (1.0f - (idle - prevIdle) / (total - prevTotal));
|
|
|
- sw.WriteLine("CPU Load: {0}", percent);
|
|
|
-
|
|
|
- prevIdle = idle;
|
|
|
- prevTotal = total;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
foreach (var hardware in _computerHardware.Hardware)
|
|
|
{
|
|
|
hardware.Update();
|
|
@@ -381,36 +362,13 @@ namespace VeloeMonitorDataCollector
|
|
|
if (_computerHardware is null)
|
|
|
return output;
|
|
|
|
|
|
- if (OperatingSystem.IsLinux())
|
|
|
- {
|
|
|
- var cpuLine = File
|
|
|
- .ReadAllLines("/proc/stat")
|
|
|
- .First()
|
|
|
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
|
|
|
- .Skip(1)
|
|
|
- .Select(float.Parse)
|
|
|
- .ToArray();
|
|
|
-
|
|
|
- var idle = cpuLine[3];
|
|
|
- var total = cpuLine.Sum();
|
|
|
-
|
|
|
- var percent = 100 * (1.0f - (idle - prevIdle) / (total - prevTotal));
|
|
|
- //for the first calc number can be inf or nan
|
|
|
- if (float.IsFinite(percent))
|
|
|
- output.Add("cpuload", percent);
|
|
|
-
|
|
|
- prevIdle = idle;
|
|
|
- prevTotal = total;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
foreach (var hardware in _computerHardware.Hardware)
|
|
|
{
|
|
|
hardware.Update();
|
|
|
//foreach (var sensor in hardware.Sensors)
|
|
|
// _logger.Warning("{0}: {1}", sensor.Name, sensor.Value);
|
|
|
|
|
|
- if (hardware.HardwareType is HardwareType.Cpu && OperatingSystem.IsWindows())
|
|
|
+ if (hardware.HardwareType is HardwareType.Cpu)
|
|
|
if (_deviceLoadSensorIndex["cpuload"] is not -1)
|
|
|
output.Add("cpuload", hardware.Sensors[_deviceLoadSensorIndex["cpuload"]].Value.GetValueOrDefault());
|
|
|
else
|
|
@@ -541,25 +499,7 @@ namespace VeloeMonitorDataCollector
|
|
|
try
|
|
|
{
|
|
|
Gs3Status server = new Gs3Status(ip, port);
|
|
|
- /*
|
|
|
- bool dataIsNull = true;
|
|
|
-
|
|
|
- while (dataIsNull && !_token.IsCancellationRequested)
|
|
|
- {
|
|
|
- var data = server.GetStatus();
|
|
|
-
|
|
|
- if (data is null)
|
|
|
- continue;
|
|
|
|
|
|
- if (_sendToDb is null)
|
|
|
- dataIsNull = false;
|
|
|
-
|
|
|
- foreach(var dbController in _sendToDb)
|
|
|
- {
|
|
|
- dbController.CheckGamespy3(data, name);
|
|
|
- }
|
|
|
- }
|
|
|
- */
|
|
|
while (!_token.IsCancellationRequested)
|
|
|
{
|
|
|
try
|
|
@@ -629,6 +569,57 @@ namespace VeloeMonitorDataCollector
|
|
|
}
|
|
|
}, _token));
|
|
|
|
|
|
+ break;
|
|
|
+ case "Url":
|
|
|
+ _updaterTasks.Add(name, new Task(async () => {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ while (!_token.IsCancellationRequested)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ await Task.Delay(TimeSpan.FromSeconds(interval));
|
|
|
+
|
|
|
+ _logger.Debug("Try to get http response");
|
|
|
+ HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ip);
|
|
|
+ request.Headers.Add("Accept-Encoding", "gzip, deflate");
|
|
|
+ request.Headers.Add("Accept-Language", "en-US,en;q=0.5");
|
|
|
+ request.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
|
|
+ request.AllowAutoRedirect = true; // find out if this site is up and don't follow a redirector
|
|
|
+ request.Method = "HEAD";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
+
|
|
|
+ if (response is null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (response.StatusCode != HttpStatusCode.OK)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (_sendToDb is null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ foreach (var dbController in _sendToDb)
|
|
|
+ {
|
|
|
+ dbController.SendUrl(response, name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex) {
|
|
|
+ _logger.Warning("{0} {1}", ip, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (WebException ex)
|
|
|
+ {
|
|
|
+ _logger.Debug("{0} {1}", ip, ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (System.Net.Sockets.SocketException ex)
|
|
|
+ {
|
|
|
+ _logger.Debug("{0} {1}", ip, ex.Message);
|
|
|
+ }
|
|
|
+ }, _token));
|
|
|
break;
|
|
|
}
|
|
|
}
|