Skip to content

Commit

Permalink
Merge pull request #4 from jobec/internal-stats
Browse files Browse the repository at this point in the history
Add queue length stats
  • Loading branch information
gen2brain authored Jun 7, 2019
2 parents e55eb6d + 038edbd commit 8445d22
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
32 changes: 31 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Statistics struct {
ProxyAuth Auth
Accounting Accounting
ProxyAccounting Accounting
Internal Internal
}

// Access type.
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
}
Expand Down Expand Up @@ -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))
}
6 changes: 6 additions & 0 deletions freeradius/freeradius.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8445d22

Please sign in to comment.