123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123(*
* Copyright (c) 2015 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)moduleGc=structletgc=reffalseletenable()=gc:=trueletdisable()=gc:=falseletfull=reffalseletfull_majorb=full:=bletwords()=lett=Gc.stat()int.Gc.live_words/1_000letrun_full_major()=if!fullthenGc.full_major()letppfmt()=match!gcwith|false->()|true->run_full_major();Format.fprintffmt"|%dk"(words())endtypecounter=MProf.Counter.tletvalue=MProf.Counter.valueletpp_counterfmtt=Format.fprintffmt"%d"(valuet)typet={tcp_listens:counter;tcp_channels:counter;tcp_connects:counter;tcp_timers:counter;mutabletotal_established:int;mutabletotal_passive_connections:int;mutabletotal_active_connections:int;mutabletotal_timers:int;}letmetrics=letopenMetricsinletdoc="TCP metrics"inletdatat=Data.v[int"syn-rcvd state"(MProf.Counter.valuet.tcp_listens);int"established state"(MProf.Counter.valuet.tcp_channels);int"client connections"(MProf.Counter.valuet.tcp_connects);int"timers"(MProf.Counter.valuet.tcp_timers);int"total timers"t.total_timers;int"total established"t.total_established;int"total syn-rcvd"t.total_passive_connections;int"total client"t.total_active_connections]inSrc.v~doc~tags:Metrics.Tags.[]~data"tcp"letppfmtt=Format.fprintffmt"[%a|%a|%a|%a%a]"pp_countert.tcp_timerspp_countert.tcp_listenspp_countert.tcp_channelspp_countert.tcp_connectsGc.pp()letincrr=MProf.Counter.increaser1letdecrr=MProf.Counter.increaser(-1)letsingleton=letmakename=MProf.Counter.create~name()in{tcp_listens=make"Tcp.listens";tcp_channels=make"Tcp.channels";tcp_connects=make"Tcp.connects";tcp_timers=make"Tcp.timers";total_timers=0;total_established=0;total_passive_connections=0;total_active_connections=0;}letmetrics()=Metrics.addmetrics(funx->x)(fund->dsingleton)letincr_listen()=incrsingleton.tcp_listens;singleton.total_passive_connections<-succsingleton.total_passive_connections;metrics()letdecr_listen()=decrsingleton.tcp_listens;metrics()letincr_channel()=incrsingleton.tcp_channels;singleton.total_established<-succsingleton.total_established;metrics()letdecr_channel()=decrsingleton.tcp_channels;metrics()letincr_connect()=incrsingleton.tcp_connects;singleton.total_active_connections<-succsingleton.total_active_connections;metrics()letdecr_connect()=decrsingleton.tcp_connects;metrics()letincr_timer()=incrsingleton.tcp_timers;singleton.total_timers<-succsingleton.total_timers;metrics()letdecr_timer()=decrsingleton.tcp_timers;metrics()