您可以打开 perfmon.exe,清除所有当前计数并添加您的自定义应用程序计数器吗?
Can you open perfmon.exe, clear any current counts and add your custom app counters?
您能否打开 perfmon.exe、清除所有当前计数并从 C# 添加您的自定义应用程序计数器?
正在考虑 perfmon API 但我找不到它。
性能计数器不太适合跟踪应用程序级指标。
在 Linux/Unix 世界中有一个优秀的 Graphite 和 StatsD 组合,我们已经将它移植到 .NET:Statsify.
它允许您从应用程序中收集各种指标:数据库查询的数量、调用 Web 服务所需的时间、活动连接的跟踪数量等——所有这些都使用简单的 API喜欢
Stats.Increment("db.query.count");
您可以使用 PerformanceCounter class,即 int System.System.Diagnostics 命名空间。
要添加您自己的类别和计数器,您可以使用如下代码:
if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))
{
CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
// Add the counter.
CounterCreationData averageCount64 = new CounterCreationData();
averageCount64.CounterType = PerformanceCounterType.AverageCount64;
averageCount64.CounterName = "AverageCounter64Sample";
CCDC.Add(averageCount64);
// Add the base counter.
CounterCreationData averageCount64Base = new CounterCreationData();
averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
averageCount64Base.CounterName = "AverageCounter64SampleBase";
CCDC.Add(averageCount64Base);
// Create the category.
PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
"Demonstrates usage of the AverageCounter64 performance counter type.",
CCDC);
}
要清除计数器,您可以将 RawValue 重置为 0,如下所示:
var pc = new PerformanceCounter("AverageCounter64SampleCategory",
"AverageCounter64Sample",
false);
pc.RawValue = 0;
上面的这些示例代码是我从这个link得到的:system.diagnostics.performancecounter
希望对您有所帮助。
您能否打开 perfmon.exe、清除所有当前计数并从 C# 添加您的自定义应用程序计数器?
正在考虑 perfmon API 但我找不到它。
性能计数器不太适合跟踪应用程序级指标。
在 Linux/Unix 世界中有一个优秀的 Graphite 和 StatsD 组合,我们已经将它移植到 .NET:Statsify.
它允许您从应用程序中收集各种指标:数据库查询的数量、调用 Web 服务所需的时间、活动连接的跟踪数量等——所有这些都使用简单的 API喜欢
Stats.Increment("db.query.count");
您可以使用 PerformanceCounter class,即 int System.System.Diagnostics 命名空间。
要添加您自己的类别和计数器,您可以使用如下代码:
if (!PerformanceCounterCategory.Exists("AverageCounter64SampleCategory"))
{
CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
// Add the counter.
CounterCreationData averageCount64 = new CounterCreationData();
averageCount64.CounterType = PerformanceCounterType.AverageCount64;
averageCount64.CounterName = "AverageCounter64Sample";
CCDC.Add(averageCount64);
// Add the base counter.
CounterCreationData averageCount64Base = new CounterCreationData();
averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
averageCount64Base.CounterName = "AverageCounter64SampleBase";
CCDC.Add(averageCount64Base);
// Create the category.
PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
"Demonstrates usage of the AverageCounter64 performance counter type.",
CCDC);
}
要清除计数器,您可以将 RawValue 重置为 0,如下所示:
var pc = new PerformanceCounter("AverageCounter64SampleCategory",
"AverageCounter64Sample",
false);
pc.RawValue = 0;
上面的这些示例代码是我从这个link得到的:system.diagnostics.performancecounter
希望对您有所帮助。