Skip to content

Commit

Permalink
Merge pull request percona#16 from delgod/issue-13
Browse files Browse the repository at this point in the history
PMM-536 revert more stable waiting
  • Loading branch information
askomorokhov authored Jan 31, 2017
2 parents 17240f9 + 505f444 commit 952c722
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /opt
# System packages #
# ############### #
RUN apt-get -y update && \
apt-get install -y apt-transport-https curl git unzip nginx mysql-server-5.5 python python-requests supervisor python-pip && \
apt-get install -y apt-transport-https curl git unzip nginx mysql-server-5.5 python python-requests supervisor && \
rm -f /etc/cron.daily/apt && \
useradd -s /bin/false pmm

Expand All @@ -30,7 +30,6 @@ COPY prometheus.yml /opt/prometheus/
COPY import-dashboards.py grafana-postinstall.sh VERSION /opt/
RUN curl -s -LO https://grafanarel.s3.amazonaws.com/builds/grafana_4.0.2-1481203731_amd64.deb && \
dpkg -i grafana_4.0.2-1481203731_amd64.deb && \
pip install -U urllib3 && \
git clone https://github.com/percona/grafana-dashboards.git && \
mv import-dashboards.py VERSION grafana-dashboards/ && \
service grafana-server start && \
Expand Down
38 changes: 20 additions & 18 deletions import-dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import sqlite3
import sys
import requests
from urllib3.util import Retry
from requests.adapters import HTTPAdapter
import time

GRAFANA_DB_DIR = sys.argv[1] if len(sys.argv) > 1 else '/var/lib/grafana'
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -34,27 +33,30 @@ def check_dashboards_version():
upgrade = True
with open(OLD_VERSION_FILE, 'r') as f:
old_ver = f.read().strip()
print '* Dashboards upgrade from version %s to %s.' % (old_ver, new_ver)
print ' * Dashboards upgrade from version %s to %s.' % (old_ver, new_ver)

if old_ver == new_ver:
print '* The dashboards are up-to-date (%s).' % (old_ver,)
print ' * The dashboards are up-to-date (%s).' % (old_ver,)
sys.exit(0)

return upgrade


def wait_for_grafana_start():
print 'Waiting for Grafana to start...'
s = requests.Session()
retries = Retry(total=10,
backoff_factor=1,
status_forcelist=[500, 502, 503, 504])
s.mount('http://', HTTPAdapter(max_retries=retries))
try:
s.get('%s/api/datasources' % HOST, timeout=0.1)
except:
print '* Grafana is unable to start correctly'
sys.exit(-1)
sys.stdout.write(' * Waiting for Grafana to start')
sys.stdout.flush()
for _ in xrange(60):
try:
requests.get('%s/api/datasources' % HOST, timeout=0.1)
except requests.exceptions.ConnectionError:
sys.stdout.write('.')
sys.stdout.flush()
time.sleep(1)
else:
print
return
print "\n * Grafana is unable to start correctly"
sys.exit(-1)


def add_api_key():
Expand Down Expand Up @@ -97,15 +99,15 @@ def add_datasources():
r = requests.post('%s/api/datasources' % HOST, data=data, headers=HEADERS)
print r.status_code, r.content
if r.status_code != 200:
print '* Cannot add Prometheus Data Source'
print ' * Cannot add Prometheus Data Source'
sys.exit(-1)

if 'CloudWatch' not in ds:
data = json.dumps({'name': 'CloudWatch', 'type': 'cloudwatch', 'jsonData': '{"defaultRegion":"us-east-1"}', 'access': 'proxy', 'isDefault': False})
r = requests.post('%s/api/datasources' % HOST, data=data, headers=HEADERS)
print r.status_code, r.content
if r.status_code != 200:
print '* Cannot add CloudWatch Data Source'
print ' * Cannot add CloudWatch Data Source'
sys.exit(-1)


Expand Down Expand Up @@ -133,7 +135,7 @@ def import_dashboards():
r = requests.post('%s/api/dashboards/db' % HOST, data=data, headers=HEADERS)
if r.status_code != 200:
print r.status_code, r.content
print '* Cannot add %s Dashboard' % file_
print ' * Cannot add %s Dashboard' % file_
sys.exit(-1)


Expand Down

0 comments on commit 952c722

Please sign in to comment.