add metrics
This commit is contained in:
parent
b47a33636a
commit
5d00dcdf47
1 changed files with 26 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
|||
import sys
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import json
|
||||
import logging
|
||||
from logging.handlers import SysLogHandler
|
||||
|
@ -81,6 +82,31 @@ class GetYoutubeVideos:
|
|||
)
|
||||
)
|
||||
|
||||
def _is_numeric(self, variable):
|
||||
if (
|
||||
isinstance(variable, int) or
|
||||
isinstance(variable, float) or
|
||||
isinstance(variable, complex)
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
def _save_metrics(self, data):
|
||||
with open(
|
||||
'/var/lib/prometheus/node-exporter/get_youtube_videos.prom',
|
||||
'w',
|
||||
encoding='UTF-8'
|
||||
) as metrics_file:
|
||||
for key in data:
|
||||
if self._is_numeric(data[key]):
|
||||
metrics_file.write(f"get_youtube_videos_{key} {data[key]}")
|
||||
elif isinstance(data[key], bool):
|
||||
value = 0
|
||||
if data[key]:
|
||||
value = '1'
|
||||
metrics_file.write(f"get_youtube_videos_{key} {value}")
|
||||
os.chmod('/var/lib/prometheus/node-exporter/get_youtube_videos.prom', stat.S_IROTH)
|
||||
|
||||
def _change_proxy(self, video_id):
|
||||
if len(self.config['proxy']) > 0:
|
||||
if isinstance(self.config['proxy'], list):
|
||||
|
|
Loading…
Reference in a new issue