add create_time

This commit is contained in:
Hugo 2021-09-20 21:58:48 +02:00
parent bb713a9a21
commit fe019750a5
1 changed files with 7 additions and 1 deletions

View File

@ -66,11 +66,13 @@ class TelegrafExporter():
self._password = password
self.source = source
def telegraf_post(self, timestamp:int, title:str, location:str, count:int)-> requests.Response:
def telegraf_post(self, timestamp:int, create_time: int, title:str,
location:str, count:int)-> requests.Response:
""" Post a value to telegraf
"""
payload = {"name": title,
"timestamp": timestamp,
"create_time": create_time,
"source": self.source,
"location": location,
"hits": count}
@ -84,10 +86,13 @@ class TelegrafExporter():
"""
# export standard hits
timestamp = int(datetime.combine(datetime.now().date(), time()).timestamp())
now = datetime.now().time()
create_time = now.second + 60*now.minute + 3600*now.hour
name="blog_client_hit"
for location, ips in page_hits.items():
try:
response = self.telegraf_post(timestamp,
create_time,
name,
location,
len(ips))
@ -100,6 +105,7 @@ class TelegrafExporter():
for location, ips in bot_hits.items():
try:
response = self.telegraf_post(timestamp,
create_time,
name,
location,
len(ips))