<commit_before>package rabbitmonit

import (
	"github.com/c-datculescu/rabbit-hole"
)

type VhostProperties struct {
	VhostInfo rabbithole.VhostInfo
	Error     VhostAlert
	Warning   VhostAlert
}

type VhostAlert struct {
	Rdy bool // are there ready messages available
	Has bool // do we have any errors
}

func (vp *VhostProperties) Calculate() {
	vp.Error = VhostAlert{}
	vp.Warning = VhostAlert{}

	vp.alertRdy()
}

func (vp *VhostProperties) alertRdy() {
	if vp.VhostInfo.MessagesRdy > 1000 {
		vp.Error.Has = true
		vp.Error.Rdy = true
	} else if vp.VhostInfo.MessagesRdy > 0 {
		vp.Warning.Has = true
		vp.Warning.Rdy = true
	}
}<commit_msg>Added statistics for in/out rate<commit_after>package rabbitmonit

import (
	"github.com/c-datculescu/rabbit-hole"
)

type VhostProperties struct {
	VhostInfo rabbithole.VhostInfo
	Error     VhostAlert
	Warning   VhostAlert
	Stats     VhostStats
}

type VhostStats struct {
	EnqueueDequeueDiff float32
}

type VhostAlert struct {
	Rdy            bool // are there ready messages available
	Has            bool // do we have any errors
	ConsumptionLow bool // the enqueue rate is bigger than the dequeue rate
}

func (vp *VhostProperties) Calculate() {
	vp.Error = VhostAlert{}
	vp.Warning = VhostAlert{}
	vp.Stats = VhostStats{}

	vp.alertRdy().
		alertConsumptionLow()
}

func (vp *VhostProperties) alertRdy() *VhostProperties {
	if vp.VhostInfo.MessagesRdy > 1000 {
		vp.Error.Has = true
		vp.Error.Rdy = true
	} else if vp.VhostInfo.MessagesRdy > 0 {
		vp.Warning.Has = true
		vp.Warning.Rdy = true
	}

	return vp
}

func (vp *VhostProperties) alertConsumptionLow() *VhostProperties {
	rate := vp.VhostInfo.MessageStats.PublishDetails.Rate - vp.VhostInfo.MessageStats.DeliverDetails.Rate
	vp.Stats.EnqueueDequeueDiff = rate
	lowerThan := vp.VhostInfo.MessageStats.DeliverDetails.Rate < vp.VhostInfo.MessageStats.PublishDetails.Rate
	if lowerThan && rate > 10 {
		vp.Error.Has = true
		vp.Error.ConsumptionLow = true
	} else if lowerThan && rate > 5 {
		vp.Warning.Has = true
		vp.Warning.ConsumptionLow = true
	}

	return vp
}
{'fraction_non_alphanumeric': 0.09826589595375723, 'fraction_numerical': 0.0072254335260115606, 'mean_word_length': 3.6779279279279278, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5667322', 'n_tokens_mistral': 772, 'n_tokens_neox': 727, 'n_words': 176}