Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pve_exporter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def main():
clusterflags.add_argument('--collector.version', dest='collector_version',
action=BooleanOptionalAction, default=True,
help='Exposes PVE version info')
clusterflags.add_argument('--collector.subscription', dest='collector_subscription',
action=BooleanOptionalAction, default=True,
help='Exposes PVE subscription info')
Copy link
Member

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).

clusterflags.add_argument('--collector.node', dest='collector_node',
action=BooleanOptionalAction, default=True,
help='Exposes PVE node info')
Expand Down Expand Up @@ -70,6 +73,7 @@ def main():
collectors = CollectorsOptions(
status=params.collector_status,
version=params.collector_version,
subscription=params.collector_subscription,
node=params.collector_node,
cluster=params.collector_cluster,
resources=params.collector_resources,
Expand Down
6 changes: 5 additions & 1 deletion src/pve_exporter/collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
ClusterResourcesCollector,
ClusterNodeCollector,
VersionCollector,
ClusterInfoCollector
ClusterInfoCollector,
SubscriptionCollector
)
from pve_exporter.collector.node import (
NodeConfigCollector,
Expand All @@ -22,6 +23,7 @@
CollectorsOptions = collections.namedtuple('CollectorsOptions', [
'status',
'version',
'subscription',
'node',
'cluster',
'resources',
Expand All @@ -46,6 +48,8 @@ def collect_pve(config, host, cluster, node, options: CollectorsOptions):
registry.register(ClusterInfoCollector(pve))
if cluster and options.version:
registry.register(VersionCollector(pve))
if cluster and options.subscription:
registry.register(SubscriptionCollector(pve))
if node and options.config:
registry.register(NodeConfigCollector(pve))
if node and options.replication:
Expand Down
46 changes: 46 additions & 0 deletions src/pve_exporter/collector/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import itertools
import typing
from datetime import datetime

from prometheus_client.core import GaugeMetricFamily

Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is iterating through nodes. Therefore it should go into node metrics, not cluster metrics.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally fair. I moved the implementation to node.py and reset cluster.py to its previous state.

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.:
Expand Down