Логирование, багфиксы, добавил мониторин /proc/mdstat. Юнит для systemd

This commit is contained in:
ftc
2020-08-30 09:15:43 +03:00
parent 092cba1cee
commit bbb0f9c63e
10 changed files with 241 additions and 79 deletions
+5 -59
View File
@@ -1,8 +1,5 @@
using IniParser.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace Barsik
{
@@ -31,66 +28,15 @@ namespace Barsik
{
return new SensorsMonitoringUnit(config, registers);
}
else
else if (type == "MDStat")
{
return new MDStatMonitoringUnit(config, registers);
}
else
{
Console.WriteLine("Unknown unit type " + type);
return null;
}
}
}
class SensorsMonitoringUnit : BaseMonitoringUnit
{
public SensorsMonitoringUnit(SectionData config, RegistersContainer registers) : base(config, registers)
{
}
public override void Run()
{
var stringToFind = config.Keys["String"];
var multiplier = float.Parse(config.Keys["Multiplier"]);
while (true)
{
System.Diagnostics.ProcessStartInfo procStartInfo = new System.Diagnostics.ProcessStartInfo("sensors");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
while (!proc.HasExited)
{
Thread.Sleep(100);
}
string result = proc.StandardOutput.ReadToEnd();
var lines = result.Split('\n');
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Contains(stringToFind))
{
var value = ExtractValue(lines[i]);
registers[baseAddress] = (int)(value * multiplier);
}
}
}
}
bool Good(char c)
{
if (c == '-' || c == '+' || c == '.') return true;
if (c >= '0' && c <= '9') return true;
return false;
}
private float ExtractValue(string v)
{
int pos = 0;
while (pos < v.Length && !Good(v[pos])) pos++;
int pos2 = pos;
while (pos2 < v.Length && Good(v[pos2])) pos2++;
float res = 0;
float.TryParse(v.Substring(pos, pos2 - pos), out res);
return res;
}
}
}