Cricket


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.

namespace Cricket
namespace Cricket.Diagnostics
namespace System
namespace System.IO
namespace System.Threading
namespace Nessos
namespace Nessos.FsPickler
type ActorHost =
  interface IDisposable
  private new : configuration:ActorHostConfiguration -> ActorHost
  member private Configure : f:(ActorHostConfiguration -> ActorHostConfiguration) -> unit
  member private RegisterActor : ref:ActorRef -> unit
  member private ResolveActor : name:ActorPath -> ActorRef list
  member SubscribeEvents : eventF:('a0 -> unit) -> ActorHost
  member private CancelToken : CancellationToken
  member private EventStream : IEventStream
  member private Name : string
  static member Dispose : unit -> unit
  ...

Full name: Cricket.ActorHost
static member ActorHost.Start : ?name:string * ?loggers:ILogWriter list * ?serializer:'a0 * ?registry:ActorRegistry * ?metrics:MetricsConfiguration * ?tracing:TracingConfiguration * ?cancellationToken:CancellationToken -> ActorHost
type Say =
  | Hello
  | HelloWorld
  | Name of string

Full name: Diagnostics_metrics.Say
union case Say.Hello: Say
union case Say.HelloWorld: Say
union case Say.Name: string -> Say
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val greeter : ActorRef

Full name: Diagnostics_metrics.greeter
val actor : ActorConfigurationBuilder

Full name: Cricket.ActorConfiguration.actor
custom operation: name (string)

Calls ActorConfigurationBuilder.Name
custom operation: body (MessageHandler<ActorCell<'a>,unit>)

Calls ActorConfigurationBuilder.Body
val loop : (unit -> MessageHandler<ActorCell<Say>,'a>)
val messageHandler : Message.MessageHandlerBuilder

Full name: Cricket.ActorConfiguration.messageHandler
val msg : Say
Multiple items
module Message

from Cricket

--------------------
type Message<'a> =
  {Id: uint64 option;
   Sender: ActorRef;
   Message: 'a;}

Full name: Cricket.Message<_>
val receive : unit -> MessageHandler<ActorCell<'a>,'a>

Full name: Cricket.Message.receive
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val name : string
Multiple items
module Actor

from Cricket

--------------------
type Actor<'a> =
  interface IDisposable
  interface IActor<'a>
  interface IActor
  new : defn:ActorConfiguration<'a> -> Actor<'a>
  override ToString : unit -> string
  member Ref : ActorRef

Full name: Cricket.Actor<_>

--------------------
new : defn:ActorConfiguration<'a> -> Actor<'a>
val spawn : config:ActorConfiguration<'a> -> ActorRef

Full name: Cricket.Actor.spawn
val cts : CancellationTokenSource

Full name: Diagnostics_metrics.cts
Multiple items
type CancellationTokenSource =
  new : unit -> CancellationTokenSource
  member Cancel : unit -> unit + 1 overload
  member Dispose : unit -> unit
  member IsCancellationRequested : bool
  member Token : CancellationToken
  static member CreateLinkedTokenSource : params tokens:CancellationToken[] -> CancellationTokenSource + 1 overload

Full name: System.Threading.CancellationTokenSource

--------------------
CancellationTokenSource() : unit
val publisher : unit -> Async<'a>

Full name: Diagnostics_metrics.publisher
val async : AsyncBuilder

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.async
val reporter : unit -> Async<'a>

Full name: Diagnostics_metrics.reporter
val pickler : XmlSerializer
type FsPickler =
  private new : unit -> FsPickler
  static member Clone : t:'T -> 'T
  static member ComputeHash : value:'T * ?hashFactory:IHashStreamFactory -> HashResult
  static member ComputeSize : value:'T -> int64
  static member CreateBinary : ?forceLittleEndian:bool * ?typeConverter:ITypeNameConverter -> BinarySerializer
  static member CreateXml : ?typeConverter:ITypeNameConverter * ?indent:bool -> XmlSerializer
  static member GatherObjectsInGraph : graph:obj -> obj []
  static member GatherTypesInObjectGraph : graph:obj -> Type []
  static member GeneratePickler : unit -> Pickler<'T>
  static member GeneratePickler : t:Type -> Pickler
  ...

Full name: Nessos.FsPickler.FsPickler
static member FsPickler.CreateXml : ?typeConverter:ITypeNameConverter * ?indent:bool -> XmlSerializer
Multiple items
type Async
static member AsBeginEnd : computation:('Arg -> Async<'T>) -> ('Arg * AsyncCallback * obj -> IAsyncResult) * (IAsyncResult -> 'T) * (IAsyncResult -> unit)
static member AwaitEvent : event:IEvent<'Del,'T> * ?cancelAction:(unit -> unit) -> Async<'T> (requires delegate and 'Del :> Delegate)
static member AwaitIAsyncResult : iar:IAsyncResult * ?millisecondsTimeout:int -> Async<bool>
static member AwaitTask : task:Task<'T> -> Async<'T>
static member AwaitWaitHandle : waitHandle:WaitHandle * ?millisecondsTimeout:int -> Async<bool>
static member CancelDefaultToken : unit -> unit
static member Catch : computation:Async<'T> -> Async<Choice<'T,exn>>
static member FromBeginEnd : beginAction:(AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg:'Arg1 * beginAction:('Arg1 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * beginAction:('Arg1 * 'Arg2 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromBeginEnd : arg1:'Arg1 * arg2:'Arg2 * arg3:'Arg3 * beginAction:('Arg1 * 'Arg2 * 'Arg3 * AsyncCallback * obj -> IAsyncResult) * endAction:(IAsyncResult -> 'T) * ?cancelAction:(unit -> unit) -> Async<'T>
static member FromContinuations : callback:(('T -> unit) * (exn -> unit) * (OperationCanceledException -> unit) -> unit) -> Async<'T>
static member Ignore : computation:Async<'T> -> Async<unit>
static member OnCancel : interruption:(unit -> unit) -> Async<IDisposable>
static member Parallel : computations:seq<Async<'T>> -> Async<'T []>
static member RunSynchronously : computation:Async<'T> * ?timeout:int * ?cancellationToken:CancellationToken -> 'T
static member Sleep : millisecondsDueTime:int -> Async<unit>
static member Start : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions * ?cancellationToken:CancellationToken -> Task<'T>
static member StartChild : computation:Async<'T> * ?millisecondsTimeout:int -> Async<Async<'T>>
static member StartChildAsTask : computation:Async<'T> * ?taskCreationOptions:TaskCreationOptions -> Async<Task<'T>>
static member StartImmediate : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
static member StartWithContinuations : computation:Async<'T> * continuation:('T -> unit) * exceptionContinuation:(exn -> unit) * cancellationContinuation:(OperationCanceledException -> unit) * ?cancellationToken:CancellationToken -> unit
static member SwitchToContext : syncContext:SynchronizationContext -> Async<unit>
static member SwitchToNewThread : unit -> Async<unit>
static member SwitchToThreadPool : unit -> Async<unit>
static member TryCancelled : computation:Async<'T> * compensation:(OperationCanceledException -> unit) -> Async<'T>
static member CancellationToken : Async<CancellationToken>
static member DefaultCancellationToken : CancellationToken

Full name: Microsoft.FSharp.Control.Async

--------------------
type Async<'T>

Full name: Microsoft.FSharp.Control.Async<_>
static member Async.Sleep : millisecondsDueTime:int -> Async<unit>
type File =
  static member AppendAllLines : path:string * contents:IEnumerable<string> -> unit + 1 overload
  static member AppendAllText : path:string * contents:string -> unit + 1 overload
  static member AppendText : path:string -> StreamWriter
  static member Copy : sourceFileName:string * destFileName:string -> unit + 1 overload
  static member Create : path:string -> FileStream + 3 overloads
  static member CreateText : path:string -> StreamWriter
  static member Decrypt : path:string -> unit
  static member Delete : path:string -> unit
  static member Encrypt : path:string -> unit
  static member Exists : path:string -> bool
  ...

Full name: System.IO.File
File.WriteAllBytes(path: string, bytes: byte []) : unit
module Metrics

from Cricket.Diagnostics
val getReport : unit -> seq<string * seq<string * MetricValue>>

Full name: Cricket.Diagnostics.Metrics.getReport
member FsPicklerSerializer.Pickle : value:'T * ?streamingContext:System.Runtime.Serialization.StreamingContext * ?encoding:System.Text.Encoding -> byte []
member FsPicklerSerializer.Pickle : valueType:System.Type * value:obj * ?streamingContext:System.Runtime.Serialization.StreamingContext * ?encoding:System.Text.Encoding -> byte []
member FsPicklerSerializer.Pickle : pickler:Pickler * value:obj * ?streamingContext:System.Runtime.Serialization.StreamingContext * ?encoding:System.Text.Encoding -> byte []
member FsPicklerSerializer.Pickle : pickler:Pickler<'T> * value:'T * ?streamingContext:System.Runtime.Serialization.StreamingContext * ?encoding:System.Text.Encoding -> byte []
static member Async.Start : computation:Async<unit> * ?cancellationToken:CancellationToken -> unit
property CancellationTokenSource.Token: CancellationToken
CancellationTokenSource.Cancel() : unit
CancellationTokenSource.Cancel(throwOnFirstException: bool) : unit
union case SystemMessage.Shutdown: SystemMessage
Fork me on GitHub