-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
platform collector - report details on python
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .platform import COLLECTOR_PLATFORM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import typing as t | ||
|
||
import sys | ||
|
||
import aioprometheus.collectors | ||
|
||
|
||
class CollectorPlatform(aioprometheus.collectors.Gauge): | ||
"""Collector for python platform information""" | ||
|
||
def __init__( | ||
self, | ||
registry: aioprometheus.collectors.Registry = None, | ||
): | ||
super().__init__( | ||
"python_info", "Python platform information", registry=registry | ||
) | ||
labels = self._labels() | ||
self.set_value(labels, 1) | ||
|
||
def _labels(self) -> t.Dict[str, str]: | ||
return { | ||
"version": sys.version, | ||
"implementation": sys.implementation.name, | ||
"major": str(sys.version_info.major), | ||
"minor": str(sys.version_info.minor), | ||
"patchlevel": str(sys.version_info.micro), | ||
"system": sys.platform, | ||
} | ||
|
||
|
||
COLLECTOR_PLATFORM = CollectorPlatform() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import unittest | ||
|
||
from aioprometheus.collectors import REGISTRY | ||
from aioprometheus.collector.platform import CollectorPlatform | ||
|
||
|
||
class TestCollectorPlatfrom(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls) -> None: | ||
REGISTRY.clear() | ||
|
||
def setUp(self) -> None: | ||
self.COLLECTOR_PLATFORM = CollectorPlatform() | ||
|
||
def tearDown(self): | ||
REGISTRY.clear() | ||
|
||
def test_python_info_is_present(self): | ||
REGISTRY.get(self.COLLECTOR_PLATFORM.name) | ||
self.assertIn("python_info", REGISTRY.collectors) | ||
|
||
def test_get(self): | ||
labels = self.COLLECTOR_PLATFORM._labels() | ||
self.assertEqual(self.COLLECTOR_PLATFORM.get(labels), 1) |