Using influxdb lib to send data out

This commit is contained in:
Alexey 2018-10-08 21:20:54 +03:00
parent 99a4a417b7
commit ddd2d58649

View file

@ -18,11 +18,13 @@ from influxdb import InfluxDBClient
def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSERPASS, MEASUREMENT): # NOQA def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSERPASS, MEASUREMENT): # NOQA
GI = pygeoip.GeoIP('GeoLiteCity.dat', pygeoip.const.MEMORY_CACHE) CLIENT = InfluxDBClient(host=INFLUXHOST, port=INFLUXPORT,
username=INFLUXUSER, password=INFLUXUSERPASS, database=INFLUXDBDB) # NOQA
GETIP = r"^(?P<remote_host>[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3})" GETIP = r"^(?P<remote_host>[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3}\.[0-9]{,3})"
IPS = {} GI = pygeoip.GeoIP('GeoLiteCity.dat', pygeoip.const.MEMORY_CACHE)
GEOHASH = {} GEOHASH = {}
COUNT = {} COUNT = {}
IPS = {}
with open(LOGPATH, "r") as FILE: with open(LOGPATH, "r") as FILE:
STR_RESULTS = os.stat(LOGPATH) STR_RESULTS = os.stat(LOGPATH)
ST_SIZE = STR_RESULTS[6] ST_SIZE = STR_RESULTS[6]
@ -47,7 +49,7 @@ def logparse(LOGPATH, INFLUXHOST, INFLUXPORT, INFLUXDBDB, INFLUXUSER, INFLUXUSER
IPS['fields'] = COUNT IPS['fields'] = COUNT
METRICS.append(IPS) METRICS.append(IPS)
RESULT = json.dumps(METRICS) RESULT = json.dumps(METRICS)
print(RESULT) CLIENT.write_points(RESULT)
def main(): def main():