123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121(*
* 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())endtypet={mutabletcp_listens:int;mutabletcp_channels:int;mutabletcp_connects:int;mutabletcp_timers:int;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"t.tcp_listens;int"established state"t.tcp_channels;int"client connections"t.tcp_connects;int"timers"t.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"[%d|%d|%d|%d%a]"t.tcp_timerst.tcp_listenst.tcp_channelst.tcp_connectsGc.pp()letsingleton={tcp_listens=0;tcp_channels=0;tcp_connects=0;tcp_timers=0;total_timers=0;total_established=0;total_passive_connections=0;total_active_connections=0;}letmetrics()=Metrics.addmetrics(funx->x)(fund->dsingleton)letincr_listen()=singleton.tcp_listens<-succsingleton.tcp_listens;singleton.total_passive_connections<-succsingleton.total_passive_connections;metrics()letdecr_listen()=singleton.tcp_listens<-predsingleton.tcp_listens;metrics()letincr_channel()=singleton.tcp_channels<-succsingleton.tcp_channels;singleton.total_established<-succsingleton.total_established;metrics()letdecr_channel()=singleton.tcp_channels<-predsingleton.tcp_channels;metrics()letincr_connect()=singleton.tcp_connects<-succsingleton.tcp_connects;singleton.total_active_connections<-succsingleton.total_active_connections;metrics()letdecr_connect()=singleton.tcp_connects<-predsingleton.tcp_connects;metrics()letincr_timer()=singleton.tcp_timers<-succsingleton.tcp_timers;singleton.total_timers<-succsingleton.total_timers;metrics()letdecr_timer()=singleton.tcp_timers<-predsingleton.tcp_timers;metrics()