-
Notifications
You must be signed in to change notification settings - Fork 6
/
manage.py
executable file
·69 lines (54 loc) · 1.71 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import json
import random
import requests
import time
from configobj import ConfigObj
from flask_script import Manager
from validate import Validator
import rrdtool
from flaskrrd import app, init_webapp
from flaskrrd.model import db, RRD
manager = Manager(app)
@manager.command
def update_rrd():
while True:
try:
print requests.post(
'http://localhost:5000/update/test',
headers={'Content-Type': 'application/json'},
data=json.dumps({
'metrics': {
'COUNTER': {
'a': str(random.randint(0, 1000)),
'b': str(random.randint(0, 1000)),
'c': str(random.randint(0, 1000)),
},
},
})).status_code
except Exception:
print 'Failed to make request, maybe server is down?'
#raise
finally:
time.sleep(1)
@manager.command
def graph_rrd():
print requests.get(
'http://localhost:5000/graph/test').status_code
@manager.command
def dump_database():
"""Dump the flask-rrd database."""
init_webapp()
for r in RRD.query.all():
print r
@manager.command
def runserver(*args, **kwargs):
"""Override default `runserver` to init webapp before running."""
app = init_webapp()
# TODO(sholsapp): parameterize this, but don't clobber the *args, **kwargs
# space, because it's annoying to have to pass these in to the `run` method.
config = ConfigObj('config/sample.config', configspec='config/sample.configspec')
app.config_obj = config
app.run(*args, host='0.0.0.0', **kwargs)
if __name__ == "__main__":
manager.run()