[英]How to get data from Oracle to send it to statsd or directly into InfluxDB?
Is there a solution to get some data from Oracle database for further send it to statsd or directly into InfluxDB? 是否有解决方案从Oracle数据库获取一些数据以进一步将其发送到statsd或直接发送到InfluxDB? I have a lot of sql queries that I need to run periodically for getting some counters.
我有很多sql查询,我需要定期运行以获取一些计数器。 I need an alternative of ORABBIX (zabbix), that have a persistent connection to database, but for stastd/InfluxDB.
我需要ORABBIX(zabbix)的替代方案,它与数据库有持久的连接,但是对于stastd / InfluxDB。 I want to reduce an connections to database while querying for counters that is in tables.
我想在查询表中的计数器时减少与数据库的连接。 Thank you.
谢谢。
Since there is the cx_Oracle and InfluxDBClient you can write a simple Python script that opens all neccessary DB connections, prepares a bunch of SQL statements and repeatedly executes them and feeds them into a influxdb instance. 由于有cx_Oracle和InfluxDBClient,您可以编写一个简单的Python脚本来打开所有必要的数据库连接,准备一堆SQL语句并重复执行它们并将它们提供给一个Influxdb实例。
Basically something along those lines: 基本上是这样的:
from influxdb import InfluxDBClient
import cx_Oracle
ic = InfluxDBClient('vigilante.example.org', 8086, 'collector', 'pw', 'db'
db_dict = {}
for sid in sids:
db_dict[sid] = cx_Oracle.connect(ORACLE_USER, ORACLE_PASS, sid)
cursor_dict = {}
for (name, c) in config.items():
cursor = db_dict[c['sid']].cursor()
cursor.prepare(c['config'])
cursor_dict[name, c['sid']] = (cursor, c['line'])
def collect(cursor_dict):
vs = []
for ((name, sid), (cursor, line)) in cursor_dict:
rows.execute(cursosr.fetchall())
if rows:
vs.append(line.format(sid, *rows[0]))
if vs:
ic.write_points(vs, protocol='line')
while True:
collect(cursor_dict)
time.sleep(sleep_for_some_dynamically_computed_time)
In that example, each SQL statement returns exactly one row and has a influxdb line associated ( c['line']
) which looks like: 在该示例中,每个SQL语句只返回一行并且具有关联的涌入线(
c['line']
),如下所示:
measurement,db={} col_name1={},col_name2={},col_name3={}
You can also add a timestamp to that line - if it is omitted, influxdb uses the current time. 您还可以向该行添加时间戳 - 如果省略,则Influxdb使用当前时间。 Note that this script is long running - and uses prepared statements to avoid wasting DB resources.
请注意,此脚本长时间运行 - 并使用预准备语句来避免浪费数据库资源。
Alternatively, if you already have a collectd running: there is an oracle plugin for collectd. 或者,如果您已经运行了一个collectd :还有一个用于collectd的oracle插件 。 Thus, you could use your existing queries with that plugin and configure collectd to forward the data points to an influxdb instance (via UDP, ie enable a UDP listening port in the influxdb config).
因此,您可以将现有查询与该插件一起使用,并配置 collectd将数据点转发 到Influxdb实例(通过UDP,即在Influxdb配置中启用UDP侦听端口)。
To sent the data directly into the influxDB: 要将数据直接发送到InfluxDB:
We can write a java code to insert the data into the influxDB using influxdb-java API 我们可以编写一个java代码,使用Influxdb-java API将数据插入到InfluxDB中
We can create a oracle ojdbc connection, query the data using a sql query and store the result in a ResultSet and create a influxDB connection, read the queried data from the result and store it as point into the influxDB measurement. 我们可以创建一个oracle ojdbc连接,使用sql查询查询数据并将结果存储在ResultSet中并创建一个InfluxDB连接,从结果中读取查询的数据并将其作为点存储到InfluxDB测量中。
We can add the time stamp while creating a point or ignore it , in that case it will automatically take the system date as a time stamp. 我们可以在创建点时添加时间戳或忽略它,在这种情况下,它会自动将系统日期作为时间戳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.