-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide auto registration facility for collectors (#18)
To provide more than one simple collector we refactor the registration of collectors to do this automatically. From now all collectors that follows the convention for new collectors. We also add a real life collector for load average (1, 5, 15). Finally we prepare the new major release.
- Loading branch information
Showing
11 changed files
with
109 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[bumpversion] | ||
commit = True | ||
tag = False | ||
current_version = 0.1.0 | ||
current_version = 1.0.0 | ||
|
||
[bumpversion:file:setup.py] |
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
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
exporter_name: "Python prammable Prometheus exporter" | ||
collectors: | ||
- loadavg | ||
- my | ||
credentials: |
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
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,20 @@ | ||
import os | ||
|
||
from p3exporter.collector import CollectorConfig | ||
from prometheus_client.core import GaugeMetricFamily | ||
|
||
class LoadavgCollector(object): | ||
|
||
def __init__(self, config: CollectorConfig): | ||
"""Instanciate a CpuCollector object.""" | ||
pass | ||
|
||
def collect(self): | ||
"""Collect load avg for 1, 5 and 15 minutes interval. | ||
Returns three gauge metrics. One for each load. | ||
""" | ||
self.avg1, self.avg5, self.avg15 = os.getloadavg() | ||
yield GaugeMetricFamily('load_avg_1', "1m load average.", value=self.avg1) | ||
yield GaugeMetricFamily('load_avg_5', "5m load average.", value=self.avg5) | ||
yield GaugeMetricFamily('load_avg_15', "15m load average.", value=self.avg15) |
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,26 @@ | ||
import random | ||
import time | ||
|
||
from p3exporter.collector import CollectorConfig | ||
from prometheus_client.core import GaugeMetricFamily | ||
|
||
class MyCollector(object): | ||
"""A sample collector. | ||
It does not really do much. It only runs a method and return the time it runs as a gauge metric. | ||
""" | ||
|
||
def __init__(self, config: CollectorConfig): | ||
"""Instanciate a MyCollector object.""" | ||
pass | ||
|
||
def collect(self): | ||
"""Collect the metrics.""" | ||
self.timer = time.perf_counter() | ||
_run_process() | ||
runtime = time.perf_counter() - self.timer | ||
yield GaugeMetricFamily('my_process_runtime', 'Time a process runs in seconds', value=runtime) | ||
|
||
def _run_process(): | ||
"""Sample function to ran a command for metrics.""" | ||
time.sleep(random.random()) # nosec |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ flake8 | |
flake8-colors | ||
flake8-docstrings | ||
flask | ||
inflection | ||
twine | ||
setuptools | ||
PyYAML | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
inflection | ||
prometheus-client | ||
PyYAML | ||
flask |
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