Metrics. NET step by step, metrics. netstepby

Source: Internet
Author: User

Metrics. NET step by step, metrics. netstepby
Install the Nuget package

Search metrics in nuget,

Class Program {static void Main (string [] args) {Metric. config // Web monitoring dashboard, which provides Metrics.. NET metric chart. withHttpEndpoint ("http: // localhost: 1234/metrics/") // configure report output. withReporting (rc) =>{// report output to the console rc. withConsoleReport (TimeSpan. fromSeconds (5) ;}); Console. readLine ();}}Collect measurement value Gauge

static void GaugeTest(){    Metric.Gauge("test.gauge", () => ran.NextDouble() * 1000, Unit.None);}

Static Random ran = new Random (DateTime. now. timeOfDay. milliseconds); static void CounterTest () {var counter = Metric. counter ("test. counter ", Unit. custom ("concurrent"); Action doWork = () => {System. threading. thread. sleep (ran. next (10,300) ;}; Action idlesse = () =>{ System. threading. thread. sleep (ran. next (0,500) ;}; for (var I = 0; I <20; I ++) {Task. run () => {while (true) {counter. increment (); doWork (); counter. decrement (); idlesse ();}});}}

Static Random ran = new Random (DateTime. now. timeOfDay. milliseconds); static void HistogramTest () {var histogram = Metric. histogram ("test. histogram ", Unit. custom ("years old"), SamplingType. longTerm); Task. run () => {while (true) {histogram. update (ran. next (10, 80), ran. next (0, 2)> 0? "Male": "female"); System. Threading. Thread. Sleep (TimeSpan. FromSeconds (1 ));}});}

Static Random ran = new Random (DateTime. now. timeOfDay. milliseconds); static void MeterTest () {var meter = Metric. meter ("test. meter ", Unit. CILS, TimeUnit. seconds); Action idlesse = () => {System. threading. thread. sleep (ran. next (20, 50) ;}; Task. run () => {while (true) {meter. mark (); idlesse ();}});}

Static Random ran = new Random (DateTime. now. timeOfDay. milliseconds); static void TimerTest () {var timer = Metric. timer ("test. meter ", Unit. none, SamplingType. favourRecent, TimeUnit. seconds, TimeUnit. microseconds); Action doWork = () => {System. threading. thread. sleep (ran. next (10,300) ;}; Action idlesse = () =>{ System. threading. thread. sleep (ran. next (0,500) ;}; for (var I = 0; I <20; I ++) {Task. run () => {while (true) {timer. time (doWork); idlesse ();}});}}

Static Random ran = new Random (DateTime. now. timeOfDay. milliseconds); static void HealthCheckTest () {HealthChecks. registerHealthCheck ("test. healthcheck ", () => {return ran. next (100) <5? HealthCheckResult. Unhealthy (): HealthCheckResult. Healthy ();});}

The health check is simple. There are two output values: healthy and unhealthy ).

Measure type non-rigorous relationship Overview

{"Count": "long" "Items": [{"Item": "string", "Count": "long", "Percent": "double"}]}

HistogramValue

{    "Count" : "long",    "LastValue" : "double",    "LastUserValue" : "string",    "Max" : "double",    "MaxUserValue" : "string",    "Mean" : "double",    "Min" : "double";    "MinUserValue" : "string",    "StdDev" : "double",    "Median" : "double",    "Percentile75" : "double",    "Percentile95" : "double",    "Percentile98" : "double",    "Percentile99" : "double",    "Percentile999" : "double",    "SampleSize" : "int"}

MeterValue

{    "Count" : "long",    "MeanRate" : "double",    "OneMinuteRate" : "double",    "FiveMinuteRate" : "double",    "FifteenMinuteRate" : "double",    "RateUnit" : "TimeUnit",    "Items" : [{        "Item" : "string",        "Percent" : "double",        "Value" : {            "Count" : "long",            "MeanRate" : "double",            "OneMinuteRate" : "double",            "FiveMinuteRate" : "double",            "FifteenMinuteRate" : "double",            "RateUnit" : "TimeUnit"        }    }]}

TimerValue

{    "Rate" : "MeterValue",    "Histogram" : "HistogramValue",    "ActiveSessions" : "long"}
Measure Value collection method Gauge

Read during use, no additional function support required

Counter

Increase (long value = 1, string item = null): void // Increase the count

Decrease (long value = 1, string item = null): void // reduce the count

Histogram

Update (double value, string userValue = null): void

Meter

Mark (long count = 1, string item = null): void

Timer

Record (long duration, TimeUnit unit, string userValue = null): void

Timer (Action action, string userValue = null): void

Timer <T> (Func <T> action, string userValue = null): T

Download

MetricsDemo.rar

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.