Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ansible-warpzone
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
infrastruktur
ansible-warpzone
Commits
0bb1fb5a
Commit
0bb1fb5a
authored
1 month ago
by
Christian Elberfeld
Browse files
Options
Downloads
Patches
Plain Diff
add metrics endpoint
parent
88884862
No related branches found
No related tags found
1 merge request
!148
Umbau von PiHole auf Kea DHCP und Bind
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dhcpdns/dhcpinfo/templates/app.py
+23
-0
23 additions, 0 deletions
dhcpdns/dhcpinfo/templates/app.py
with
23 additions
and
0 deletions
dhcpdns/dhcpinfo/templates/app.py
+
23
−
0
View file @
0bb1fb5a
...
@@ -258,6 +258,29 @@ def api_status():
...
@@ -258,6 +258,29 @@ def api_status():
"
timestamp
"
:
datetime
.
now
().
isoformat
()
"
timestamp
"
:
datetime
.
now
().
isoformat
()
}
}
@app.route
(
'
/metrics
'
)
def
metrics
():
"""
Prometheus Metrics Endpoint für Kea Statistiken
"""
kea_client
=
KeaDHCPClient
(
KEA_CONTROL_AGENT_URL
,
KEA_SERVICE
,
KEA_USERNAME
,
KEA_PASSWORD
)
stats_response
=
kea_client
.
get_statistics
()
output
=
[]
connection_ok
,
_
=
kea_client
.
test_connection
()
output
.
append
(
f
"
kea_connection_ok
{
1
if
connection_ok
else
0
}
"
)
# Lease-Anzahl ermitteln
lease_response
=
kea_client
.
get_all_leases
()
total_leases
=
0
if
lease_response
and
lease_response
[
0
].
get
(
"
result
"
)
==
0
:
lease_data
=
lease_response
[
0
].
get
(
"
arguments
"
,
{})
total_leases
=
len
(
lease_data
.
get
(
"
leases
"
,
[]))
output
.
append
(
f
"
kea_total_leases
{
total_leases
}
"
)
if
stats_response
and
stats_response
[
0
].
get
(
"
result
"
)
==
0
:
stats_data
=
stats_response
[
0
].
get
(
"
arguments
"
,
{})
for
stat_name
,
stat_values
in
stats_data
.
items
():
if
isinstance
(
stat_values
,
list
)
and
len
(
stat_values
)
>
0
:
value
=
stat_values
[
0
][
0
]
prom_name
=
stat_name
.
lower
().
replace
(
'
.
'
,
'
_
'
).
replace
(
'
-
'
,
'
_
'
).
replace
(
'
[
'
,
'
_
'
).
replace
(
'
]
'
,
''
)
output
.
append
(
f
"
kea_
{
prom_name
}
{
value
}
"
)
return
'
\n
'
.
join
(
output
)
+
'
\n
'
,
200
,
{
'
Content-Type
'
:
'
text/plain; version=0.0.4; charset=utf-8
'
}
# OpenAPI/Swagger-Konfiguration
# OpenAPI/Swagger-Konfiguration
app
.
config
.
update
({
app
.
config
.
update
({
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment