HomeMogDBMogDB StackUqbar

Documentation:v2.0

Supported Versions:

Grafana Connects To Time-series Database (MD5 Mode)

  1. Database password authentication method must be MD5.

  2. Install Grafana.

    docker run -d -p 3000: 3000 --name grafana grafana/grafana
  3. Create a test table and insert data.

    CREATE TIMESERIES POLICY IF NOT EXISTS tsbs_policy WITH(duration = '1 year', chunkgroupduration = '1 day');
    CREATE TIMESERIES TABLE cpu(
        time timestamp TSTIME,
        hostname text TSTAG,
        region text TSTAG,
        datacenter text TSTAG,
        rack text TSTAG,
        os text TSTAG,
        arch text TSTAG,
        team text TSTAG,
        service text TSTAG,
        service_version text TSTAG,
        service_environment text TSTAG,
        usage_user float,
        usage_system float,
        usage_idle float,
        usage_nice float,
        usage_iowait float,
        usage_irq float,
        usage_softirq float,
        usage_steal float,
        usage_guest float,
        usage_guest_nice float
        ) POLICY tsbs_policy;
    CREATE INDEX ON cpu USING btree(hostname, time desc) LOCAL;
  4. Configure Grafana.

    • Add data source.

      img

      img

    • Add dashboard.

      img

      Click "Add a new panel", select the data source in "Data source".

      img

    • Ensure that the generated SQL can be run.

      SELECT
        time_bucket('60 seconds', time) AS minute,
        max(usage_user) AS max_usage_user
      FROM cpu
      WHERE
        hostname IN ('host_313') AND time >= '2022-01-01 00:36:15.552285 +0000' AND time < '2022-07-04 01:36:15.552285 +000' GROUP BY minute ORDER BY minute ASC;
      
      SELECT
        time_bucket('60 seconds', time) AS minute,
        max(usage_user) AS max_usage_user
      FROM cpu
      WHERE
        hostname IN ('host_364', 'host_337', 'host_128', 'host_151', 'host_141', 'host_226', 'host_275') AND time >= '2022-07-01 05:56:35.685235 +0000' AND time <= '2022-07-05 00:23:44.331213 +0000' 
      GROUP BY minute ORDER BY minute ASC;
    • View the execution result.

      img

Copyright © 2011-2024 www.enmotech.com All rights reserved.