Merge branch 'influx'
This commit is contained in:
commit
3c10a351ba
@ -23,13 +23,6 @@ steps:
|
|||||||
tags:
|
tags:
|
||||||
- latest
|
- latest
|
||||||
- ${DRONE_BUILD_NUMBER}
|
- ${DRONE_BUILD_NUMBER}
|
||||||
- name: sentry
|
|
||||||
image: tormachris/drone-sentry
|
|
||||||
settings:
|
|
||||||
sentry_project: ${DRONE_REPO_NAME}
|
|
||||||
sentry_domain: sentry.kmlabz.com
|
|
||||||
sentry_token:
|
|
||||||
from_secret: SENTRY_TOKEN
|
|
||||||
|
|
||||||
- name: ms-teams
|
- name: ms-teams
|
||||||
image: kuperiu/drone-teams
|
image: kuperiu/drone-teams
|
||||||
|
@ -13,3 +13,6 @@ marshmallow~=3.13.0
|
|||||||
marshmallow-sqlalchemy~=0.26.1
|
marshmallow-sqlalchemy~=0.26.1
|
||||||
flask-marshmallow
|
flask-marshmallow
|
||||||
py-healthcheck
|
py-healthcheck
|
||||||
|
Flask-InfluxDB
|
||||||
|
tzdata
|
||||||
|
tzlocal
|
@ -9,6 +9,7 @@ from healthcheck import HealthCheck
|
|||||||
from config import Config
|
from config import Config
|
||||||
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
|
||||||
|
|
||||||
@ -39,10 +40,12 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def init_db():
|
def init_db():
|
||||||
|
influx_db.database.create(Config.INFLUXDB_DATABASE)
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ _POSTGRES_HOSTNAME = os.getenv("INPUT_POSTGRES_HOSTNAME", "localhost")
|
|||||||
_POSTGRES_USERNAME = os.getenv("INPUT_POSTGRES_USERNAME", "input-service")
|
_POSTGRES_USERNAME = os.getenv("INPUT_POSTGRES_USERNAME", "input-service")
|
||||||
_POSTGRES_PASSWORD = os.getenv("INPUT_POSTGRES_PASSWORD", "input-service")
|
_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")
|
||||||
|
_POSTGRES_OPTS = os.getenv("INPUT_POSTGRES_OPTS", "")
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
@ -35,6 +36,12 @@ class Config:
|
|||||||
'virtual_host': '/'
|
'virtual_host': '/'
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLALCHEMY_DATABASE_URI = f"postgresql://{_POSTGRES_USERNAME}:{_POSTGRES_PASSWORD}@{_POSTGRES_HOSTNAME}:5432/{_POSTGRES_DB}?sslmode=require"
|
SQLALCHEMY_DATABASE_URI = f"postgresql://{_POSTGRES_USERNAME}:{_POSTGRES_PASSWORD}@{_POSTGRES_HOSTNAME}:5432/{_POSTGRES_DB}{_POSTGRES_OPTS}"
|
||||||
|
|
||||||
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_USER = os.getenv("INFLUX_USERNAME", "input-service")
|
||||||
|
INFLUXDB_PASSWORD = os.getenv("INFLUX_PASSWORD", "input-service-supersecret")
|
||||||
|
INFLUXDB_DATABASE = 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, abort
|
from flask import request, current_app, abort
|
||||||
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
|
||||||
|
|
||||||
@ -111,11 +114,25 @@ 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()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
return abort(569, "AMPQ Publish error")
|
return abort(569, "AMPQ Publish error")
|
||||||
|
|
||||||
|
influx_db.write_points(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
'time': datetime.now(tz=tzlocal.get_localzone()),
|
||||||
|
'measurement': 'cloudinput',
|
||||||
|
'tags': {
|
||||||
|
'device': desc['device_id']
|
||||||
|
},
|
||||||
|
'fields': {
|
||||||
|
'bruh': 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return {"tag": generated_tag}, 200
|
return {"tag": generated_tag}, 200
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user