Skip to content

Commit

Permalink
Merge pull request #42 from rokett/dev
Browse files Browse the repository at this point in the history
Added AAA stats
  • Loading branch information
rokett authored Jul 25, 2020
2 parents 0a70835 + a561523 commit 5fffc16
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 8 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [4.5.0] - 2020-07-25
- #41 Added the following AAA metrics.
- aaa_auth_success
- aaa_auth_fail
- aaa_auth_only_http_success
- aaa_auth_only_http_fail
- aaa_current_ica_sessions
- aaa_current_ica_only_connections

## [4.4.0] - 2020-07-02
### Added
- #37 Added LBVS and GSLB VS state metric.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: build

APP = Citrix-NetScaler-Exporter
VERSION = 4.4.0
VERSION = 4.5.0
BINARY-LINUX = ${APP}_${VERSION}_Linux_amd64

BUILD_VER = $(shell git rev-parse HEAD)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ For each Content Switching virtual server, the following metrics are retrieved.
| Current multipath sessions | Gauge | None |
| Current multipath subflow connections | Gauge | None |
## AAA
| Metric | Metric Type | Unit |
| -----------------------------| ----------- | ---- |
| Auth Successes | Counter | None |
| Auth Failures | Counter | None |
| Auth Only HTTP Successes | Counter | None |
| Auth Only HTTP Faliures | Counter | None |
| Current ICA Sessions | Counter | None |
| Current ICA Only Connections | Counter | None |
## Downloading a release
<https://github.com/rokett/Citrix-NetScaler-Exporter/releases>
Expand Down
113 changes: 113 additions & 0 deletions collector/aaa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package collector

import (
"strconv"

"citrix-netscaler-exporter/netscaler"

"github.com/prometheus/client_golang/prometheus"
)

var (
aaaAuthSuccess = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "aaa_auth_success",
Help: "Count of authentication successes",
},
[]string{
"ns_instance",
},
)

aaaAuthFail = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "aaa_auth_fail",
Help: "Count of authentication failures",
},
[]string{
"ns_instance",
},
)

aaaAuthOnlyHTTPSuccess = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "aaa_auth_only_http_success",
Help: "Count of HTTP connections that succeeded authorisation",
},
[]string{
"ns_instance",
},
)

aaaAuthOnlyHTTPFail = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "aaa_auth_only_http_fail",
Help: "Count of HTTP connections that failed authorisation",
},
[]string{
"ns_instance",
},
)

aaaCurIcaSessions = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "aaa_current_ica_sessions",
Help: "Count of current Basic ICA only sessions",
},
[]string{
"ns_instance",
},
)

aaaCurIcaOnlyConn = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "aaa_current_ica_only_connections",
Help: "Count of current Basic ICA only connections",
},
[]string{
"ns_instance",
},
)
)

func (e *Exporter) collectAaaAuthSuccess(ns netscaler.NSAPIResponse) {
e.aaaAuthSuccess.Reset()

val, _ := strconv.ParseFloat(ns.AAAStats.AuthSuccess, 64)
e.aaaAuthSuccess.WithLabelValues(e.nsInstance).Set(val)
}

func (e *Exporter) collectAaaAuthFail(ns netscaler.NSAPIResponse) {
e.aaaAuthFail.Reset()

val, _ := strconv.ParseFloat(ns.AAAStats.AuthFail, 64)
e.aaaAuthFail.WithLabelValues(e.nsInstance).Set(val)
}

func (e *Exporter) collectAaaAuthOnlyHTTPSuccess(ns netscaler.NSAPIResponse) {
e.aaaAuthOnlyHTTPSuccess.Reset()

val, _ := strconv.ParseFloat(ns.AAAStats.AuthOnlyHTTPSuccess, 64)
e.aaaAuthOnlyHTTPSuccess.WithLabelValues(e.nsInstance).Set(val)
}

func (e *Exporter) collectAaaAuthOnlyHTTPFail(ns netscaler.NSAPIResponse) {
e.aaaAuthOnlyHTTPFail.Reset()

val, _ := strconv.ParseFloat(ns.AAAStats.AuthOnlyHTTPFail, 64)
e.aaaAuthOnlyHTTPFail.WithLabelValues(e.nsInstance).Set(val)
}

func (e *Exporter) collectAaaCurIcaSessions(ns netscaler.NSAPIResponse) {
e.aaaCurIcaSessions.Reset()

val, _ := strconv.ParseFloat(ns.AAAStats.CurrentIcaSessions, 64)
e.aaaCurIcaSessions.WithLabelValues(e.nsInstance).Set(val)
}

func (e *Exporter) collectAaaCurIcaOnlyConn(ns netscaler.NSAPIResponse) {
e.aaaCurIcaOnlyConn.Reset()

val, _ := strconv.ParseFloat(ns.AAAStats.CurrentIcaOnlyConnections, 64)
e.aaaCurIcaOnlyConn.WithLabelValues(e.nsInstance).Set(val)
}
23 changes: 23 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
level.Error(e.logger).Log("msg", err)
}

aaa, err := netscaler.GetAAAStats(nsClient, "")
if err != nil {
level.Error(e.logger).Log("msg", err)
}

fltModelID, _ := strconv.ParseFloat(nslicense.NSLicense.ModelID, 64)

fltTotRxMB, _ := strconv.ParseFloat(ns.NSStats.TotalReceivedMB, 64)
Expand Down Expand Up @@ -375,6 +380,24 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.collectVPNVirtualServerState(vpnVirtualServers)
e.vpnVirtualServersState.Collect(ch)

e.collectAaaAuthSuccess(aaa)
e.aaaAuthSuccess.Collect(ch)

e.collectAaaAuthFail(aaa)
e.aaaAuthFail.Collect(ch)

e.collectAaaAuthOnlyHTTPSuccess(aaa)
e.aaaAuthOnlyHTTPSuccess.Collect(ch)

e.collectAaaAuthOnlyHTTPFail(aaa)
e.aaaAuthOnlyHTTPFail.Collect(ch)

e.collectAaaCurIcaSessions(aaa)
e.aaaCurIcaSessions.Collect(ch)

e.collectAaaCurIcaOnlyConn(aaa)
e.aaaCurIcaOnlyConn.Collect(ch)

servicegroups, err := netscaler.GetServiceGroups(nsClient, "attrs=servicegroupname")
if err != nil {
level.Error(e.logger).Log("msg", err)
Expand Down
19 changes: 19 additions & 0 deletions collector/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ type Exporter struct {
vpnVirtualServersTotalRequestBytes *prometheus.CounterVec
vpnVirtualServersTotalResponseBytes *prometheus.CounterVec
vpnVirtualServersState *prometheus.GaugeVec
aaaAuthSuccess *prometheus.CounterVec
aaaAuthFail *prometheus.CounterVec
aaaAuthOnlyHTTPSuccess *prometheus.CounterVec
aaaAuthOnlyHTTPFail *prometheus.CounterVec
aaaCurIcaSessions *prometheus.CounterVec
aaaCurIcaOnlyConn *prometheus.CounterVec
username string
password string
url string
Expand Down Expand Up @@ -243,6 +249,12 @@ func NewExporter(url string, username string, password string, ignoreCert bool,
vpnVirtualServersTotalRequestBytes: vpnVirtualServersTotalRequestBytes,
vpnVirtualServersTotalResponseBytes: vpnVirtualServersTotalResponseBytes,
vpnVirtualServersState: vpnVirtualServersState,
aaaAuthSuccess: aaaAuthSuccess,
aaaAuthFail: aaaAuthFail,
aaaAuthOnlyHTTPSuccess: aaaAuthOnlyHTTPSuccess,
aaaAuthOnlyHTTPFail: aaaAuthOnlyHTTPFail,
aaaCurIcaSessions: aaaCurIcaSessions,
aaaCurIcaOnlyConn: aaaCurIcaOnlyConn,
username: username,
password: password,
url: url,
Expand Down Expand Up @@ -367,4 +379,11 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.vpnVirtualServersTotalRequestBytes.Describe(ch)
e.vpnVirtualServersTotalResponseBytes.Describe(ch)
e.vpnVirtualServersState.Describe(ch)

e.aaaAuthSuccess.Describe(ch)
e.aaaAuthFail.Describe(ch)
e.aaaAuthOnlyHTTPSuccess.Describe(ch)
e.aaaAuthOnlyHTTPFail.Describe(ch)
e.aaaCurIcaSessions.Describe(ch)
e.aaaCurIcaOnlyConn.Describe(ch)
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ require (
github.com/prometheus/client_model v0.0.0-20170216185247-6f3806018612 // indirect
github.com/prometheus/common v0.0.0-20171006141418-1bab55dd05db // indirect
github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8 // indirect
github.com/rokett/citrix-netscaler-exporter v0.0.0-20200702205428-732ed26d0330
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ github.com/prometheus/common v0.0.0-20171006141418-1bab55dd05db h1:PmL7nSW2mvuot
github.com/prometheus/common v0.0.0-20171006141418-1bab55dd05db/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8 h1:Kh7M6mzRpQ2de1rixoSQZr4BTINXFm8WDbeN5ttnwyE=
github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rokett/citrix-netscaler-exporter v0.0.0-20200702205428-732ed26d0330 h1:15BVklRUaRQDK7Kx5SQwezMo704umalkhu1tcR3mMoM=
github.com/rokett/citrix-netscaler-exporter v0.0.0-20200702205428-732ed26d0330/go.mod h1:Jg3dOB2VWYEnPyuIU6X+WAEz9hiXLt0hnr/efhcgJrU=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2 changes: 1 addition & 1 deletion make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SETLOCAL

set APP=Citrix-NetScaler-Exporter
set VERSION=4.4.0
set VERSION=4.5.0
set BINARY-WINDOWS-X64=%APP%_%VERSION%_Windows_amd64.exe
set BINARY-LINUX=%APP%_%VERSION%_Linux_amd64

Expand Down
34 changes: 34 additions & 0 deletions netscaler/get_aaa_stats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package netscaler

import (
"encoding/json"

"github.com/pkg/errors"
)

// AAAStats represents the data returned from the /stat/aaa Nitro API endpoint
type AAAStats struct {
AuthSuccess string `json:"aaaauthsuccess"`
AuthFail string `json:"aaaauthfail"`
AuthOnlyHTTPSuccess string `json:"aaaauthonlyhttpsuccess"`
AuthOnlyHTTPFail string `json:"aaaauthonlyhttpfail"`
CurrentIcaSessions string `json:"aaacuricasessions"`
CurrentIcaOnlyConnections string `json:"aaacuricaonlyconn"`
}

// GetAAAStats queries the Nitro API for AAA stats
func GetAAAStats(c *NitroClient, querystring string) (NSAPIResponse, error) {
stats, err := c.GetStats("aaa", querystring)
if err != nil {
return NSAPIResponse{}, err
}

var response = new(NSAPIResponse)

err = json.Unmarshal(stats, &response)
if err != nil {
return NSAPIResponse{}, errors.Wrap(err, "error unmarshalling response body")
}

return *response, nil
}
1 change: 1 addition & 0 deletions netscaler/nsapiresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type NSAPIResponse struct {
GSLBVirtualServerStats []GSLBVirtualServerStats `json:"gslbvserver"`
CSVirtualServerStats []CSVirtualServerStats `json:"csvserver"`
VPNVirtualServerStats []VPNVirtualServerStats `json:"vpnvserver"`
AAAStats AAAStats `json:"aaa"`
}
3 changes: 0 additions & 3 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,3 @@ github.com/prometheus/common/model
# github.com/prometheus/procfs v0.0.0-20170703101242-e645f4e5aaa8
github.com/prometheus/procfs
github.com/prometheus/procfs/xfs
# github.com/rokett/citrix-netscaler-exporter v0.0.0-20200702205428-732ed26d0330
github.com/rokett/citrix-netscaler-exporter/collector
github.com/rokett/citrix-netscaler-exporter/netscaler

0 comments on commit 5fffc16

Please sign in to comment.