-
Notifications
You must be signed in to change notification settings - Fork 125
Add subscription collector and CLI flag for PVE subscription info #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
8a039b2
43a09a1
fd58678
6eb6d6a
87ecf94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| import itertools | ||
| import typing | ||
| from datetime import datetime | ||
|
|
||
| from prometheus_client.core import GaugeMetricFamily | ||
|
|
||
|
|
@@ -80,6 +81,51 @@ def collect(self): # pylint: disable=missing-docstring | |
| yield metric | ||
|
|
||
|
|
||
| class SubscriptionCollector: | ||
| """ | ||
| Collects Proxmox VE subscription information (node, subscription level, status, next due date). | ||
| """ | ||
|
|
||
| def __init__(self, pve): | ||
| self._pve = pve | ||
|
|
||
| def collect(self): # pylint: disable=missing-docstring | ||
| nodes = [node for node in self._pve.cluster.status.get() if node['type'] == 'node'] | ||
|
|
||
| info_metric = GaugeMetricFamily( | ||
| "pve_subscription_info", | ||
| "Proxmox VE subscription info (1 if present)", | ||
| labels=["node", "level", "status"], | ||
| ) | ||
|
|
||
| next_due_metric = GaugeMetricFamily( | ||
| "pve_subscription_next_due_timestamp", | ||
| "Subscription next due date as Unix timestamp", | ||
| labels=["node", "level"], | ||
| ) | ||
|
|
||
| for node in nodes: | ||
|
||
| subscription = self._pve.nodes(node['name']).subscription.get() | ||
|
|
||
| level = subscription.get("level", "unknown") | ||
| status = subscription.get("status", "unknown") | ||
|
|
||
| info_metric.add_metric( | ||
| [node["name"], level, status], | ||
| 1, | ||
| ) | ||
|
|
||
| next_due_date = subscription.get("nextduedate") | ||
| if next_due_date: | ||
| timestamp = datetime.strptime(next_due_date, "%Y-%m-%d").timestamp() | ||
| next_due_metric.add_metric( | ||
| [node["name"], level], | ||
| timestamp, | ||
| ) | ||
|
|
||
| yield info_metric | ||
| yield next_due_metric | ||
|
|
||
| class ClusterNodeCollector: | ||
| """ | ||
| Collects Proxmox VE cluster node information. E.g.: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block should be moved to
nodeflags(further down).