-
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 4 commits
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 logging | ||
| import itertools | ||
| from datetime import datetime | ||
|
|
||
| from prometheus_client.core import GaugeMetricFamily | ||
|
|
||
|
|
@@ -126,3 +127,51 @@ def collect(self): # pylint: disable=missing-docstring | |
| metrics[key].add_metric(label_values, metric_value) | ||
|
|
||
| return itertools.chain(metrics.values(), info_metrics.values()) | ||
|
|
||
| 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 | ||
| info_metric = GaugeMetricFamily( | ||
| "pve_subscription_info", | ||
| "Proxmox VE subscription info (1 if present)", | ||
| labels=["node", "level", "status"], | ||
| ) | ||
|
Comment on lines
140
to
151
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to be able to alert on the subscription It looks like the subscription status is an enum with the following options: new notfound active invalid expired suspended. Thus, the metrics could maybe look more like this: Alerting could then be done on |
||
|
|
||
| next_due_metric = GaugeMetricFamily( | ||
| "pve_subscription_next_due_timestamp", | ||
|
||
| "Subscription next due date as Unix timestamp", | ||
| labels=["node", "level"], | ||
| ) | ||
|
|
||
| node = None | ||
| for entry in self._pve.cluster.status.get(): | ||
| if entry['type'] == 'node' and entry['local']: | ||
| node = entry['name'] | ||
| break | ||
|
|
||
| subscription = self._pve.nodes(node).subscription.get() | ||
|
|
||
| level = subscription.get("level", "unknown") | ||
| status = subscription.get("status", "unknown") | ||
|
|
||
| info_metric.add_metric( | ||
| [node, 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, level], | ||
| timestamp, | ||
| ) | ||
|
|
||
| yield info_metric | ||
| yield next_due_metric | ||
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).