Skip to content

Commit

Permalink
Also log Unix time
Browse files Browse the repository at this point in the history
This allows us to configure Promtail with:
```
scrape_configs:
- job_name: [name]
  pipeline_stages:
  - timestamp:
      source: time
      format: Unix
  static_configs:
  - targets:
      - localhost
    labels:
      job: [name]
      …
```
In order to set the timestamp of the log-line to the exact time that the
speedtest was completed, rather than the time that Promtail scraped the
record (which could be later, if Promtail was booted a few mins after
the exporter and Prometheus were booted).
  • Loading branch information
samjewell committed Jul 2, 2021
1 parent 9bf121d commit d305824
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import logging
import os
import subprocess
import time
from prometheus_client import make_wsgi_app, Gauge
from flask import Flask
from waitress import serve

format_string = '%(levelname)s: %(asctime)s: %(message)s''
format_string = '%(levelname)s: %(asctime)s: %(message)s'
logging.basicConfig(filename='speedtest.log', encoding='utf-8', level=logging.DEBUG, format=format_string)

app = Flask("Speedtest-Exporter") # Create flask app
Expand Down Expand Up @@ -88,11 +89,11 @@ def updateResults():
download_speed.set(r_download)
upload_speed.set(r_upload)
up.set(r_status)
current_dt = datetime.datetime.now()
logging.info(
" Server=" + str(r_server)
+ " Jitter=" + str(r_jitter) + " ms"
+ " Ping=" + str(r_ping) + " ms"
"time=" + str(time.time())
+ " Server=" + str(r_server)
+ " Jitter=" + str(r_jitter) + "ms"
+ " Ping=" + str(r_ping) + "ms"
+ " Download=" + bits_to_megabits(r_download)
+ " Upload=" + bits_to_megabits(r_upload)
+ " Url=" + r_url
Expand Down

0 comments on commit d305824

Please sign in to comment.