This commit is contained in:
parent
92884b6760
commit
211be6cf96
@ -13,3 +13,6 @@ marshmallow
|
||||
marshmallow-sqlalchemy
|
||||
flask-marshmallow
|
||||
py-healthcheck
|
||||
Flask-InfluxDB
|
||||
tzdata
|
||||
tzlocal
|
@ -1,5 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
import logging
|
||||
from flask import Flask
|
||||
from flask_restful import Api
|
||||
import sentry_sdk
|
||||
@ -10,6 +9,7 @@ from healthcheck import HealthCheck
|
||||
from config import *
|
||||
from db import db
|
||||
from marshm import ma
|
||||
from influxus import influx_db
|
||||
from resources import SampleResource, SampleParameterResource
|
||||
from healthchecks import health_database_status
|
||||
|
||||
@ -42,10 +42,17 @@ app.config['FLASK_PIKA_PARAMS'] = {'host': RABBITMQ_HOST,
|
||||
'password': RABBITMQ_PASSWORD,
|
||||
'port': 5672,
|
||||
'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)
|
||||
health = HealthCheck()
|
||||
db.init_app(app)
|
||||
ma.init_app(app)
|
||||
influx_db.init_app(app)
|
||||
|
||||
with app.app_context():
|
||||
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")
|
||||
|
||||
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
|
||||
|
||||
"""
|
||||
Flask Restful endpoints
|
||||
Database api
|
||||
"""
|
||||
|
||||
__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
|
||||
import json
|
||||
from datetime import datetime
|
||||
import tzlocal
|
||||
from xeger import Xeger
|
||||
from flask_restful import Resource
|
||||
from flask import request, current_app
|
||||
import requests
|
||||
import pika
|
||||
from db import db
|
||||
from influxus import influx_db
|
||||
from models import SampleMetadata
|
||||
from schemas import SampleSchema, SampleMetadataSchema
|
||||
from config import *
|
||||
@ -106,7 +109,20 @@ class SampleResource(Resource):
|
||||
routing_key='feature',
|
||||
body=json.dumps({'tag': generated_tag}).encode('UTF-8'))
|
||||
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:
|
||||
current_app.logger.exception(e)
|
||||
db.session.rollback()
|
||||
|
Loading…
Reference in New Issue
Block a user