Coder Social home page Coder Social logo

Add more dashboards about clickhouse HOT 1 OPEN

serxa avatar serxa commented on May 27, 2024
Add more dashboards

from clickhouse.

Comments (1)

serxa avatar serxa commented on May 27, 2024

Here is a template for all types of charts that are now available to be built from system tables using new features:

CurrentMetric (system.metric_log)

Single line

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  avg(metric)
FROM (
  SELECT event_time, sum(CurrentMetric_Query) AS metric
  FROM clusterAllReplicas(default, merge('system', '^metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
  GROUP BY event_time)
GROUP BY t
ORDER BY t WITH FILL STEP {rounding:UInt32} SETTINGS skip_unavailable_shards = 1

Two-lines

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  avg(SystemReplicasThreads),
  avg(SystemReplicasThreadsActive)
FROM (
  SELECT event_time,
    sum(CurrentMetric_SystemReplicasThreads) AS SystemReplicasThreads,
    sum(CurrentMetric_SystemReplicasThreadsActive) AS SystemReplicasThreadsActive
  FROM clusterAllReplicas(default, merge('system', '^metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
  GROUP BY event_time)
GROUP BY t
ORDER BY t SETTINGS skip_unavailable_shards = 1

Single line per host (double group by is not required)

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  hostname() as label,
  avg(CurrentMetric_SystemReplicasThreadsActive)
FROM clusterAllReplicas(default, merge('system', '^metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
GROUP BY t, label
ORDER BY t, label SETTINGS skip_unavailable_shards = 1

ProfileEvent (system.metric_log)

Single line

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  avg(metric)
FROM (
  SELECT event_time, sum(ProfileEvent_Query) AS metric
  FROM clusterAllReplicas(default, merge('system', '^metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
  GROUP BY event_time)
GROUP BY t
ORDER BY t WITH FILL STEP {rounding:UInt32} SETTINGS skip_unavailable_shards = 1

Two-line

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  avg(SelectQuery),
  avg(InsertQuery)
FROM (
  SELECT event_time,
    sum(ProfileEvent_SelectQuery) AS SelectQuery,
    sum(ProfileEvent_InsertQuery) AS InsertQuery
  FROM clusterAllReplicas(default, merge('system', '^metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
  GROUP BY event_time)
GROUP BY t
ORDER BY t SETTINGS skip_unavailable_shards = 1

Single line per host (double group by is required: first sum on second scale, then average over rounding interval)

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  label,
  avg(metric)
FROM (
  SELECT event_time,
    hostname() as label,
    sum(ProfileEvent_Query) AS metric
  FROM clusterAllReplicas(default, merge('system', '^metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
  GROUP BY event_time, label)
GROUP BY t, label
ORDER BY t, label SETTINGS skip_unavailable_shards = 1

AsynchronousMetrics (system.asynchronous_metric_log)

Single line

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  avg(value)
FROM
  clusterAllReplicas(default, merge('system', '^asynchronous_metric_log'))
WHERE event_date >= toDate(now() - {seconds:UInt32})
  AND event_time >= now() - {seconds:UInt32}
  AND metric = 'OSSystemTimeNormalized'
GROUP BY t
ORDER BY t WITH FILL STEP {rounding:UInt32} SETTINGS skip_unavailable_shards = 1

Multiple metrics

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  metric as label,
  avg(value)
FROM
  clusterAllReplicas(default, merge('system', '^asynchronous_metric_log'))
WHERE event_date >= toDate(now() - {seconds:UInt32})
  AND event_time >= now() - {seconds:UInt32}
  AND metric in ['OSSystemTimeNormalized', 'OSUserTimeNormalized', 'OSIrqTimeNormalized']
GROUP BY t, label
ORDER BY t, label SETTINGS skip_unavailable_shards = 1

Single line per host (double group by is not required)

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  hostname() as label,
  avg(value)
FROM
  clusterAllReplicas(default, merge('system', '^asynchronous_metric_log'))
WHERE event_date >= toDate(now() - {seconds:UInt32})
  AND event_time >= now() - {seconds:UInt32}
  AND metric = 'OSUserTimeNormalized'
GROUP BY t, label
ORDER BY t, label SETTINGS skip_unavailable_shards = 1

Read/Write on the same chart (I'm not sure if this one is actually a good idea)

SELECT
  toStartOfInterval(event_time, INTERVAL {rounding:UInt32} SECOND)::INT AS t,
  label,
  avg(if(label='NetworkReceiveBytes', value, -value))
FROM (
  SELECT event_time,
    sum(value) AS value,
    if(metric LIKE 'NetworkReceiveBytes%', 'NetworkReceiveBytes', 'NetworkSendBytes') as label
  FROM clusterAllReplicas(default, merge('system', '^asynchronous_metric_log'))
  WHERE event_date >= toDate(now() - {seconds:UInt32})
    AND event_time >= now() - {seconds:UInt32}
    AND (metric LIKE 'NetworkReceiveBytes%' OR metric LIKE 'NetworkSendBytes%')
  GROUP BY event_time, label)
GROUP BY t, label
ORDER BY t, label SETTINGS skip_unavailable_shards = 1

from clickhouse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.