From 038edbdb3350c6d815eb3147aa27d2a00beebf88 Mon Sep 17 00:00:00 2001 From: Joris Beckers Date: Fri, 7 Jun 2019 13:01:43 +0200 Subject: [PATCH] Add queue length stats --- client/client.go | 32 +++++++++++++++++++++++++++++++- collector/collector.go | 10 ++++++++++ freeradius/freeradius.go | 6 ++++++ 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index ceae993..8a7360c 100644 --- a/client/client.go +++ b/client/client.go @@ -20,6 +20,7 @@ type Statistics struct { ProxyAuth Auth Accounting Accounting ProxyAccounting Accounting + Internal Internal } // Access type. @@ -51,6 +52,15 @@ type Accounting struct { UnknownTypes uint32 } +// Internal type. +type Internal struct { + QueueLenInternal uint32 + QueueLenProxy uint32 + QueueLenAuth uint32 + QueueLenAcct uint32 + QueueLenDetail uint32 +} + // FreeRADIUSClient fetches metrics from status server. type FreeRADIUSClient struct { addr string @@ -67,7 +77,7 @@ func NewFreeRADIUSClient(addr, secret string, timeout int) (*FreeRADIUSClient, e packet := radius.New(radius.CodeStatusServer, []byte(secret)) rfc2869.MessageAuthenticator_Set(packet, auth) - freeradius.SetValue(packet, freeradius.StatisticsType, radius.NewInteger(uint32(freeradius.StatisticsTypeAuthAcctProxyAuthAcct))) + freeradius.SetValue(packet, freeradius.StatisticsType, radius.NewInteger(uint32(freeradius.StatisticsTypeAll))) encode, err := packet.Encode() if err != nil { @@ -233,6 +243,26 @@ func (f *FreeRADIUSClient) Stats() (Statistics, error) { if err != nil { return stats, err } + stats.Internal.QueueLenInternal, err = freeradius.GetValue(response, freeradius.QueueLenInternal) + if err != nil { + return stats, err + } + stats.Internal.QueueLenProxy, err = freeradius.GetValue(response, freeradius.QueueLenProxy) + if err != nil { + return stats, err + } + stats.Internal.QueueLenAuth, err = freeradius.GetValue(response, freeradius.QueueLenAuth) + if err != nil { + return stats, err + } + stats.Internal.QueueLenAcct, err = freeradius.GetValue(response, freeradius.QueueLenAcct) + if err != nil { + return stats, err + } + stats.Internal.QueueLenDetail, err = freeradius.GetValue(response, freeradius.QueueLenDetail) + if err != nil { + return stats, err + } } return stats, nil diff --git a/collector/collector.go b/collector/collector.go index 92a5f4b..a40790d 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -55,6 +55,11 @@ func NewFreeRADIUSCollector(cl *client.FreeRADIUSClient) *FreeRADIUSCollector { "freeradius_total_proxy_acct_invalid_requests": prometheus.NewDesc("freeradius_total_proxy_acct_invalid_requests", "Total proxy acct invalid requests", nil, nil), "freeradius_total_proxy_acct_dropped_requests": prometheus.NewDesc("freeradius_total_proxy_acct_dropped_requests", "Total proxy acct dropped requests", nil, nil), "freeradius_total_proxy_acct_unknown_types": prometheus.NewDesc("freeradius_total_proxy_acct_unknown_types", "Total proxy acct unknown types", nil, nil), + "freeradius_queue_len_internal": prometheus.NewDesc("freeradius_queue_len_internal", "Interal queue length", nil, nil), + "freeradius_queue_len_proxy": prometheus.NewDesc("freeradius_queue_len_proxy", "Proxy queue length", nil, nil), + "freeradius_queue_len_auth": prometheus.NewDesc("freeradius_queue_len_auth", "Auth queue length", nil, nil), + "freeradius_queue_len_acct": prometheus.NewDesc("freeradius_queue_len_acct", "Acct queue length", nil, nil), + "freeradius_queue_len_detail": prometheus.NewDesc("freeradius_queue_len_detail", "Detail queue length", nil, nil), }, } } @@ -111,4 +116,9 @@ func (f *FreeRADIUSCollector) Collect(ch chan<- prometheus.Metric) { ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_total_proxy_acct_invalid_requests"], prometheus.CounterValue, float64(stats.ProxyAccounting.InvalidRequests)) ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_total_proxy_acct_dropped_requests"], prometheus.CounterValue, float64(stats.ProxyAccounting.DroppedRequests)) ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_total_proxy_acct_unknown_types"], prometheus.CounterValue, float64(stats.ProxyAccounting.UnknownTypes)) + ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_queue_len_internal"], prometheus.GaugeValue, float64(stats.Internal.QueueLenInternal)) + ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_queue_len_proxy"], prometheus.GaugeValue, float64(stats.Internal.QueueLenProxy)) + ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_queue_len_auth"], prometheus.GaugeValue, float64(stats.Internal.QueueLenAuth)) + ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_queue_len_acct"], prometheus.GaugeValue, float64(stats.Internal.QueueLenAcct)) + ch <- prometheus.MustNewConstMetric(f.metrics["freeradius_queue_len_detail"], prometheus.GaugeValue, float64(stats.Internal.QueueLenDetail)) } diff --git a/freeradius/freeradius.go b/freeradius/freeradius.go index df67e68..a55cb17 100644 --- a/freeradius/freeradius.go +++ b/freeradius/freeradius.go @@ -68,6 +68,12 @@ const ( TotalProxyAcctInvalidRequests = 159 TotalProxyAcctDroppedRequests = 160 TotalProxyAcctUnknownTypes = 161 + + QueueLenInternal = 162 + QueueLenProxy = 163 + QueueLenAuth = 164 + QueueLenAcct = 165 + QueueLenDetail = 166 ) // GetValue returns attribute value.