From bb276fc8edbf9d2fe074a279b99d36468f5b77fa Mon Sep 17 00:00:00 2001 From: Raf Nijskens Date: Mon, 2 Oct 2023 18:08:20 -0500 Subject: [PATCH 1/2] issue 26: support openvpnas 2.12 --- exporters/openvpnas_exporter.go | 53 ++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/exporters/openvpnas_exporter.go b/exporters/openvpnas_exporter.go index f12a9bf..f270ed1 100644 --- a/exporters/openvpnas_exporter.go +++ b/exporters/openvpnas_exporter.go @@ -31,6 +31,7 @@ type OpenVPNExporter struct { openvpnSubscriptionFallbackClientConnections *prometheus.Desc openvpnSubscriptionMaximumClientConnections *prometheus.Desc openvpnConnectedClientsDesc *prometheus.Desc + openvpnSubscriptionTotalClientConnections *prometheus.Desc } func NewOpenVPNExporter(xmlrpcPath string) (*OpenVPNExporter, error) { @@ -61,6 +62,10 @@ func NewOpenVPNExporter(xmlrpcPath string) (*OpenVPNExporter, error) { prometheus.BuildFQName("openvpnas", "", "subscription_fallback_client_connections"), "Number of fallback connections in use on the OpenVPN subscription.", nil, nil) + openvpnSubscriptionTotalClientConnectionsDesc := prometheus.NewDesc( + prometheus.BuildFQName("openvpnas", "", "subscription_total_client_connections"), + "Number of total connections in use on the OpenVPN subscription.", + nil, nil) openvpnSubscriptionMaximumClientConnectionsDesc := prometheus.NewDesc( prometheus.BuildFQName("openvpnas", "", "subscription_maximum_client_connections"), "Maximum number of client connections allowed by the OpenVPN subscription.", @@ -75,6 +80,7 @@ func NewOpenVPNExporter(xmlrpcPath string) (*OpenVPNExporter, error) { openvpnSubscriptionCurrentClientConnections: openvpnSubscriptionCurrentClientConnectionsDesc, openvpnSubscriptionFallbackClientConnections: openvpnSubscriptionFallbackClientConnectionsDesc, openvpnSubscriptionMaximumClientConnections: openvpnSubscriptionMaximumClientConnectionsDesc, + openvpnSubscriptionTotalClientConnections: openvpnSubscriptionTotalClientConnectionsDesc, }, nil } @@ -97,7 +103,6 @@ func (e *OpenVPNExporter) Collect(ch chan<- prometheus.Metric) { client, _ := xmlrpc.NewClient("http://localhost/", opts...) defer client.Close() - err := e.CollectVPNSummary(*client, ch) if err != nil { ch <- prometheus.MustNewConstMetric( @@ -126,7 +131,9 @@ func (e *OpenVPNExporter) Collect(ch chan<- prometheus.Metric) { func (e *OpenVPNExporter) CollectVPNSummary(client xmlrpc.Client, ch chan<- prometheus.Metric) error { result := &struct { VPNSummary struct { - NClients int `xml:"n_clients"` + NClients int `xml:"n_clients"` + OvpnDcoVer string `xml:"ovpn_dco_ver"` + OvpnDcoAvailable bool `xml:"ovpn_dco_available"` } }{} @@ -147,25 +154,24 @@ func (e *OpenVPNExporter) CollectVPNSummary(client xmlrpc.Client, ch chan<- prom func (e *OpenVPNExporter) CollectSubscriptionStatistics(client xmlrpc.Client, ch chan<- prometheus.Metric) error { result := &struct { SubscriptionStatus struct { - AgentDisabled bool `xml:"agent_disabled"` - AgentId string `xml:"agent_id"` - CcLimit int `xml:"cc_limit"` - CurrentCc int `xml:"current_cc"` - Error string `xml:"error"` - FallbackCc int `xml:"fallback_cc"` - GracePeriod int `xml:"grace_period"` - LastSuccessfulUpdate int `xml:"last_successful_update"` - LastSuccessfulUpdateAge int `xml:"last_successful_update_age"` - MaxCc int `xml:"max_cc"` - Name string `xml:"name"` - NextUpdate int `xml:"next_update"` - NextUpdateIn int `xml:"next_update_in"` - Notes []string `xml:"notes"` - Overdraft bool `xml:"overdraft"` - Server string `xml:"server"` - State string `xml:"state"` - Type string `xml:"type"` - UpdatesFailed int `xml:"updates_failed"` + AgentDisabled bool `xml:"agent_disabled"` + AgentId string `xml:"agent_id"` + CcLimit int `xml:"cc_limit"` + CurrentCc int `xml:"current_cc"` + Error string `xml:"error"` + FallbackCc int `xml:"fallback_cc"` + GracePeriod int `xml:"grace_period"` + LastSuccessfulUpdate int `xml:"last_successful_update"` + MaxCc int `xml:"max_cc"` + Name string `xml:"name"` + NextUpdate int `xml:"next_update"` + Notes []string `xml:"notes"` + Overdraft bool `xml:"overdraft"` + Server string `xml:"server"` + State string `xml:"state"` + TotalCc int `xml:"total_cc"` + Type string `xml:"type"` + UpdatesFailed int `xml:"updates_failed"` } }{} @@ -195,5 +201,10 @@ func (e *OpenVPNExporter) CollectSubscriptionStatistics(client xmlrpc.Client, ch prometheus.GaugeValue, float64(result.SubscriptionStatus.FallbackCc)) + ch <- prometheus.MustNewConstMetric( + e.openvpnSubscriptionTotalClientConnections, + prometheus.GaugeValue, + float64(result.SubscriptionStatus.TotalCc)) + return nil } From 4b9b1d4a60357d0ead1394b976337f414a9b1268 Mon Sep 17 00:00:00 2001 From: Raf Nijskens Date: Tue, 3 Oct 2023 10:54:30 -0500 Subject: [PATCH 2/2] keep all fields and add comments --- exporters/openvpnas_exporter.go | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/exporters/openvpnas_exporter.go b/exporters/openvpnas_exporter.go index f270ed1..966f31b 100644 --- a/exporters/openvpnas_exporter.go +++ b/exporters/openvpnas_exporter.go @@ -128,6 +128,7 @@ func (e *OpenVPNExporter) Collect(ch chan<- prometheus.Metric) { 1.0) } +// Get all fields by running: /usr/local/openvpn_as/scripts# OPENVPN_AS_DEBUG_XML=1 ./sacli VPNSummary func (e *OpenVPNExporter) CollectVPNSummary(client xmlrpc.Client, ch chan<- prometheus.Metric) error { result := &struct { VPNSummary struct { @@ -151,27 +152,30 @@ func (e *OpenVPNExporter) CollectVPNSummary(client xmlrpc.Client, ch chan<- prom return nil } +// Get all fields by running: /usr/local/openvpn_as/scripts# OPENVPN_AS_DEBUG_XML=1 ./sacli SubscriptionStatus func (e *OpenVPNExporter) CollectSubscriptionStatistics(client xmlrpc.Client, ch chan<- prometheus.Metric) error { result := &struct { SubscriptionStatus struct { - AgentDisabled bool `xml:"agent_disabled"` - AgentId string `xml:"agent_id"` - CcLimit int `xml:"cc_limit"` - CurrentCc int `xml:"current_cc"` - Error string `xml:"error"` - FallbackCc int `xml:"fallback_cc"` - GracePeriod int `xml:"grace_period"` - LastSuccessfulUpdate int `xml:"last_successful_update"` - MaxCc int `xml:"max_cc"` - Name string `xml:"name"` - NextUpdate int `xml:"next_update"` - Notes []string `xml:"notes"` - Overdraft bool `xml:"overdraft"` - Server string `xml:"server"` - State string `xml:"state"` - TotalCc int `xml:"total_cc"` - Type string `xml:"type"` - UpdatesFailed int `xml:"updates_failed"` + AgentDisabled bool `xml:"agent_disabled"` + AgentId string `xml:"agent_id"` + CcLimit int `xml:"cc_limit"` + CurrentCc int `xml:"current_cc"` + Error string `xml:"error"` + FallbackCc int `xml:"fallback_cc"` + GracePeriod int `xml:"grace_period"` + LastSuccessfulUpdate int `xml:"last_successful_update"` + LastSuccessfulUpdateAge int `xml:"last_successful_update_age"` + MaxCc int `xml:"max_cc"` + Name string `xml:"name"` + NextUpdate int `xml:"next_update"` + NextUpdateIn int `xml:"next_update_in"` + Notes []string `xml:"notes"` + Overdraft bool `xml:"overdraft"` + Server string `xml:"server"` + State string `xml:"state"` + TotalCc int `xml:"total_cc"` + Type string `xml:"type"` + UpdatesFailed int `xml:"updates_failed"` } }{}