diff --git a/ATxDiagnostics/ATxDiagnostics.cs b/ATxDiagnostics/ATxDiagnostics.cs new file mode 100644 index 0000000000000000000000000000000000000000..f3b80fb81e11a53514f5fe5ee46bd04fcc0914d3 --- /dev/null +++ b/ATxDiagnostics/ATxDiagnostics.cs @@ -0,0 +1,96 @@ +using System; +using System.Diagnostics; +using System.Management; +using System.Reflection; +using ATxCommon; +using ATxCommon.Monitoring; +using NLog; +using NLog.Config; +using NLog.Targets; + +namespace ATxDiagnostics +{ + class ATxDiagnostics + { + private static readonly Logger Log = LogManager.GetCurrentClassLogger(); + + static void Main(string[] args) { + var loglevel = LogLevel.Debug; + if (args.Length > 0 && args[0] == "trace") { + loglevel = LogLevel.Trace; + } + var logConfig = new LoggingConfiguration(); + var logTargetConsole = new ConsoleTarget { + Name = "console", + Header = "AutoTx Diagnostics", + Layout = @"${time} [${level}] ${message}", + }; + logConfig.AddTarget(logTargetConsole); + var logRuleConsole = new LoggingRule("*", loglevel, logTargetConsole); + logConfig.LoggingRules.Add(logRuleConsole); + LogManager.Configuration = logConfig; + + var commonAssembly = Assembly.GetAssembly(typeof(ATxCommon.Monitoring.Cpu)); + var commonVersionInfo = FileVersionInfo.GetVersionInfo(commonAssembly.Location); + Log.Info("ATxCommon library version: {0}", commonVersionInfo.ProductVersion); + + Log.Debug("Free space on drive [C:]: " + Conv.BytesToString(SystemChecks.GetFreeDriveSpace("C:"))); + + Log.Info("Checking CPU load using ATxCommon.Monitoring..."); + var cpu = new Cpu { + Interval = 250, + Limit = 25, + Probation = 4, // 4 * 250 ms = 1 second + Enabled = true + }; + System.Threading.Thread.Sleep(10000); + cpu.Enabled = false; + Log.Info("Finished checking CPU load using ATxCommon.Monitoring.\n"); + + Log.Info("Checking CPU load using WMI..."); + for (int i = 0; i < 10; i++) { + WmiQueryCpuLoad(); + System.Threading.Thread.Sleep(1000); + } + Log.Info("Finished checking CPU load using WMI.\n"); + } + + private static int WmiQueryCpuLoad() { + Log.Trace("Querying WMI for CPU load..."); + var watch = Stopwatch.StartNew(); + var queryString = "SELECT Name, PercentProcessorTime " + + "FROM Win32_PerfFormattedData_PerfOS_Processor"; + var opts = new EnumerationOptions { + Timeout = new TimeSpan(0, 0, 10), + ReturnImmediately = false, + }; + var searcher = new ManagementObjectSearcher("", queryString, opts); + Int32 usageInt32 = -1; + + var managementObjects = searcher.Get(); + if (managementObjects.Count > 0) { + Log.Trace("WMI query returned {0} objects.", managementObjects.Count); + foreach (var mo in managementObjects) { + var obj = (ManagementObject)mo; + var usage = obj["PercentProcessorTime"]; + var name = obj["Name"]; + + usageInt32 = Convert.ToInt32(usage); + Log.Debug("CPU usage {1}: {0}", usageInt32, name); + + } + } else { + Log.Error("No objects returned from WMI!"); + } + + managementObjects.Dispose(); + searcher.Dispose(); + + watch.Stop(); + Log.Trace("WMI query took {0} ms.", watch.ElapsedMilliseconds); + + return usageInt32; + } + + } +} diff --git a/ATxDiagnostics/ATxDiagnostics.csproj b/ATxDiagnostics/ATxDiagnostics.csproj new file mode 100644 index 0000000000000000000000000000000000000000..140cd0fd36f439cc19e9b0d5d4a2c510323d2893 --- /dev/null +++ b/ATxDiagnostics/ATxDiagnostics.csproj @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{1FDA9634-87C9-4C25-AD12-BF79DA61D44D}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>ATxDiagnostics</RootNamespace> + <AssemblyName>AutoTxDiagnostics</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <TargetFrameworkProfile /> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants> + </DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> + <HintPath>..\packages\NLog.4.3.11\lib\net45\NLog.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + </ItemGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Management" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="ATxDiagnostics.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\ATxCommon\ATxCommon.csproj"> + <Project>{166D65D5-EE10-4364-8AA3-4D86BA5CE244}</Project> + <Name>ATxCommon</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <PropertyGroup> + <PreBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Prepare-Build.ps1 -SolutionDir $(SolutionDir) -ConfigurationName $(ConfigurationName)</PreBuildEvent> + </PropertyGroup> +</Project> \ No newline at end of file diff --git a/ATxDiagnostics/App.config b/ATxDiagnostics/App.config new file mode 100644 index 0000000000000000000000000000000000000000..d1428ad712d72a50520dab5091ddcb5ea2b5f3e6 --- /dev/null +++ b/ATxDiagnostics/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/> + </startup> +</configuration> diff --git a/ATxDiagnostics/Properties/AssemblyInfo.cs b/ATxDiagnostics/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000000000000000000000000000000000..31539f5897346cc8b639a8421e160b9ef839da4c --- /dev/null +++ b/ATxDiagnostics/Properties/AssemblyInfo.cs @@ -0,0 +1,44 @@ +using System.Reflection; +using System.Runtime.InteropServices; +using ATxCommon; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("AutoTx Diagnostics")] +[assembly: AssemblyDescription("AutoTx Command Line Diagnostics Tool")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("IMCF, Biozentrum, University of Basel")] +[assembly: AssemblyProduct("AutoTx")] +[assembly: AssemblyCopyright("© University of Basel 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1fda9634-87c9-4c25-ad12-bf79da61d44d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion(BuildDetails.GitMajor + "." + + BuildDetails.GitMinor + "." + + BuildDetails.GitPatch + ".0")] +[assembly: AssemblyFileVersion(BuildDetails.GitMajor + "." + + BuildDetails.GitMinor + "." + + BuildDetails.GitPatch + ".0")] + +[assembly: AssemblyInformationalVersion(BuildDetails.BuildDate + + " " + BuildDetails.GitCommit + + " (" + BuildDetails.GitBranch + ")")] \ No newline at end of file diff --git a/AutoTx.sln b/AutoTx.sln index 920d1a1d393e6bb2507498f19a8469711a7b4e01..81a8bca68b5a45e515b1ec39b558baced6cbcf2d 100644 --- a/AutoTx.sln +++ b/AutoTx.sln @@ -24,6 +24,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Resources\Mail-Templates\Transfer-Success.txt = Resources\Mail-Templates\Transfer-Success.txt EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ATxDiagnostics", "ATxDiagnostics\ATxDiagnostics.csproj", "{1FDA9634-87C9-4C25-AD12-BF79DA61D44D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,6 +52,10 @@ Global {6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Debug|Any CPU.Build.0 = Debug|Any CPU {6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.ActiveCfg = Release|Any CPU {6CAFC0C6-A428-4D30-A9F9-700E829FEA51}.Release|Any CPU.Build.0 = Release|Any CPU + {1FDA9634-87C9-4C25-AD12-BF79DA61D44D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FDA9634-87C9-4C25-AD12-BF79DA61D44D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FDA9634-87C9-4C25-AD12-BF79DA61D44D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FDA9634-87C9-4C25-AD12-BF79DA61D44D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE