【问题标题】:How to get data from Oracle to send it to statsd or directly into InfluxDB?如何从 Oracle 获取数据以将其发送到 statsd 或直接发送到 InfluxDB?
【发布时间】:2015-02-20 17:09:30
【问题描述】:

有没有一种解决方案可以从 Oracle 数据库中获取一些数据以进一步将其发送到 statsd 或直接发送到 InfluxDB?我有很多 sql 查询需要定期运行以获取一些计数器。我需要 ORABBIX (zabbix) 的替代品,它与数据库有持久连接,但用于 stastd/InfluxDB。我想在查询表中的计数器时减少与数据库的连接。谢谢。

【问题讨论】:

    标签: oracle monitoring statsd influxdb


    【解决方案1】:

    由于有cx_OracleInfluxDBClient,您可以编写一个简单的 Python 脚本来打开所有必要的数据库连接,准备一堆 SQL 语句并重复执行它们并将它们输入到 influxdb 实例中。

    基本上是这样的:

    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)
    

    在该示例中,每个 SQL 语句都只返回一行,并有一个关联的 influxdb 行 (c['line']),如下所示:

    measurement,db={} col_name1={},col_name2={},col_name3={}
    

    您还可以在该行添加时间戳 - 如果省略,influxdb 使用当前时间。请注意,此脚本运行时间很长 - 并使用准备好的语句来避免浪费数据库资源。

    或者,如果您已经有一个 collectd 正在运行:collectd 有一个 oracle plugin。因此,您可以将现有查询与该插件和 configure collectd to forward 数据点 to an influxdb 实例一起使用(通过 UDP,即在 influxdb 配置中启用 UDP 侦听端口)。

    【讨论】:

      【解决方案2】:

      将数据直接发送到influxDB:

      我们可以编写一个 java 代码,使用 influxdb-java API 将数据插入到 influxDB 中

      我们可以创建一个 oracle ojdbc 连接,使用 sql 查询查询数据并将结果存储在 ResultSet 中并创建一个 influxDB 连接,从结果中读取查询的数据并将其作为点存储到 influxDB 测量中。

      我们可以在创建点时添加时间戳或忽略它,这样它会自动将系统日期作为时间戳。

      参考以下链接:https://github.com/influxdata/influxdb-java/blob/master/src/test/java/org/influxdb/InfluxDBTest.java

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-26
        • 2017-02-08
        相关资源
        最近更新 更多