Skip to content

Commit

Permalink
Merge pull request #319 from mrannanj/prometheus
Browse files Browse the repository at this point in the history
Prometheus
  • Loading branch information
neilcook authored Jul 28, 2020
2 parents 8d3ae09 + ba9f2d4 commit 770dd78
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions docker/regression/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ RUN apt-get update && \
docker-compose \
python3-pip \
python3-venv \
prometheus \
redis \
geoip-bin \
geoip-database \
Expand Down
14 changes: 14 additions & 0 deletions regression-tests/prometheus-wforce.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
global:
scrape_interval: 4s

scrape_configs:
- job_name: wforce

scrape_interval: 4s

static_configs:
- targets: [ 'localhost:8084' ]

basic_auth:
username: 'wforce'
password: 'super'
24 changes: 23 additions & 1 deletion regression-tests/test_Prometheus.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import requests
import time
import os
import requests
import subprocess
from urllib.parse import urlparse
from urllib.parse import urljoin

from prometheus_client.parser import text_string_to_metric_families
from prometheus_client.samples import Sample
from test_helper import ApiTestCase

PROMETHEUS_PORT="9090"
PROMETHEUS_URL="http://localhost:%s" % PROMETHEUS_PORT
PROMETHEUS_CONF="./prometheus-wforce.yml"

class TestPrometheus(ApiTestCase):

def parsePrometheusResponse(self, response):
Expand Down Expand Up @@ -83,3 +87,21 @@ def test_TrackalertMetrics(self):
self.assertGreater(float(values['trackalert_commands_total{cmd="custom"}']), custom_count)
self.assertGreater(float(values['trackalert_worker_response_duration_seconds_bucket{le="+Inf"}']), 0)

def test_RealPrometheus(self):
cmd = ["prometheus", "--config.file=%s" % PROMETHEUS_CONF]
prometheus = subprocess.Popen(cmd, close_fds=True)
prometheus_tries = 20
try:
for i in range(prometheus_tries+1):
try:
r = requests.get('%s/api/v1/label/__name__/values' %
PROMETHEUS_URL)
assert 'wforce_commands_total' in r.text, r.text
break
except:
if i == prometheus_tries:
raise
time.sleep(4)
finally:
prometheus.terminate()
prometheus.wait()

0 comments on commit 770dd78

Please sign in to comment.