2020-09-26 22:33:30 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- mode: Python -*-
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
redis exporter
|
|
|
|
v0.1.0
|
|
|
|
|
2020-10-13 20:00:10 +00:00
|
|
|
A basic exporter
|
2020-09-26 22:33:30 +00:00
|
|
|
|
|
|
|
LICENCE : CC
|
|
|
|
|
2020-10-13 20:00:10 +00:00
|
|
|
by cocoa
|
2020-09-26 22:33:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
from __future__ import print_function
|
2020-09-29 23:04:35 +00:00
|
|
|
import sys
|
2020-09-29 16:02:45 +00:00
|
|
|
import os
|
2020-09-29 23:04:35 +00:00
|
|
|
import argparse
|
2020-09-26 22:33:30 +00:00
|
|
|
import redis
|
2020-10-13 20:00:10 +00:00
|
|
|
import time
|
2020-09-26 22:33:30 +00:00
|
|
|
|
|
|
|
argsparser = argparse.ArgumentParser(description="Redis exporter LJ")
|
|
|
|
argsparser.add_argument("-i","--ip",help="IP address of the Redis server ",default="127.0.0.1",type=str)
|
|
|
|
argsparser.add_argument("-p","--port",help="Port of the Redis server ",default="6379",type=str)
|
2020-09-27 16:50:50 +00:00
|
|
|
argsparser.add_argument("-k","--key",help="Redis key to update",default="0",type=str)
|
2020-09-26 22:33:30 +00:00
|
|
|
argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose")
|
|
|
|
args = argsparser.parse_args()
|
|
|
|
|
|
|
|
ip = args.ip
|
|
|
|
port = args.port
|
|
|
|
key = args.key
|
|
|
|
verbose=args.verbose
|
|
|
|
|
|
|
|
def debug(*args, **kwargs):
|
|
|
|
if( verbose == False ):
|
|
|
|
return
|
|
|
|
print(*args, file=sys.stderr, **kwargs)
|
|
|
|
|
|
|
|
r=redis.StrictRedis(host=ip, port=port, db=0)
|
|
|
|
|
|
|
|
try:
|
|
|
|
while True:
|
2020-09-29 23:04:35 +00:00
|
|
|
line = sys.stdin.readline()
|
|
|
|
if line == "":
|
|
|
|
time.sleep(0.01)
|
2020-10-13 20:00:10 +00:00
|
|
|
continue
|
2020-09-29 23:04:35 +00:00
|
|
|
line = line.rstrip('\n')
|
|
|
|
line=line[1:-1]
|
|
|
|
line = line.replace("[",'(')
|
|
|
|
line = line.replace("]",')')
|
|
|
|
line = "[{}]".format(line)
|
2020-10-09 23:40:46 +00:00
|
|
|
if line == "[]":
|
2020-10-13 19:54:06 +00:00
|
|
|
line="[(400.0,400.0,0),(400.0,400.0,0),(400.0,400.0,0),(400.0,400.0,0)]"
|
2020-10-09 23:40:46 +00:00
|
|
|
continue
|
2020-09-29 23:04:35 +00:00
|
|
|
if r.set(key,line)==True:
|
2020-09-26 22:33:30 +00:00
|
|
|
debug("exports::redis set("+str(key)+") to "+line)
|
|
|
|
except EOFError:
|
|
|
|
debug("break")# no more information
|
|
|
|
|