def json_raw(): logging.info('Starting prcessing %s for ip %s ', request.path, (request.environ.get('HTTP_X_REAL_IP', request.remote_addr))) ''' Influx format data: https://github.com/influxdata/influxdb-python [ { "measurement": "cpu_load_short", "tags": { "host": "server01", "region": "us-west" }, "time": "2009-11-10T23:00:00Z", "fields": { "value": 0.64 } } ] ''' if request.content_type != 'application/json': logging.error( '%s %s has no application/json in the header as content type', (request.environ.get('HTTP_X_REAL_IP', request.remote_addr)), request.path) return jsonify({"Error": "Expecting Json"}), 403 data = request.get_json() import modules.to_influx as influx infdata = influx.to_influx(data, "raw") from modules.influxdb import push_data return jsonify({"Status": push_data(infdata)})
def proc_uptime(): logging.info('Starting prcessing %s for ip %s ', request.path, (request.environ.get('HTTP_X_REAL_IP', request.remote_addr))) import modules.linux.proc_uptime as uptime import modules.to_influx as influx data = request.data.decode('utf-8') uptime_ = uptime.pars(data, "uptime") infdata = influx.to_influx(uptime_, "uptime") from modules.influxdb import push_data return jsonify({"Status": push_data(infdata)})
def proc_vmstats(): logging.info('Starting prcessing %s for ip %s ', request.path, request.environ.get('HTTP_X_REAL_IP', request.remote_addr)) import modules.linux.proc_vmstat as vmstat import modules.to_influx as influx data = request.data.decode('utf-8') vmstat_ = vmstat.pars(data, "vmstat") infdata = influx.to_influx(vmstat_, "vmstat") from modules.influxdb import push_data return jsonify({"Status": push_data(infdata)})
def proc_meminfo(): logging.info('Starting prcessing %s for ip %s ', request.path, (request.environ.get('HTTP_X_REAL_IP', request.remote_addr))) import modules.linux.proc_meminfo as meminfo import modules.to_influx as influx data = request.data.decode('utf-8') mem = meminfo.pars(data, "meminfo") infdata = influx.to_influx(mem, "meminfo") from modules.influxdb import push_data return jsonify({"Status": push_data(infdata)})
def file_proc_meminfo(): logging.info('Starting prcessing %s for ip %s ', request.path, (request.environ.get('HTTP_X_REAL_IP', request.remote_addr))) if 'file' not in request.files: return "need a file" elif request.files['file'].filename in {'proc_meminfo', 'meminfo'}: data = request.files['file'].read()[0:].decode('utf-8') else: return "Be sure you use /proc/net/meminfo or meminfo file" import modules.linux.proc_meminfo as meminfo import modules.to_influx as influx mem = meminfo.pars(data, "meminfo") infdata = influx.to_influx(mem, "meminfo") from modules.influxdb import push_data return jsonify({"Status": push_data(infdata)})