Skip to content

Commit bd6957b

Browse files
committed
Restructure project
1 parent bce6924 commit bd6957b

34 files changed

+280
-112
lines changed

examples/WebApiApplication/Controllers/MetricsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Text;
66
using System.Web.Http;
77
using Prometheus.Client;
8-
using Prometheus.Client.Advanced;
8+
using Prometheus.Client.Collectors;
99

1010
namespace WebApiApplication.Controllers
1111
{

examples/WebApiApplication/Global.asax.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System.Web.Http;
2-
using Prometheus.Client.Advanced;
2+
3+
using Prometheus.Client.Collectors;
34

45
namespace WebApiApplication
56
{
67
public class WebApiApplication : System.Web.HttpApplication
78
{
89
protected void Application_Start()
910
{
10-
CollectorRegistry.Instance.RegisterOnDemandCollectors(new[] { new DotNetStatsCollector() });
11+
CollectorRegistry.Instance.RegisterOnDemandCollectors(new IOnDemandCollector[] { new DotNetStatsCollector(), new WindowsDotNetStatsCollector(), new PerfCounterCollector() });
1112
GlobalConfiguration.Configure(WebApiConfig.Register);
1213
}
1314
}

examples/WebCoreApplication/Controllers/MetricsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Text;
33
using Microsoft.AspNetCore.Mvc;
44
using Prometheus.Client;
5-
using Prometheus.Client.Advanced;
5+
using Prometheus.Client.Collectors;
66

77

88
namespace WebCoreApplication.Controllers

examples/WebCoreApplication/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.Extensions.Configuration;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Logging;
6-
using Prometheus.Client.Advanced;
6+
using Prometheus.Client.Collectors;
77

88
namespace WebCoreApplication
99
{
@@ -18,7 +18,7 @@ public Startup(IHostingEnvironment env)
1818
.AddEnvironmentVariables();
1919
Configuration = builder.Build();
2020

21-
CollectorRegistry.Instance.RegisterOnDemandCollectors(new[] { new DotNetStatsCollector() });
21+
CollectorRegistry.Instance.RegisterOnDemandCollectors(new IOnDemandCollector[] { new DotNetStatsCollector(), new WindowsDotNetStatsCollector() });
2222
}
2323

2424
public IConfigurationRoot Configuration { get; }

src/Prometheus.Client/Advanced/IOnDemandCollector.cs

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Prometheus.Client/Advanced/Child.cs renamed to src/Prometheus.Client/Child.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using Prometheus.Advanced;
2-
using Prometheus.Advanced.DataContracts;
1+
using Prometheus.Client.Collectors;
32
using Prometheus.Client.Internal;
3+
using Prometheus.Contracts;
44

5-
namespace Prometheus.Client.Advanced
5+
namespace Prometheus.Client
66
{
77
public abstract class Child
88
{

src/Prometheus.Client/Advanced/Collector.cs renamed to src/Prometheus.Client/Collectors/Collector.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
using System;
22
using System.Collections.Concurrent;
33
using System.Text.RegularExpressions;
4-
using Prometheus.Advanced;
5-
using Prometheus.Advanced.DataContracts;
64
using Prometheus.Client.Internal;
5+
using Prometheus.Contracts;
76

8-
namespace Prometheus.Client.Advanced
7+
namespace Prometheus.Client.Collectors
98
{
109
public abstract class Collector<T> : ICollector where T : Child, new()
1110
{

src/Prometheus.Client/Advanced/CollectorRegistry.cs renamed to src/Prometheus.Client/Collectors/CollectorRegistry.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using Prometheus.Advanced.DataContracts;
5+
using Prometheus.Contracts;
66

7-
namespace Prometheus.Client.Advanced
7+
8+
namespace Prometheus.Client.Collectors
89
{
910
public class CollectorRegistry : ICollectorRegistry
1011
{

src/Prometheus.Client/Advanced/DotNetStatsCollector.cs renamed to src/Prometheus.Client/Collectors/DotNetStatsCollector.cs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,51 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44

5-
namespace Prometheus.Client.Advanced
5+
namespace Prometheus.Client.Collectors
66
{
77
/// <summary>
8-
/// Collects metrics on .net without performance counters
8+
/// Collects metrics on .net without performance counters
99
/// </summary>
1010
public class DotNetStatsCollector : IOnDemandCollector
1111
{
12+
private readonly List<Counter.ThisChild> _collectionCounts = new List<Counter.ThisChild>();
1213
private readonly Process _process;
13-
private Counter _perfErrors;
14-
private readonly List<Counter.Child> _collectionCounts = new List<Counter.Child>();
15-
private Gauge _totalMemory;
16-
private Gauge _virtualMemorySize;
17-
private Gauge _workingSet;
18-
private Gauge _privateMemorySize;
1914
private Counter _cpuTotal;
15+
private Counter _perfErrors;
16+
2017
private Gauge _startTime;
21-
private Gauge _numThreads;
22-
private Gauge _pid;
18+
private Gauge _totalMemory;
19+
2320

21+
/// <summary>
22+
/// Constructors
23+
/// </summary>
2424
public DotNetStatsCollector()
2525
{
2626
_process = Process.GetCurrentProcess();
2727
}
2828

29+
/// <inheritdoc />
30+
2931
public void RegisterMetrics()
3032
{
33+
_perfErrors = Metrics.CreateCounter("dotnet_collection_errors_total", "Total number of errors that occured during collections");
34+
3135
var collectionCountsParent = Metrics.CreateCounter("dotnet_collection_count_total", "GC collection count", "generation");
3236

3337
for (var gen = 0; gen <= GC.MaxGeneration; gen++)
34-
{
3538
_collectionCounts.Add(collectionCountsParent.Labels(gen.ToString()));
36-
}
3739

3840
// Metrics that make sense to compare between all operating systems
3941
_startTime = Metrics.CreateGauge("process_start_time_seconds", "Start time of the process since unix epoch in seconds");
4042
_cpuTotal = Metrics.CreateCounter("process_cpu_seconds_total", "Total user and system CPU time spent in seconds");
4143

42-
// Windows specific metrics
43-
_virtualMemorySize = Metrics.CreateGauge("process_windows_virtual_bytes", "Process virtual memory size");
44-
_workingSet = Metrics.CreateGauge("process_windows_working_set", "Process working set");
45-
_privateMemorySize = Metrics.CreateGauge("process_windows_private_bytes", "Process private memory size");
46-
_numThreads = Metrics.CreateGauge("process_windows_num_threads", "Total number of threads");
47-
_pid = Metrics.CreateGauge("process_windows_processid", "Process ID");
48-
4944
// .net specific metrics
5045
_totalMemory = Metrics.CreateGauge("dotnet_totalmemory", "Total known allocated memory");
51-
_perfErrors = Metrics.CreateCounter("dotnet_collection_errors_total", "Total number of errors that occured during collections");
46+
5247

5348
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
5449
_startTime.Set((_process.StartTime.ToUniversalTime() - epoch).TotalSeconds);
55-
_pid.Set(_process.Id);
5650
}
5751

5852
public void UpdateMetrics()
@@ -68,11 +62,8 @@ public void UpdateMetrics()
6862
}
6963

7064
_totalMemory.Set(GC.GetTotalMemory(false));
71-
_virtualMemorySize.Set(_process.VirtualMemorySize64);
72-
_workingSet.Set(_process.WorkingSet64);
73-
_privateMemorySize.Set(_process.PrivateMemorySize64);
65+
7466
_cpuTotal.Inc(_process.TotalProcessorTime.TotalSeconds - _cpuTotal.Value);
75-
_numThreads.Set(_process.Threads.Count);
7667
}
7768
catch (Exception)
7869
{

src/Prometheus.Client/Advanced/ICollector.cs renamed to src/Prometheus.Client/Collectors/ICollector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Prometheus.Advanced.DataContracts;
1+
using Prometheus.Contracts;
22

3-
namespace Prometheus.Client.Advanced
3+
namespace Prometheus.Client.Collectors
44
{
55
public interface ICollector
66
{

0 commit comments

Comments
 (0)