Skip to content

Instantly share code, notes, and snippets.

@GUIpsp
Created October 15, 2025 07:42
Show Gist options
  • Select an option

  • Save GUIpsp/3133d558381c726984fa4e37801792e2 to your computer and use it in GitHub Desktop.

Select an option

Save GUIpsp/3133d558381c726984fa4e37801792e2 to your computer and use it in GitHub Desktop.
SELECT
JSONExtractString(labels, 'hostname') as hostname,
argMax(JSONExtractString(labels, 'your_tag_name'), value) as tag_from_max,
max(value) as max_value
FROM signoz_metrics.distributed_samples_v2
WHERE
metric_name = 'your_metric_name'
AND timestamp_ms >= {{.start_time}}
AND timestamp_ms <= {{.end_time}}
GROUP BY JSONExtractString(labels, 'hostname')
ORDER BY max_value DESC
@GUIpsp
Copy link
Author

GUIpsp commented Oct 15, 2025

SELECT
    JSONExtractString(labels, 'hostname') AS hostname,
    argMax(JSONExtractString(labels, 'current_program_scene'), value) AS current_program_scene,
    max(value) AS max_value
FROM signoz_metrics.distributed_samples_v4
INNER JOIN
(
    SELECT DISTINCT 
        fingerprint,
        labels
    FROM signoz_metrics.distributed_time_series_v4
    WHERE (metric_name = 'scene_info')
        AND (unix_milli >= intDiv({{.start_timestamp_ms}}, 3600000) * 3600000)
        AND (unix_milli < {{.end_timestamp_ms}})
) AS filtered_time_series USING (fingerprint)
WHERE (metric_name = 'scene_info')
    AND (unix_milli >= {{.start_timestamp_ms}})
    AND (unix_milli < {{.end_timestamp_ms}})
GROUP BY JSONExtractString(labels, 'hostname')
ORDER BY max_value DESC

@GUIpsp
Copy link
Author

GUIpsp commented Oct 15, 2025

SELECT
    JSONExtractString(labels, 'host.name') AS hostname,
    argMax(JSONExtractString(labels, 'current_program_scene'), (unix_milli, value)) AS current_program_scene,
    max(unix_milli) AS latest_timestamp,
    argMax(value, (unix_milli, value)) AS value_at_latest
FROM signoz_metrics.distributed_samples_v4
INNER JOIN
(
    SELECT DISTINCT 
        fingerprint,
        labels
    FROM signoz_metrics.distributed_time_series_v4
    WHERE (metric_name = 'scene_info')
        AND (unix_milli >= intDiv({{.start_timestamp_ms}}, 3600000) * 3600000)
        AND (unix_milli < {{.end_timestamp_ms}})
) AS filtered_time_series USING (fingerprint)
WHERE (metric_name = 'scene_info')
    AND (unix_milli >= {{.start_timestamp_ms}})
    AND (unix_milli < {{.end_timestamp_ms}})
GROUP BY JSONExtractString(labels, 'host.name')
ORDER BY hostname ASC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment