Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Jan 20, 2022
1 parent 27c514f commit 8b8dca6
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 191 deletions.
12 changes: 10 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@
"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/netcoreapp3.1/cv4pve-metrics-exporter.dll",
"args": [],
"program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter/bin/Debug/net6.0/cv4pve-metrics-exporter.dll",
"args": [
"--host",
"10.92.90.101" ,
"--username",
"root",
"--password",
"campanacor321!1",
"prometheus"
],
"cwd": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Metrics.Exporter",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
Expand Down
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cv4pve-metrics-export

[![License](https://img.shields.io/github/license/Corsinvest/cv4pve-metrics-exporter.svg)](LICENSE.md) [![AppVeyor branch](https://img.shields.io/appveyor/ci/franklupo/cv4pve-metrics-exporter/master.svg)](https://ci.appveyor.com/project/franklupo/cv4pve-metrics-exporter)
[![License](https://img.shields.io/github/license/Corsinvest/cv4pve-metrics-exporter.svg)](LICENSE.md)

```text
______ _ __
Expand Down
11 changes: 0 additions & 11 deletions appveyor.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<Version>1.3.1</Version>
<Version>1.4.0</Version>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
Expand All @@ -16,6 +16,7 @@
<PackageIcon>icon.png</PackageIcon>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>icon.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryType>Github</RepositoryType>
Expand All @@ -33,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="2.8.0" />
<PackageReference Include="prometheus-net" Version="3.6.0" />
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="3.1.3" />
<PackageReference Include="prometheus-net" Version="5.0.2" />
</ItemGroup>
</Project>
257 changes: 115 additions & 142 deletions src/Corsinvest.ProxmoxVE.Metrics.Exporter.Api/PrometheusExporter.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.2.0</Version>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.3.0</Version>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>cv4pve-metrics-exporter</AssemblyName>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
<Product>Corsinvest for Proxmox VE Metrics Exporter</Product>
<AssemblyTitle>Corsinvest for Proxmox VE Metrics Exporter</AssemblyTitle>
<Description>Corsinvest for Proxmox VE Metrics Exporter</Description>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<!-- Fix RedHat, Centos,Fedora -->
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />

<TrimmerRootAssembly Include="System.Net.WebClient" />

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

<!-- <ProjectReference Include="..\Corsinvest.ProxmoxVE.Metrics.Exporter.Api\Corsinvest.ProxmoxVE.Metrics.Exporter.Api.csproj" /> -->
<PackageReference Include="Corsinvest.ProxmoxVE.Metrics.Exporter.Api" Version="1.3.0" />
<PackageReference Include="Corsinvest.ProxmoxVE.Metrics.Exporter.Api" Version="1.4.0" />
</ItemGroup>
</Project>
46 changes: 29 additions & 17 deletions src/Corsinvest.ProxmoxVE.Metrics.Exporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

using System;
using Corsinvest.ProxmoxVE.Api.Extension.Helpers;
using Corsinvest.ProxmoxVE.Api.Shell.Helpers;
using Corsinvest.ProxmoxVE.Metrics.Exporter.Api;
using McMaster.Extensions.CommandLineUtils;
Expand All @@ -36,33 +37,44 @@ static void Main(string[] args)

cmd.OnExecute(() =>
{
var hostsAndPortHA = app.GetHost().Value();
var host = optHost.HasValue() ? optHost.Value() : PrometheusExporter.DEFAULT_HOST;
var username = app.GetUsername().Value();
var password = app.GetPasswordFromOption();
var port = optPort.HasValue() ? optPort.ParsedValue : PrometheusExporter.DEFAULT_PORT;
var url = optUrl.HasValue() ? optUrl.Value() : PrometheusExporter.DEFAULT_URL;
var prefix = optPrefix.HasValue() ? optPrefix.Value() : PrometheusExporter.DEFAULT_PREFIX;

var exporter = new PrometheusExporter(app.GetHost().Value(),
app.GetUsername().Value(),
app.GetPasswordFromOption(),
host,
port,
url,
prefix,
optNodeDiskInfo.HasValue());
var client = ClientHelper.GetClientFromHA(hostsAndPortHA, null);
if (client.Login(username, password))
{
var exporter = new PrometheusExporter(hostsAndPortHA,
username,
password,
host,
port,
url,
prefix,
optNodeDiskInfo.HasValue());

exporter.Start();
exporter.Start();

app.Out.WriteLine("Corsinvest for Proxmox VE");
app.Out.WriteLine($"Cluster: {app.GetHost().Value()} - User: {app.GetUsername().Value()}");
app.Out.WriteLine($"Exporter Prometheus: http://{host}:{port}/{url} - Prefix: {prefix}");
app.Out.WriteLine($"Export Node Disk Info: {optNodeDiskInfo.HasValue()}");
app.Out.WriteLine("Corsinvest for Proxmox VE");
app.Out.WriteLine($"Cluster: {app.GetHost().Value()} - User: {app.GetUsername().Value()}");
app.Out.WriteLine($"Exporter Prometheus: http://{host}:{port}/{url} - Prefix: {prefix}");
app.Out.WriteLine($"Export Node Disk Info: {optNodeDiskInfo.HasValue()}");

Console.ReadLine();
Console.ReadLine();

try { exporter.Stop(); }
catch { }
try { exporter.Stop(); }
catch { }

app.Out.WriteLine("End application");
app.Out.WriteLine("End application");
}
else
{
throw new ApplicationException("Error authentication!");
}
});
});

Expand Down
12 changes: 6 additions & 6 deletions src/Corsinvest.ProxmoxVE.Metrics.Exporter/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ Write-Output "
(Made in Italy)
=========================================================
== Build System
========================================================="
=========================================================
== Build System
========================================================="

$pathNet = "Bin\Release\netcoreapp3.1"
$pathNet = "Bin\Release\net6.0"

Remove-Item -Path ".\$pathNet" -Recurse -Force

$rids = @("linux-x64", "linux-arm", "linux-arm64", "osx-x64", "win-x86", "win-x64", "win-arm", "win-arm64")
foreach ($rid in $rids) {
dotnet publish -r $rid -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true
dotnet publish -r $rid -c Release /p:PublishSingleFile=true --self-contained /p:EnableCompressionInSingleFile=true
$path = "$pathNet\$rid\publish\"

$fileName = Get-ChildItem $path -Exclude *.pdb -name
$fileDest = "$pathNet\$fileName-$rid.zip"
$fileDest = "$pathNet\$fileName-$rid.zip"
Remove-Item $fileDest -ErrorAction SilentlyContinue
Compress-Archive $path\$fileName $fileDest
}

0 comments on commit 8b8dca6

Please sign in to comment.