Skip to content

Commit

Permalink
Proxmox VE 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed May 2, 2024
1 parent 24ee905 commit 470ae49
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 24 deletions.
19 changes: 10 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
// Usare IntelliSense per individuare gli attributi esistenti per il debug C#
// Usa il passaggio del mouse per la descrizione degli attributi esistenti
// Per ulteriori informazioni, visitare https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter/bin/Debug/net6.0/cv4pve-metrics-exporter.dll",
"args": [],
// Se i framework di destinazione sono stati modificati, assicurarsi di aggiornare il percorso del programma.
"program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter/bin/Debug/net8.0/cv4pve-metrics-exporter.dll",
"args": [
"@Parm.parm"
],
"cwd": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
// Per ulteriori informazioni sul campo 'console', vedere https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
"request": "attach"
}
]
}
13 changes: 6 additions & 7 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter/Corsinvest.ProxmoxVE.Metrics.Exporter.csproj",
"${workspaceFolder}/Corsinvest.ProxmoxVE.Metrics.Exporter.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -19,9 +19,9 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter/Corsinvest.ProxmoxVE.Metrics.Exporter.csproj",
"${workspaceFolder}/Corsinvest.ProxmoxVE.Metrics.Exporter.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
Expand All @@ -32,9 +32,8 @@
"args": [
"watch",
"run",
"${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter/Corsinvest.ProxmoxVE.Metrics.Exporter.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
"--project",
"${workspaceFolder}/Corsinvest.ProxmoxVE.Metrics.Exporter.sln"
],
"problemMatcher": "$msCompile"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<Version>1.4.2</Version>
<Version>1.5.0</Version>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
Expand Down Expand Up @@ -34,7 +34,7 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\..\cv4pve-api-dotnet\src\Corsinvest.ProxmoxVE.Api.Extension\Corsinvest.ProxmoxVE.Api.Extension.csproj" /> -->
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="7.3.7" />
<PackageReference Include="prometheus-net" Version="6.0.0" />
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="8.2.0" />
<PackageReference Include="prometheus-net" Version="8.2.1" />
</ItemGroup>
</Project>
186 changes: 186 additions & 0 deletions src/Corsinvest.ProxmoxVE.Metrics.Exporter.Api/InfluxDBExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
// /*
// * SPDX-License-Identifier: GPL-3.0-only
// * SPDX-FileCopyrightText: 2019 Copyright Corsinvest Srl
// */

// using System;
// using System.Collections.Generic;
// using System.Diagnostics;
// using System.IO;
// using System.Linq;
// using System.Threading.Tasks;
// using Corsinvest.ProxmoxVE.Api;
// using Corsinvest.ProxmoxVE.Api.Extension;
// using Corsinvest.ProxmoxVE.Api.Extension.Utils;
// using Corsinvest.ProxmoxVE.Api.Shared.Models.Access;
// using Corsinvest.ProxmoxVE.Api.Shared.Models.Cluster;
// using Corsinvest.ProxmoxVE.Api.Shared.Models.Node;
// using Corsinvest.ProxmoxVE.Api.Shared.Models.Vm;
// using Corsinvest.ProxmoxVE.Api.Shared.Utils;
// using InfluxDB.Collector;
// using JsonSubTypes;
// using Microsoft.Extensions.Logging;
// using static Corsinvest.ProxmoxVE.Api.PveClient.PveAccess;

// namespace Corsinvest.ProxmoxVE.Metrics.Exporter.Api;

// /// <summary>
// /// InfluxDB Exporter
// /// </summary>
// public class InfluxDBExporter
// {
// private readonly string _pveHostsAndPortHA;
// private readonly string _pveUsername;
// private readonly string _pvePassword;
// private readonly string _pveApiToken;
// private readonly ILoggerFactory _loggerFactory;
// private readonly string _url;
// private readonly string _database;

// /// <summary>
// /// Constructor
// /// </summary>
// /// <param name="pveHostsAndPortHA"></param>
// /// <param name="pveUsername"></param>
// /// <param name="pvePassword"></param>
// /// <param name="pveApiToken"></param>
// /// <param name="loggerFactory"></param>
// /// <param name="url"></param>
// /// <param name="database"></param>
// public InfluxDBExporter(string pveHostsAndPortHA,
// string pveUsername,
// string pvePassword,
// string pveApiToken,
// ILoggerFactory loggerFactory,
// string url,
// string database)
// {
// _pveHostsAndPortHA = pveHostsAndPortHA;
// _pveUsername = pveUsername;
// _pvePassword = pvePassword;
// _pveApiToken = pveApiToken;
// _loggerFactory = loggerFactory;
// _url = url;
// _database = database;
// }

// /// <summary>
// /// Send async data
// /// </summary>
// /// <returns></returns>
// public async Task SendAsync()
// {
// var stopwatch = new Stopwatch();
// stopwatch.Start();

// var client = ClientHelper.GetClientFromHA(_pveHostsAndPortHA);
// client.LoggerFactory = _loggerFactory;
// if (string.IsNullOrWhiteSpace(_pveApiToken))
// {
// await client.Login(_pveUsername, _pvePassword);
// }
// //await CollectAsync2(client);

// stopwatch.Stop();
// }

// private async Task CollectAsync1x(PveClient client)
// {
// var collector = new CollectorConfiguration()
// // .Tag.With("host", Environment.GetEnvironmentVariable("COMPUTERNAME"))
// // .Tag.With("os", Environment.GetEnvironmentVariable("OS"))
// //.Tag.With("process", Path.GetFileName(process.MainModule.FileName))
// .Batch.AtInterval(TimeSpan.FromSeconds(10))
// .WriteTo.InfluxDB(_url, _database)
// .CreateCollector();

// var resources = await client.Cluster.Resources.Get();

// foreach (var node in await client.Nodes.Get())
// {
// collector.Write("system", new Dictionary<string, object>()
// {
// {"object", "nodes"},
// {"host", node.Node},
// {"uptime", node.Uptime},
// {"status", node.Status},
// {"cpu", node.CpuUsagePercentage},
// {"cpus", node.CpuSize},
// {"mem", node.MemoryUsage},
// {"maxmem", node.MemorySize},
// });

// //storages
// foreach (var storage in await client.Nodes[node.Node].Storage.Get())
// {
// var data = new Dictionary<string, object>
// {
// { "active", storage.Active },
// { "avail", storage.Available },
// { "content", storage.Content },
// { "enabled", storage.Enabled },
// { "host", storage.Storage },
// { "nodename", node.Node },
// { "shared", storage.Shared },
// { "total", storage.Size },
// { "used", storage.Used }
// };

// if (!string.IsNullOrWhiteSpace(storage.Type)) { data.Add("type", storage.Type); }

// collector.Write("system", data);
// }

// //qemu/lxc
// foreach (var vm in resources.Where(a => a.ResourceType == ClusterResourceType.Vm))
// {
// VmBaseStatusCurrent status = vm.VmType switch
// {
// VmType.Lxc => await client.Nodes[node.Node].Lxc[vm.VmId].Status.Current.Get(),
// VmType.Qemu => await client.Nodes[node.Node].Qemu[vm.VmId].Status.Current.Get(),
// _ => throw new ArgumentOutOfRangeException(),
// };

// var data = new Dictionary<string, object>
// {
// {"vmid", status.VmId},
// {"host", node.Node},
// {"uptime", status.Uptime},
// {"status", status.Status},
// {"cpu", status.CpuUsagePercentage},
// {"cpus", status.CpuSize},
// {"diskread", status.DiskRead},
// {"diskwrite", status.DiskWrite},
// {"mem", status.MemoryUsage},
// {"maxmem", status.MemorySize},
// {"disk", status.DiskUsage},
// {"maxdisk", status.DiskSize},
// {"netin", status.NetIn},
// {"netout", status.NetOut},
// {"pid", status.Pid},
// {"lock", vm.IsLocked ? 1:0},
// };

// if (vm.VmType == VmType.Qemu)
// {
// var qmStatus = (VmQemuStatusCurrent)status;
// data.Add("balloon", qmStatus.Balloon);
// data.Add("qmstatus", qmStatus.Qmpstatus);
// data.Add("running-qemu", qmStatus.RunningQemu);
// data.Add("running-machine", qmStatus.RunningMachine);

// //uèdate data from agent
// try
// {
// var aa = await client.Nodes[node.Node].Qemu[vm.VmId].Agent.GetFsinfo.Get();
// data["disk"] = aa.Result.Select(a => a.UsedBytes).Sum();
// data["maxdisk"] = aa.Result.Select(a => a.TotalBytes).Sum();
// }
// catch { }
// }

// collector.Write("system", data);
// }
// }
// }
// }
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.4.1</Version>
<TargetFramework>net6.0</TargetFramework>
<Version>1.5.0</Version>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>cv4pve-metrics-exporter</AssemblyName>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
Expand All @@ -18,9 +18,8 @@

<ItemGroup>
<!-- <ProjectReference Include="..\..\..\cv4pve-api-dotnet\src\Corsinvest.ProxmoxVE.Api.Shell\Corsinvest.ProxmoxVE.Api.Shell.csproj" /> -->
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Shell" Version="7.3.7" />
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Shell" Version="8.2.0" />

<!-- <ProjectReference Include="..\Corsinvest.ProxmoxVE.Metrics.Exporter.Api\Corsinvest.ProxmoxVE.Metrics.Exporter.Api.csproj" /> -->
<PackageReference Include="Corsinvest.ProxmoxVE.Metrics.Exporter.Api" Version="1.4.2" />
<ProjectReference Include="..\Corsinvest.ProxmoxVE.Metrics.Exporter.Api\Corsinvest.ProxmoxVE.Metrics.Exporter.Api.csproj" />
</ItemGroup>
</Project>

0 comments on commit 470ae49

Please sign in to comment.