This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
diagnostics_metrics.fsx
77 lines (60 loc) · 1.58 KB
/
diagnostics_metrics.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(*** hide ***)
// This block of code is omitted in the generated HTML documentation. Use
// it to define helpers that you do not want to show in the documentation.
#I "../../bin"
#r "FsPickler.dll"
#r "Cricket.dll"
open Cricket
open Cricket.Diagnostics
open System.IO
open System.Threading
open Nessos.FsPickler
(**
Metrics
=======
*)
ActorHost.Start()
type Say =
| Hello
| HelloWorld
| Name of string
let greeter =
actor {
name "greeter"
body (
let rec loop() = messageHandler {
let! msg = Message.receive() //Wait for a message
match msg with
| Hello -> printfn "Hello" //Handle Hello leg
| HelloWorld -> printfn "Hello World" //Handle HelloWorld leg
| Name name -> printfn "Hello, %s" name //Handle Name leg
return! loop() //Recursively loop
}
loop())
} |> Actor.spawn
let cts = new CancellationTokenSource()
let rec publisher() = async {
do greeter <-- Name "Metrics"
return! publisher()
}
(**
Write the metrics out to a file on a background thread
*)
let rec reporter() =
let pickler = FsPickler.CreateXml()
async {
do! Async.Sleep(5000)
do File.WriteAllBytes(@"C:\temp\Example.metrics", Metrics.getReport() |> pickler.Pickle)
return! reporter()
}
(**
Start everything
*)
Async.Start(reporter(), cts.Token)
Async.Start(publisher(), cts.Token)
cts.Cancel()
greeter <-- Shutdown
(**
Sample metrics output
explain exponential weights, and different types of counters.
*)