This commit is contained in:
parent
92884b6760
commit
211be6cf96
@ -13,3 +13,6 @@ marshmallow
|
|||||||
marshmallow-sqlalchemy
|
marshmallow-sqlalchemy
|
||||||
flask-marshmallow
|
flask-marshmallow
|
||||||
py-healthcheck
|
py-healthcheck
|
||||||
|
Flask-InfluxDB
|
||||||
|
tzdata
|
||||||
|
tzlocal
|
@ -1,5 +1,4 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import logging
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_restful import Api
|
from flask_restful import Api
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
@ -10,6 +9,7 @@ from healthcheck import HealthCheck
|
|||||||
from config import *
|
from config import *
|
||||||
from db import db
|
from db import db
|
||||||
from marshm import ma
|
from marshm import ma
|
||||||
|
from influxus import influx_db
|
||||||
from resources import SampleResource, SampleParameterResource
|
from resources import SampleResource, SampleParameterResource
|
||||||
from healthchecks import health_database_status
|
from healthchecks import health_database_status
|
||||||
|
|
||||||
@ -42,10 +42,17 @@ app.config['FLASK_PIKA_PARAMS'] = {'host': RABBITMQ_HOST,
|
|||||||
'password': RABBITMQ_PASSWORD,
|
'password': RABBITMQ_PASSWORD,
|
||||||
'port': 5672,
|
'port': 5672,
|
||||||
'virtual_host': '/'}
|
'virtual_host': '/'}
|
||||||
|
app.config['INFLUXDB_HOST']=INFLUXDB_HOST
|
||||||
|
app.config['INFLUXDB_PORT']=INFLUXDB_PORT
|
||||||
|
app.config['INFLUXDB_USER']=INFLUXDB_USERNAME
|
||||||
|
app.config['INFLUXDB_PASSWORD']=INFLUXDB_PASSWORD
|
||||||
|
app.config['INFLUXDB_DATABASE']=INFLUXDB_DB
|
||||||
|
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
health = HealthCheck()
|
health = HealthCheck()
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
ma.init_app(app)
|
ma.init_app(app)
|
||||||
|
influx_db.init_app(app)
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
@ -33,3 +33,9 @@ POSTGRES_PASSWORD = os.getenv("INPUT_POSTGRES_PASSWORD", "input-service")
|
|||||||
POSTGRES_DB = os.getenv("INPUT_POSTGRES_DB", "input-service")
|
POSTGRES_DB = os.getenv("INPUT_POSTGRES_DB", "input-service")
|
||||||
|
|
||||||
STORAGE_HOSTNAME = os.getenv("INPUT_STORAGE_HOSTNAME", "localhost:8042")
|
STORAGE_HOSTNAME = os.getenv("INPUT_STORAGE_HOSTNAME", "localhost:8042")
|
||||||
|
|
||||||
|
INFLUXDB_HOST = os.getenv("INFLUX_HOST", "input-influx")
|
||||||
|
INFLUXDB_PORT = os.getenv("INFLUX_PORT", "8086")
|
||||||
|
INFLUXDB_USERNAME = os.getenv("INFLUX_USERNAME", "input-service")
|
||||||
|
INFLUXDB_PASSWORD = os.getenv("INFLUX_PASSWORD", "input-service-supersecret")
|
||||||
|
INFLUXDB_DB = os.getenv("INFLUX_DB", "input-service")
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Flask Restful endpoints
|
Database api
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__author__ = '@tormakris'
|
__author__ = '@tormakris'
|
||||||
|
15
src/influxus.py
Normal file
15
src/influxus.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from flask_influxdb import InfluxDB
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Influx api
|
||||||
|
"""
|
||||||
|
|
||||||
|
__author__ = '@tormakris'
|
||||||
|
__copyright__ = "Copyright 2020, Birbnetes Team"
|
||||||
|
__module_name__ = "influxus"
|
||||||
|
__version__text__ = "1"
|
||||||
|
|
||||||
|
influx_db = InfluxDB()
|
@ -1,11 +1,14 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import json
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
import tzlocal
|
||||||
from xeger import Xeger
|
from xeger import Xeger
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
from flask import request, current_app
|
from flask import request, current_app
|
||||||
import requests
|
import requests
|
||||||
import pika
|
import pika
|
||||||
from db import db
|
from db import db
|
||||||
|
from influxus import influx_db
|
||||||
from models import SampleMetadata
|
from models import SampleMetadata
|
||||||
from schemas import SampleSchema, SampleMetadataSchema
|
from schemas import SampleSchema, SampleMetadataSchema
|
||||||
from config import *
|
from config import *
|
||||||
@ -106,7 +109,20 @@ class SampleResource(Resource):
|
|||||||
routing_key='feature',
|
routing_key='feature',
|
||||||
body=json.dumps({'tag': generated_tag}).encode('UTF-8'))
|
body=json.dumps({'tag': generated_tag}).encode('UTF-8'))
|
||||||
connection.close()
|
connection.close()
|
||||||
|
influx_db.write_points(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'time': datetime.now(tz=tzlocal.get_localzone()),
|
||||||
|
'measurement': 'cloudinput',
|
||||||
|
'tags': {
|
||||||
|
'device': desc['device_id']
|
||||||
|
},
|
||||||
|
'fields': {
|
||||||
|
'bruh': 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
Loading…
Reference in New Issue
Block a user