Skip to content

Instantly share code, notes, and snippets.

@dgfitch
Created October 4, 2011 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgfitch/1262415 to your computer and use it in GitHub Desktop.
Save dgfitch/1262415 to your computer and use it in GitHub Desktop.
Simple HTTP statistics timer in F#
open System
open System.IO
open System.Net
open System.Diagnostics
let track (url:string) (log:string) =
while true do
let stopwatch = new Stopwatch()
stopwatch.Start()
let error = ref (None : string option)
let status = ref 0
try
let request = WebRequest.Create(url) :?> HttpWebRequest
use response = request.GetResponse() :?> HttpWebResponse
status := int response.StatusCode
with ex ->
error := Some ex.Message
stopwatch.Stop()
try
printfn "%A - elapsed %A" System.DateTime.Now stopwatch.Elapsed
use file = File.AppendText log
file.WriteLine( sprintf "\"%A\",\"%A\",\"%s\"" System.DateTime.Now stopwatch.Elapsed.Milliseconds (defaultArg error.Value "") )
file.Close()
with ex ->
printfn "ERROR: %s" ex.Message
System.Threading.Thread.Sleep INTERVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment