Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8f9e0c852 |
@@ -61,6 +61,10 @@ metrics:
|
|||||||
The cluster state collector exposes `pve_cluster_mode`, where `1` means that
|
The cluster state collector exposes `pve_cluster_mode`, where `1` means that
|
||||||
Proxmox VE is configured as a cluster and `0` means that it is a standalone node.
|
Proxmox VE is configured as a cluster and `0` means that it is a standalone node.
|
||||||
|
|
||||||
|
The `pve_node_subscription_status` metric uses `0` when no subscription is
|
||||||
|
configured, `1` for an active subscription, and `2` for an expired or otherwise
|
||||||
|
unusable subscription.
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
To build the Docker image for PVE Exporter, use the following command:
|
To build the Docker image for PVE Exporter, use the following command:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func NewPveSubscriptionCollector(apiClient *proxmox.PveApiClient, registry *TTLR
|
|||||||
c.status = NewTTLGaugeVec(
|
c.status = NewTTLGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Name: "pve_node_subscription_status",
|
Name: "pve_node_subscription_status",
|
||||||
Help: "Node subscription status.",
|
Help: "Node subscription status (0 = not found, 1 = active, 2 = expired or otherwise unusable).",
|
||||||
},
|
},
|
||||||
[]string{"cluster", "node"},
|
[]string{"cluster", "node"},
|
||||||
5*time.Minute,
|
5*time.Minute,
|
||||||
@@ -111,7 +111,7 @@ func (c *PveSubscriptionCollector) CollectMetrics() error {
|
|||||||
c.info.With(subsLabels).Set(1)
|
c.info.With(subsLabels).Set(1)
|
||||||
|
|
||||||
// Subscription state.
|
// Subscription state.
|
||||||
c.status.With(labels).Set(subscription.GetActiveNumeric())
|
c.status.With(labels).Set(subscription.GetStatusNumeric())
|
||||||
|
|
||||||
// Subscription sockets count.
|
// Subscription sockets count.
|
||||||
c.sockets.With(labels).Set(float64(subscription.Sockets))
|
c.sockets.With(labels).Set(float64(subscription.Sockets))
|
||||||
|
|||||||
+11
-6
@@ -430,13 +430,18 @@ func (r *PveSdnResource) GetStatusNumeric() float64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetActiveNumeric returns the numeric state of a subscription.
|
// GetStatusNumeric returns the numeric state of a subscription.
|
||||||
// Returns 1 if the subscription status is "active", otherwise returns 0.
|
// A missing subscription is 0, an active subscription is 1, and an expired
|
||||||
func (r *PveSubscription) GetActiveNumeric() float64 {
|
// or otherwise unusable subscription is 2.
|
||||||
if r.Status == "active" {
|
func (r *PveSubscription) GetStatusNumeric() float64 {
|
||||||
return 1
|
switch r.Status {
|
||||||
}
|
case "notfound":
|
||||||
return 0
|
return 0
|
||||||
|
case "active":
|
||||||
|
return 1
|
||||||
|
default:
|
||||||
|
return 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSmartPassedState returns the numeric health state of a disk.
|
// GetSmartPassedState returns the numeric health state of a disk.
|
||||||
|
|||||||
@@ -28,3 +28,27 @@ func TestPveClusterStatusGetClusterModeNumeric(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPveSubscriptionGetStatusNumeric(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
status string
|
||||||
|
want float64
|
||||||
|
}{
|
||||||
|
{status: "notfound", want: 0},
|
||||||
|
{status: "active", want: 1},
|
||||||
|
{status: "expired", want: 2},
|
||||||
|
{status: "invalid", want: 2},
|
||||||
|
{status: "suspended", want: 2},
|
||||||
|
{status: "new", want: 2},
|
||||||
|
{status: "unknown", want: 2},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.status, func(t *testing.T) {
|
||||||
|
subscription := PveSubscription{Status: tt.status}
|
||||||
|
if got := subscription.GetStatusNumeric(); got != tt.want {
|
||||||
|
t.Fatalf("GetStatusNumeric() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user