I’m facing some trouble to adapt one script for telegraf + grafana + oracle.
I’m receiving this error:
2021-08-17T13:54:00Z E! [inputs.exec] Error in plugin: metric parse error: expected field at 224:72: “oracle_status,fqdn=ORADB-DASE,delphix=none,db=TEST instancename=TEST,db_status=OPEN”
Here is the code:
import socket
import argparse
import subprocess
import re
import cx_Oracle
fqdn = socket.getfqdn()
class OraStats():
def __init__(self, user, passwd, sid):
self.user = user
self.passwd = passwd
self.sid = sid
self.delengine = "none"
self.connection = cx_Oracle.connect(self.user, self.passwd, self.sid)
cursor = self.connection.cursor()
cursor.execute("select distinct(SVRNAME) from v$dnfs_servers")
rows = cursor.fetchall()
for i in range(0, cursor.rowcount):
self.dengine_ip = rows[i][0]
proc = subprocess.Popen(["nslookup", self.dengine_ip], stdout=subprocess.PIPE)
lookupresult = proc.communicate()[0].split('\n')
for line in lookupresult:
if 'name=' in re.sub(r'\s', '', line):
self.delengine = re.sub('\..*$', '', re.sub(r'^.*name=', '', re.sub(r'\s', '', re.sub(r'.$', '', line))))
def dbstatus(self, user, passwd, sid, format):
cursor = self.connection.cursor()
cursor.execute("""
select instance_name,status from v$instance
""")
for stat in cursor:
instancename = stat[0]
stat_status = stat[1]
print "oracle_status,fqdn={0},delphix={1},db={2} instancename={3},db_status={4}".format(fqdn,self.delengine,sid, re.sub(' ','_', instancename),re.sub(' ','_', stat_status))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--format', help="Output format, default influx", choices=['kafka', 'influx'], default='influx')
subparsers = parser.add_subparsers(dest='stat')
parser_all = subparsers.add_parser('ALL', help="Get all database stats")
parser_all.add_argument('-u', '--user', help="Username with sys views grant", required=True)
parser_all.add_argument('-p', '--passwd', required=True)
parser_all.add_argument('-s', '--sid', help="tnsnames SID to connect", required=True)
args = parser.parse_args()
if args.stat == "ALL":
stats.dbstatus(args.user, args.passwd, args.sid, args.format)