Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
pip install flask
pip install requests
pip install vcrpy
pip install prometheus_client
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
108 changes: 108 additions & 0 deletions fixtures/vcr_cassettes/metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
interactions:
- request:
body: null
headers:
Accept:
- "*/*"
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: http://127.0.0.1:5000/metrics
response:
body:
string:
'# HELP python_gc_objects_collected_total Objects collected during gc

# TYPE python_gc_objects_collected_total counter

python_gc_objects_collected_total{generation="0"} 424.0

python_gc_objects_collected_total{generation="1"} 24.0

python_gc_objects_collected_total{generation="2"} 0.0

# HELP python_gc_objects_uncollectable_total Uncollectable objects found during
GC

# TYPE python_gc_objects_uncollectable_total counter

python_gc_objects_uncollectable_total{generation="0"} 0.0

python_gc_objects_uncollectable_total{generation="1"} 0.0

python_gc_objects_uncollectable_total{generation="2"} 0.0

# HELP python_gc_collections_total Number of times this generation was collected

# TYPE python_gc_collections_total counter

python_gc_collections_total{generation="0"} 33.0

python_gc_collections_total{generation="1"} 2.0

python_gc_collections_total{generation="2"} 0.0

# HELP python_info Python platform information

# TYPE python_info gauge

python_info{implementation="CPython",major="3",minor="13",patchlevel="1",version="3.13.1"}
1.0

# HELP process_virtual_memory_bytes Virtual memory size in bytes.

# TYPE process_virtual_memory_bytes gauge

process_virtual_memory_bytes 4.6829568e+07

# HELP process_resident_memory_bytes Resident memory size in bytes.

# TYPE process_resident_memory_bytes gauge

process_resident_memory_bytes 4.0833024e+07

# HELP process_start_time_seconds Start time of the process since unix epoch
in seconds.

# TYPE process_start_time_seconds gauge

process_start_time_seconds 1.74983991025e+09

# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.

# TYPE process_cpu_seconds_total counter

process_cpu_seconds_total 3.46

# HELP process_open_fds Number of open file descriptors.

# TYPE process_open_fds gauge

process_open_fds 6.0

# HELP process_max_fds Maximum number of open file descriptors.

# TYPE process_max_fds gauge

process_max_fds 1.048576e+06

'
headers:
Connection:
- close
Content-Length:
- "1893"
Content-Type:
- text/plain; version=0.0.4; charset=utf-8; charset=utf-8
Date:
- Fri, 13 Jun 2025 19:27:04 GMT
Server:
- Werkzeug/3.1.3 Python/3.13.1
status:
code: 200
message: OK
version: 1
8 changes: 7 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'''Module containing the main function of the app.'''
from flask import Flask
from flask import Flask, Response
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST
import opensense
#import test_main

Expand All @@ -19,6 +20,11 @@ def get_temperature():
'''Function to get the current temperature.'''
return opensense.get_temperature()

@app.route('/metrics')
def metrics():
'''Function to return Prometheus metrics.'''
return Response(generate_latest(), mimetype=CONTENT_TYPE_LATEST)

### Test module ###
# @app.route('/test')
# def test():
Expand Down
19 changes: 3 additions & 16 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
blinker==1.9.0
certifi==2025.1.31
charset-normalizer==3.4.1
click==8.1.8
DateTime==5.5
Flask==3.1.0
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.2
pytz==2025.1
requests==2.32.3
setuptools==76.1.0
urllib3==2.3.0
Werkzeug==3.1.3
zope.interface==7.2
Flask==3.1.1
requests==2.32.4
prometheus-client==0.22.1
Loading