-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSdCardUsage.cs
47 lines (42 loc) · 1.41 KB
/
SdCardUsage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace SystemUsage
{
public class SdCard
{
public double Total;
public double Used;
public double Free;
}
class SdCardUsage
{
public SdCard GetSdCard()
{
var output = "";
var info = new ProcessStartInfo("df -Bm");
info.FileName = "/bin/bash";
info.Arguments = "-c \"df -Bm\"";
info.RedirectStandardOutput = true;
using (var process = Process.Start(info))
{
output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
}
var lines = output.Split("\n").ToList();
lines.RemoveAt(0);
lines.RemoveAt(lines.Count - 1);
var metrics = new SdCard();
foreach (var item in lines)
{
metrics.Total += Convert.ToDouble(item.Split(" ", StringSplitOptions.RemoveEmptyEntries)[1].Replace("M", ""));
metrics.Used += Convert.ToDouble(item.Split(" ", StringSplitOptions.RemoveEmptyEntries)[2].Replace("M", ""));
metrics.Free += Convert.ToDouble(item.Split(" ", StringSplitOptions.RemoveEmptyEntries)[3].Replace("M", ""));
}
return metrics;
}
}
}