67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
using IniParser.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Threading;
|
|
|
|
namespace Barsik
|
|
{
|
|
/// <summary>
|
|
/// Monitors configured RAID array status via /proc/mdstat
|
|
/// Will fill registers info starting from baseAddress with
|
|
/// disk status (0 - fail, 1 - up) in following order:
|
|
/// raid #0 disk #0
|
|
/// raid #0 disk #1
|
|
/// ...
|
|
/// raid #0 disk #N
|
|
/// raid #1 disk #0
|
|
/// ...
|
|
/// etc
|
|
/// </summary>
|
|
class MDStatMonitoringUnit : BaseMonitoringUnit
|
|
{
|
|
public MDStatMonitoringUnit(SectionData config, RegistersContainer registers) : base(config, registers)
|
|
{
|
|
}
|
|
|
|
public override void Run()
|
|
{
|
|
while (true)
|
|
{
|
|
int currentAddress = baseAddress;
|
|
// the file is not so big, so read it completely
|
|
var lines = File.ReadAllLines("/proc/mdstat");
|
|
for (int i = 0; i < lines.Length;)
|
|
{
|
|
if (lines[i].StartsWith("md") && i < lines.Length - 1)
|
|
{
|
|
// we found device description
|
|
// second line of it is as follows:
|
|
// 2930264896 blocks super 1.0 [2/2] [UU]
|
|
// we need last characters in brackets []
|
|
currentAddress += FillDiskStatus(currentAddress, lines[i + 1]);
|
|
i += 2;
|
|
}
|
|
else i++;
|
|
}
|
|
Thread.Sleep(2000);
|
|
}
|
|
}
|
|
|
|
private int FillDiskStatus(int address, string v)
|
|
{
|
|
int last_pos = v.LastIndexOf(']');
|
|
int pos;
|
|
for (pos = last_pos; pos > 0 && v[pos] != '['; pos--) ;
|
|
if (v[pos] != '[') return 0;
|
|
for (int i = pos + 1; i < last_pos; i++)
|
|
{
|
|
if (v[i] == 'U') registers[address + i - (pos + 1)] = 1;
|
|
else registers[address + i - (pos + 1)] = 1;
|
|
}
|
|
return last_pos - pos - 1;
|
|
}
|
|
}
|
|
}
|