In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to monitor the performance of applications in Metrics. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
A metric type
Metrics provides five basic types of metrics: Gauges, Counters, Histograms, Meters and Timers
Gauge
Gauge is the simplest measurement type, with only a simple return value, which is used to record the instantaneous value of some objects or things.
For example, we have a counter of type Gauge to record the number of cities currently active for a service.
Metric.Gauge ("Service Cities Count", () = > Cities.Count, new Unit ("a")); Counters
Counter is a simple 64-bit counter that can be added and decreased.
For example, we can define two counters of type Counter to count the number of all service requests and the total number of requests currently being processed.
/ keep the total count of the requests/// private readonly Counter totalRequestsCounter = Metric.Counter ("Requests", Unit.Requests); / count the current concurrent requests/// private readonly Counter concurrentRequestsCounter = Metric.Counter ("SampleMetrics.ConcurrentRequests", Unit.Requests)
In this way, at the beginning of our request processing, both counters are incremented at the same time.
This.concurrentRequestsCounter.Increment (); / / increment concurrent requests counterthis.totalRequestsCounter.Increment (); / / increment total requests counter
When a request is processed, subtract the request currently being processed by one
This.concurrentRequestsCounter.Decrement (); / / decrement number of concurrent requests
This kind of counter can also be used to count, such as how many people are online, or how many session in the server are within the validity period.
Meters
Meter is a self-incrementing counter that is usually used to measure the rate of occurrence of a series of events. It provides the average rate, as well as the exponential smoothing average rate, as well as the rate of 1 minute, 5 minutes, and 15 minutes after sampling.
For example, you need to count the rate of requests, such as the average number of requests coming in per minute. You only need to define a metric
/ measure the rate at which requests come in/// private readonly Meter meter = Metric.Meter ("Requests", Unit.Requests,TimeUnit.Seconds)
Call the Mark method where the request is processed.
This.meter.Mark (); / / signal a new request to the meter
For example, measure the probability of service errors, such as how many errors per hour. You can define a metric.
/ measure the rate of service exception/// private readonly Meter errorMeter = Metric.Meter ("Error", Unit.Errors, TimeUnit.Hours)
In this way, if there is an exception when processing the request, you can call the Mark method of errorMeter.
This.errorMeter.Mark (); / / signal a new error to the meterHistograms
Histrogram is used to measure the distribution of Value in stream data. Histrogram can calculate maximum / minimum values, averages, variances, quantiles (such as median, or 95th quantiles), such as 75%, 90%, 98%, 99%, within which range of data.
For example, we want to measure the length distribution of all request parameters passed into the service. Then, you can define a histogram.
/ keep a histogram of the input data of our request method / private readonly Histogram histogramOfData = Metric.Histogram ("ResultsExample", Unit.Items)
Then, at the request, call its Update method to update the value.
This.histogramOfData.Update (request.length, methodName); / / update the histogram with the input dataTimer
Timer is a combination of Histogram and Meter, such as counting the rate and processing time of current requests.
You can define a Timer:
/ measure the time rate and duration of requests/// private readonly Timer timer = Metric.Timer ("Requests", Unit.Requests)
When in use, call the NewContext of timer.
Using (this.timer.NewContext (i.ToString () / / measure until disposed {...} output of two metrics data
After collecting so much data, we need to dynamically display or save the data in real time. Metric provides a variety of data reporting interfaces. Include self-contained Metrics.NET.FlotVisualization, as well as output to professional system monitoring Graphite, output to open source, distributed, time series medium InfluxDB, or output to ElasticSearch. It is also very easy to configure. For example, if you want to display it directly on the http page, you only need to set the appropriate EndPoint during initialization:
Metric.Config .WithHttpEndpoint ("http://localhost:1234/metrics/") .WithAllCounters () .WithInternalMetrics () .Withreporting (config = > config .WithConsoleReport (TimeSpan.FromSeconds (30)
Then type http://localhost:1234/metrics/ in the browser, and you can see all kinds of quasi-real-time measurement information collected:
The performance DashBoard of the above is a little bit rudimentary. Usually, we usually store the real-time collected data in the distributed time series database InfluxDB, and then use the open source chart control Grafana to display the data in real time. For example, we can create a dynamic quasi-real-time performance monitoring system like the following:
The above is how to monitor the performance of applications in Metrics. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.