Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
opensprinkler_prometheus_exporter
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
Service Desk
Analyze
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
varac-projects
opensprinkler_prometheus_exporter
Commits
3f8a9134
Verified
Commit
3f8a9134
authored
2 years ago
by
Varac
Browse files
Options
Downloads
Patches
Plain Diff
Initial commit
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
opensprinkler_exporter.py
+99
-0
99 additions, 0 deletions
opensprinkler_exporter.py
with
99 additions
and
0 deletions
opensprinkler_exporter.py
0 → 100755
+
99
−
0
View file @
3f8a9134
#!/usr/bin/env python3
"""
Prometheus exporter for opensprinkler metrics.
Exports Opensprinkler metrics that can get scraped by Prometheus.
See https://openthings.freshdesk.com/support/solutions/articles/5000716363-os-api-documents
for Opensprinkler API documentation and https://github.com/OpenSprinkler/OpenSprinkler-Weather
for the weather provider API (I couldn
'
t find any weather provider API docs)
Author: varac@varac.net
"""
import
json
import
logging
import
os
import
time
# from datetime import datetime
import
plac
import
requests
from
prometheus_client
import
start_http_server
,
Gauge
logging
.
basicConfig
()
log
=
logging
.
getLogger
(
__name__
)
# Initialize Prometheus instrumentation
wt_base_eto
=
Gauge
(
'
opensprinkler_wt_base_eto
'
,
'
Weather provider: BaseETo
'
)
wt_eto
=
Gauge
(
'
opensprinkler_wt_eto
'
,
'
Weather provider: ETo
'
)
wt_radiation
=
Gauge
(
'
opensprinkler_wt_radiation
'
,
'
Weather provider: radiation
'
)
wt_temp_min
=
Gauge
(
'
opensprinkler_wt_temp_min
'
,
'
Weather provider: min temperature
'
)
wt_temp_max
=
Gauge
(
'
opensprinkler_wt_temp_max
'
,
'
Weather provider: max temperature
'
)
wt_hum_min
=
Gauge
(
'
opensprinkler_wt_hum_min
'
,
'
Weather provider: min humidity
'
)
wt_hum_max
=
Gauge
(
'
opensprinkler_wt_hum_max
'
,
'
Weather provider: max humidity
'
)
wt_wind
=
Gauge
(
'
opensprinkler_wt_wind
'
,
'
Weather provider: wind speed
'
)
wt_p
=
Gauge
(
'
opensprinkler_wt_p
'
,
'
Weather provider: ?
'
)
def
main
():
"""
Start main function.
"""
# Setup logging
try
:
loglevel
=
getattr
(
logging
,
os
.
environ
.
get
(
'
LOGLEVEL
'
,
'
INFO
'
).
upper
())
except
AttributeError
:
pass
log
.
setLevel
(
level
=
loglevel
)
interval
=
int
(
os
.
environ
.
get
(
'
INTERVAL
'
,
60
))
PW
=
str
(
os
.
environ
[
'
OS_API_PW
'
])
API_URL
=
str
(
os
.
environ
[
'
OS_API_URL
'
],
'
http://localhost:8080
'
)
url
=
f
'
{
API_URL
}
/jc?pw=
{
PW
}
'
port
=
int
(
os
.
environ
.
get
(
'
PORT
'
,
3089
))
log
.
info
(
'
Starting prometheus exporter on port %s
'
,
str
(
port
))
log
.
info
(
url
)
start_http_server
(
port
)
while
True
:
try
:
req
=
requests
.
get
(
url
)
if
req
.
status_code
==
200
:
log
.
info
(
"
Success
"
)
j
=
json
.
loads
(
req
.
content
)
log
.
debug
(
j
)
wto
=
j
[
'
wto
'
]
wtdata
=
j
[
'
wtdata
'
]
wt_base_eto
.
set
(
wto
[
'
baseETo
'
])
wt_eto
.
set
(
wtdata
[
'
eto
'
])
wt_radiation
.
set
(
wtdata
[
'
radiation
'
])
wt_temp_min
.
set
(
wtdata
[
'
minT
'
])
wt_temp_max
.
set
(
wtdata
[
'
maxT
'
])
wt_hum_min
.
set
(
wtdata
[
'
minH
'
])
wt_hum_max
.
set
(
wtdata
[
'
maxH
'
])
wt_wind
.
set
(
wtdata
[
'
wind
'
])
wt_p
.
set
(
wtdata
[
'
p
'
])
else
:
log
.
info
(
req
.
status_code
)
log
.
info
(
req
.
content
)
except
KeyboardInterrupt
:
break
except
Exception
as
err
:
log
.
info
(
err
)
log
.
info
(
'
sleeping for %d seconds
'
,
interval
)
time
.
sleep
(
interval
)
if
__name__
==
'
__main__
'
:
plac
.
call
(
main
)
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