1
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
dockerfile: Dockerfile
|
||||
container_name: nas_robot
|
||||
restart: always
|
||||
networks:
|
||||
- all_in
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
volumes:
|
||||
@@ -19,10 +21,16 @@
|
||||
image: beevelop/nginx-basic-auth:v2023.10.1
|
||||
container_name: nas_robot_proxy
|
||||
restart: always
|
||||
networks:
|
||||
- all_in
|
||||
ports:
|
||||
- 14902:80 # 开放端口
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
- HTPASSWD=suncheng:$$apr1$$2QX32QHP$$HIGAbCuTt8jxdc4uDzNLI1
|
||||
- FORWARD_PORT=8080
|
||||
- FORWARD_HOST=nas_robot
|
||||
- FORWARD_HOST=nas_robot
|
||||
|
||||
networks:
|
||||
all_in:
|
||||
external: true
|
||||
@@ -10,6 +10,8 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
|
||||
<PackageReference Include="FluentScheduler" Version="5.5.1"/>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="InfluxDB.Client" Version="4.18.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using FluentScheduler;
|
||||
using InfluxDB.Client;
|
||||
using InfluxDB.Client.Api.Domain;
|
||||
using InfluxDB.Client.Writes;
|
||||
using Interface.Jobs;
|
||||
|
||||
namespace Service.Jobs;
|
||||
@@ -28,6 +31,9 @@ public class DiskMonitorRegistry : Registry, IDiskMonitorRegistry
|
||||
process.WaitForExit();
|
||||
|
||||
Console.WriteLine(FormatResult(result));
|
||||
|
||||
|
||||
WriteToInfluxDB(result);
|
||||
}
|
||||
|
||||
private string FormatResult(string result)
|
||||
@@ -40,10 +46,45 @@ public class DiskMonitorRegistry : Registry, IDiskMonitorRegistry
|
||||
|
||||
if (line.Contains("/host/wd/"))
|
||||
{
|
||||
sb.AppendLine($"{cols[5].Substring("/host".Length)}, {cols[1]}, {cols[4].TrimEnd('%')}, {cols[3]}");
|
||||
sb.AppendLine($"{cols[5].Substring("/host".Length)},{cols[1]},{cols[4].TrimEnd('%')},{cols[3]}");
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void WriteToInfluxDB(string result)
|
||||
{
|
||||
/*
|
||||
/wd/apps,916G,53,410G
|
||||
/wd/volc,3.6T,69,1.1T
|
||||
/wd/volb,3.6T,60,1.4T
|
||||
/wd/vola,3.6T,88,440G
|
||||
*/
|
||||
|
||||
var lines = result.Split("\n");
|
||||
|
||||
using var client = new InfluxDBClient("http://influxdb:8086", "BD4A71llb9_XbCA5mmKDbc_yTYwadPPLwyk4nAQ0l_yR_WJmw_-dMOWIs0KlS7-pZtHot_HrejY5GcOohKElmA==");
|
||||
using var writeApi = client.GetWriteApi();
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
var cols = line.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
var path = cols[0];
|
||||
var totalSize = cols[1];
|
||||
var usedPercent = cols[2];
|
||||
var available = cols[3];
|
||||
|
||||
var point = PointData
|
||||
.Measurement("disk_usage")
|
||||
.Tag("path", path)
|
||||
.Field("total_size", totalSize)
|
||||
.Field("used_percent", double.Parse(usedPercent))
|
||||
.Field("available", available)
|
||||
.Timestamp(DateTime.UtcNow, WritePrecision.Ns);
|
||||
|
||||
writeApi.WritePoint(point, "def-bucket", "def-org");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user