首页 > 其他分享 >influxDB

influxDB

时间:2023-12-31 13:11:21浏览次数:21  
标签:influxdb host client influxDB print query user

InfluxDB

https://www.influxdata.com/

时间序列数据库。

Real-time insights from any time series data with a single, purpose-built database. Run at any scale in any environment in the cloud, on-premises, or at the edge.

 

教程

官方:

https://docs.influxdata.com/influxdb/cloud/get-started/

国内翻译:

https://jasper-zhang1.gitbooks.io/influxdb/content/

尚硅谷视频:

https://www.bilibili.com/video/BV1xd4y1c73c/?spm_id_from=333.337.search-card.all.click&vd_source=41b9bfb5ef0a4175a4cb4170a475f680

 

全家桶demo

旧版1.x, 所有组件组装成一个docker容器,使用supervisord启动。

https://github.com/philhawthorne/docker-influxdb-grafana

 

新版:

https://github.com/samuelebistoletti/docker-statsd-influxdb-grafana

 

python客户端

https://github.com/jaibwtl/influxdb-python-demo/tree/main

from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS

bucket = "my-bucket"

client = InfluxDBClient(url="http://localhost:8086", token="my-super-secret-auth-token", org="my-org")

write_api = client.write_api(write_options=SYNCHRONOUS)
query_api = client.query_api()

p = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)

write_api.write(bucket=bucket, record=p)

## using Table structure
tables = query_api.query('from(bucket:"my-bucket") |> range(start: -10m)')

for table in tables:
    print(table)
    for row in table.records:
        print (row.values)


## using csv library
csv_result = query_api.query_csv('from(bucket:"my-bucket") |> range(start: -10m)')
val_count = 0
for row in csv_result:
    for cell in row:
        val_count += 1

 

official example

https://github.com/influxdata/influxdb-python/blob/master/examples/tutorial.py

# -*- coding: utf-8 -*-
"""Tutorial on using the InfluxDB client."""

import argparse

from influxdb import InfluxDBClient


def main(host='localhost', port=8086):
    """Instantiate a connection to the InfluxDB."""
    user = 'root'
    password = 'root'
    dbname = 'example'
    dbuser = 'smly'
    dbuser_password = 'my_secret_password'
    query = 'select Float_value from cpu_load_short;'
    query_where = 'select Int_value from cpu_load_short where host=$host;'
    bind_params = {'host': 'server01'}
    json_body = [
        {
            "measurement": "cpu_load_short",
            "tags": {
                "host": "server01",
                "region": "us-west"
            },
            "time": "2009-11-10T23:00:00Z",
            "fields": {
                "Float_value": 0.64,
                "Int_value": 3,
                "String_value": "Text",
                "Bool_value": True
            }
        }
    ]

    client = InfluxDBClient(host, port, user, password, dbname)

    print("Create database: " + dbname)
    client.create_database(dbname)

    print("Create a retention policy")
    client.create_retention_policy('awesome_policy', '3d', 3, default=True)

    print("Switch user: " + dbuser)
    client.switch_user(dbuser, dbuser_password)

    print("Write points: {0}".format(json_body))
    client.write_points(json_body)

    print("Querying data: " + query)
    result = client.query(query)

    print("Result: {0}".format(result))

    print("Querying data: " + query_where)
    result = client.query(query_where, bind_params=bind_params)

    print("Result: {0}".format(result))

    print("Switch user: " + user)
    client.switch_user(user, password)

    print("Drop database: " + dbname)
    client.drop_database(dbname)


def parse_args():
    """Parse the args."""
    parser = argparse.ArgumentParser(
        description='example code to play with InfluxDB')
    parser.add_argument('--host', type=str, required=False,
                        default='localhost',
                        help='hostname of InfluxDB http API')
    parser.add_argument('--port', type=int, required=False, default=8086,
                        help='port of InfluxDB http API')
    return parser.parse_args()


if __name__ == '__main__':
    args = parse_args()
    main(host=args.host, port=args.port)

 

标签:influxdb,host,client,influxDB,print,query,user
From: https://www.cnblogs.com/lightsong/p/17937422

相关文章

  • influxdb 进行数据删除和修改
    本文为博主原创,转载请注明出处:1.条件删除数据InfluxDB只支持基于时间的删除操作。可以使用 DELETE 语句来删除指定时间范围内的数据。例如,以下的SQL语句将删除 measurement_name 表中时间在'2023-06-30'到'2023-06-3015:16:01'之间的所有数据:DELETEFROM......
  • 软件测试/测试开发|Docker+Jmeter+InfluxDB+Grafana 搭建性能监控平台
    为什么要搭建性能监控平台?1.1需求背景在用Jmeter获取性能测试结果的时候,Jmeter本身带有聚合报告如下图所示:这个报告有几个很明显的缺点:只能自己看,无法实时共享;报告信息的展示比较简陋单一,不直观;1.2需求方案为了解决上述问题,必须要请出了InfluxDB+Grafana:InfluxDB:持续型......
  • 47、Flink 的指标报告介绍(graphite、influxdb、prometheus、statsd和datalog)及示例(jmx
    文章目录Flink系列文章一、MetricReporters1、概述及示例2、入门示例0)、特别说明1)、配置2)、验证3)、自定义的指标收集器3、基于标志符格式vs.基于tags格式4、Pushvs.Pull5、发送器1)、JMX2)、Graphite2)、InfluxDB4)、Prometheus5)、PrometheusPushGateway6)、StatsD7)、Datadog8)......
  • 软件测试/测试开发|Docker+Jmeter+InfluxDB+Grafana 搭建性能监控平台
    为什么要搭建性能监控平台?1.1需求背景在用Jmeter获取性能测试结果的时候,Jmeter本身带有聚合报告如下图所示:这个报告有几个很明显的缺点:只能自己看,无法实时共享;报告信息的展示比较简陋单一,不直观;1.2需求方案为了解决上述问题,必须要请出了InfluxDB+Grafana......
  • [INFLUXDB] 查询数据时,INFLUXDB报“InfluxDBException: user is locked”
    1问题描述通过QueryAPI查询INFLUXDB数据库数据时,查询失败,日志中报INFLUXDB数据库错误:...org.influxdb.InfluxDBException:userislocked atorg.influxdb.InfluxDBException.buildExceptionFromErrorMessage(InfluxDBException.java:161)~[influxdb-java-2.22.jar!/:?]......
  • mysql 读取 influxdb
    QueryResultcountResults=influxDBConfig.query(selectSql.toString());QueryResultresults=influxDBConfig.query(selectSql.toString());List<KeyValue>keyValues=queryResultProcess(results);privateList<KeyValue>queryResultProcess(QueryRe......
  • influxdb: unable to parse points 异常解决总结
    转载请注明出处:influxdb使用过程经常遇到:unabletoparsepoints 的异常:    unabletoparsepoints是InfluxDB抛出的异常,表示无法解析数据点(points)。这个错误通常与数据格式不匹配或数据字段类型错误有关。可能导致"unabletoparsepoints"错误的原因:1.......
  • 基于centos 7 +grafana-enterprise-8.4.2+influxdb2_2.7.4-1+jmeter-5.6.2的企业级压
    耗时2.5天平台搭建完成,在此记录一下,分享给同样苦逼的IT人。一.查看系统信息与位数[root@bj01-saas-stresstest-prod01~]#uname-aLinuxbj01-saas-stresstest-prod016.1.11-2302.1.1#1SMPPREEMPT_DYNAMICThuApr615:52:39CST2023x86_64GNU/Linux得到系统环境......
  • 全网最详细!Centos7.X 搭建Grafana+Jmeter+Influxdb 性能实时监控平台 (上)
    来源:https://developer.aliyun.com/article/907041本文涉及的产品可观测可视化Grafana版,10个用户账号1个月 立即试用 简介: 全网最详细!Centos7.X搭建Grafana+Jmeter+Influxdb性能实时监控平台(上)背景日常工作中,经常会用到Jmeter......
  • 【influxDB】CentOS 7.x InfluxDB 1.8.0的安装使用
    一、安装wgethttps://dl.influxdata.com/influxdb/releases/influxdb-1.8.0.x86_64.rpmyum-ylocalinstallinfluxdb-1.8.0.x86_64.rpm image.pngsystemctlstartinfluxdbsystemctlenableinfluxdbsystemctlstatusinfluxdbss-tan|grep8086......