可以,使用 BI 元数据库账号连接元数据库后,执行下面这条 SQL 即可查询 ETL 的当前状态、开始时间、结束时间和运行时长。
```sql
SELECT
df.data_flow_id AS etl_id,
df.name AS etl_name,
CASE
WHEN COALESCE(ts.task_state, '') IN ('Running', 'PROCESSING') THEN 'RUNNING'
WHEN COALESCE(ts.task_state, '') IN ('Queueing', 'QUEUEING') THEN 'WAITING'
WHEN COALESCE(ts.task_state, '') IN ('Finished', 'FINISHED') THEN 'SUCCESS'
WHEN COALESCE(ts.task_state, '') IN ('Failed', 'FAILED', 'Canceled', 'CANCELED') THEN 'FAILED'
WHEN rh.status IN (2, 7, 8, 9, 10, 12) AND rh.end_time IS NULL THEN 'RUNNING'
WHEN rh.status = 1 THEN 'WAITING'
WHEN rh.status = 4 THEN 'SUCCESS'
WHEN rh.status IN (5, 6, 11) THEN 'FAILED'
WHEN df.status IN (2, 7, 8, 9, 10, 12)
AND df.last_exec_start_time IS NOT NULL
AND (df.last_exec_end_time IS NULL OR df.last_exec_end_time < df.last_exec_start_time) THEN 'RUNNING'
WHEN df.status = 1 THEN 'WAITING'
WHEN df.status = 4 THEN 'SUCCESS'
WHEN df.status IN (5, 6, 11) THEN 'FAILED'
ELSE 'UNKNOWN'
END AS realtime_status,
COALESCE(ts.running_time, rh.begin_time, df.last_exec_start_time) AS start_time,
COALESCE(ts.finished_time, rh.end_time, df.last_exec_end_time) AS end_time,
CASE
WHEN COALESCE(ts.running_time, rh.begin_time, df.last_exec_start_time) IS NULL THEN NULL
ELSE EXTRACT(
EPOCH FROM (
COALESCE(ts.finished_time, rh.end_time, df.last_exec_end_time, NOW())
- COALESCE(ts.running_time, rh.begin_time, df.last_exec_start_time)
)
)::bigint
END AS running_seconds,
rh.last_execute_time AS history_running_seconds,
rh.last_update_rows,
rh.task_id,
ts.task_type,
ts.task_state,
rh.status AS history_status_code,
df.status AS etl_status_code
FROM data_flow df
LEFT JOIN (
SELECT h1.*
FROM resource_update_history h1
JOIN (
SELECT dom_id, resource_id, MAX(id) AS max_id
FROM resource_update_history
GROUP BY dom_id, resource_id
) h2
ON h1.id = h2.max_id
) rh
ON rh.dom_id = df.dom_id
AND rh.resource_id = df.data_flow_id
LEFT JOIN task_status ts
ON ts.dom_id = df.dom_id
AND ts.task_id = rh.task_id
AND ts.is_del = false
WHERE df.is_del = false
AND df.dom_id = '你的dom_id'
ORDER BY COALESCE(ts.running_time, rh.begin_time, df.last_exec_start_time, df.utime) DESC;
```
如果只想查询某一个 ETL,可以补充条件:
`AND df.data_flow_id = '你的etl_id'`
|