In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use CZGL.ProcessMetrics to monitor .NET applications". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's ideas to study and learn "how to monitor .NET applications with CZGL.ProcessMetrics".
Guide reading
CZGL.ProcessMetrics is a Metrics library, which can record the program's GC, CPU, memory, machine network, disk space and other information, use Prometheus to collect information, and then use Grafana to display.
Preview the effect picture:
Install ProcsssMetrics
You only need to install a library through Nuget to quickly add resource monitoring to the program. ProcssMetrics also supports Winform, Wpf, ASP.NET Core, and so on.
CZGL.ProcessMetrics supports .NET Standard 2.0 and .NET Core 3.1, but in .NET Standard 2.0, some information is not available because part of the Core API is missing, which is as follows:
Identify .NET Core API indicates that gc_memory_infoGC.GetGCMemoryInfo () gets GC memory information total_allocated_bytesGC.GetTotalAllocatedBytes () Total allocation dotnet_lock_contention_totalMonitor.LockContentionCount thread pool contention
To create a new application, search for CZGL.ProcessMetrics direct references in Nuget.
Nuget address: https://www.nuget.org/packages/CZGL.ProcessMetrics
There are two ways to use Metrics. The first is to use built-in HttpListener, which can provide URL access independently without putting it in Web. It is suitable for applications such as winform, wpf or pure console. However, with HttpListener, you need to start the application in an administrator way to run properly.
How to use it:
Using CZGL.ProcessMetrics;...... MetricsServer metricsServer = new MetricsServer ("http://*:1234/metrics/");metricsServer.Start();
The other is to use ASP.NET Core,Metrics as middleware to join the Web application, at this time using kestrel.
In Nuget, search for the CZGL.ProcessMetrics.ASPNETCore package, and then use middleware to generate Metrics endpoints.
App.UseEndpoints (endpoints = > {endpoints.MapControllers (); endpoints.ProcessMetrices ("/ metrics");})
But at present, either way, it is necessary to let the exposed port out so that Prometheus can access API. Later, it will be added to support the ability to push monitoring information directly to Prometheus without exposing API and providing Web services.
Visit the corresponding URL, and you can see that there is a lot of information output, which is the format of the Prometheus data.
Http://127.0.0.1:1234/metrics
Set up Prometheus/Grafana
Here we use Docker to build a monitoring platform.
Pull the image:
Docker pull prom/prometheusdocker pull grafana/grafana
Under the / opt/prometheus directory, create a new prometheus.yml file with the following contents:
# my global configglobal: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. Evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configurationalerting: alertmanagers:-static_configs:-targets: #-alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files: #-"first_rules.yml" #-"second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.scrape_configs: # The job name is added as a label `job= `to any timeseries scraped from this config. -job_name: 'prometheus' # metrics_path defaults to' / metrics' # scheme defaults to 'http'. Static_configs:-targets: ['localhost:9090']-job_name:' processmetrice' metrics_path:'/ metrics' static_configs:-targets: ['123.123.123.123virtual 1234']
Please replace the IP in the last line.
Start Prometheus using the container:
Docker run-d-p 9090 9090-v / opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
Start Grafana using the container:
Mkdir / opt/grafana-storagechmod 777-R / opt/grafana-storagedocker run-d-p 3000 name=grafana-v / opt/grafana-storage:/var/lib/grafana grafana/grafana
Open port 9090, open Status-Targets in the menu bar, and you can see the relevant records.
Next, access port 3000, open Grafana, and the initial account password is admin.
Configure Grafana
First, we need to get the monitoring data in the Prometheus for Grafana, and we need to add a data source.
Select Prometheus, follow the prompts, and fill in HTTP-URL.
Next, download the author's customized Jsom Model, the file name is CZGL.ProcessMetrics.json.
Download address:
Https://github.com/whuanle/CZGL.SystemInfo/releases/tag/v1.0
Then import the model file.
You can see the monitoring interface.
Thank you for reading, the above is "how to use CZGL.ProcessMetrics to monitor .NET applications" content, after the study of this article, I believe you have a deeper understanding of how to use CZGL.ProcessMetrics to monitor .NET applications, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.