Update and add monitoring views

This commit is contained in:
xbgmsharp
2023-07-18 15:18:29 +02:00
parent 197e080035
commit 2eb645123b

View File

@@ -359,45 +359,75 @@ CREATE OR REPLACE VIEW api.monitoring_view WITH (security_invoker=true,security_
ORDER BY time DESC LIMIT 1; ORDER BY time DESC LIMIT 1;
COMMENT ON VIEW COMMENT ON VIEW
api.monitoring_view api.monitoring_view
IS 'Monitoring web view'; IS 'Monitoring static web view';
CREATE VIEW api.monitoring_humidity AS CREATE VIEW api.monitoring_humidity WITH (security_invoker=true,security_barrier=true) AS
SELECT SELECT m.time, key, value
time AS "time", FROM api.metrics m,
metrics-> 'environment.inside.humidity' AS insideHumidity, jsonb_each_text(m.metrics)
metrics-> 'environment.outside.humidity' AS outsideHumidity WHERE key ILIKE 'environment.%.humidity'
FROM api.metrics m ORDER BY m.time DESC;
ORDER BY time DESC LIMIT 1; COMMENT ON VIEW
api.monitoring_humidity
IS 'Monitoring environment.%.humidity web view';
-- View System RPI monitoring for grafana -- View System RPI monitoring for grafana
-- View Electric monitoring for grafana -- View Electric monitoring for grafana
-- View main monitoring for grafana -- View main monitoring for grafana
-- LAST Monitoring data from json! -- LAST Monitoring data from json!
CREATE VIEW api.monitoring_temperatures AS CREATE VIEW api.monitoring_temperatures WITH (security_invoker=true,security_barrier=true) AS
SELECT SELECT m.time, key, value
time AS "time", FROM api.metrics m,
metrics-> 'environment.water.temperature' AS waterTemperature, jsonb_each_text(m.metrics)
metrics-> 'environment.inside.temperature' AS insideTemperature, WHERE key ILIKE 'environment.%.temperature'
metrics-> 'environment.outside.temperature' AS outsideTemperature ORDER BY m.time DESC;
FROM api.metrics m COMMENT ON VIEW
ORDER BY time DESC LIMIT 1; api.monitoring_temperatures
IS 'Monitoring environment.%.temperature web view';
-- json key regexp -- json key regexp
-- https://stackoverflow.com/questions/38204467/selecting-for-a-jsonb-array-contains-regex-match -- https://stackoverflow.com/questions/38204467/selecting-for-a-jsonb-array-contains-regex-match
-- Last voltage data from json! -- Last voltage data from json!
CREATE VIEW api.monitoring_voltage AS CREATE VIEW api.monitoring_voltage WITH (security_invoker=true,security_barrier=true) AS
SELECT m.time, key, value
FROM api.metrics m,
jsonb_each_text(m.metrics)
WHERE key ILIKE 'electrical.%.voltage'
ORDER BY m.time DESC;
COMMENT ON VIEW
api.monitoring_voltage
IS 'Monitoring electrical.%.voltage web view';
-- Last whatever data from json!
CREATE VIEW api.monitoring_view2 WITH (security_invoker=true,security_barrier=true) AS
SELECT SELECT
time AS "time", *
cast(metrics-> 'electrical.batteries.AUX2.voltage' AS numeric) AS AUX2, FROM
cast(metrics-> 'electrical.batteries.House.voltage' AS numeric) AS House, jsonb_each(
cast(metrics-> 'environment.rpi.pijuice.gpioVoltage' AS numeric) AS gpioVoltage, ( SELECT metrics FROM api.metrics m ORDER BY time DESC LIMIT 1)
cast(metrics-> 'electrical.batteries.Seatalk.voltage' AS numeric) AS SeatalkVoltage, );
cast(metrics-> 'electrical.batteries.Starter.voltage' AS numeric) AS StarterVoltage, -- WHERE key ilike 'tanks.%.capacity%'
cast(metrics-> 'environment.rpi.pijuice.batteryVoltage' AS numeric) AS RPIBatteryVoltage, -- or key ilike 'electrical.solar.%.panelPower'
cast(metrics-> 'electrical.batteries.victronDevice.voltage' AS numeric) AS victronDeviceVoltage -- or key ilike 'electrical.batteries%stateOfCharge'
FROM api.metrics m -- or key ilike 'tanks\.%currentLevel'
ORDER BY time DESC LIMIT 1; COMMENT ON VIEW
api.monitoring_view2
IS 'Monitoring Last whatever data from json web view';
-- Timeseries whatever data from json!
CREATE VIEW api.monitoring_view3 WITH (security_invoker=true,security_barrier=true) AS
SELECT m.time, key, value
FROM api.metrics m,
jsonb_each_text(m.metrics)
ORDER BY m.time DESC;
-- WHERE key ILIKE '%257.voltage';
-- WHERE key ilike 'tanks.%.capacity%'
-- or key ilike 'electrical.solar.%.panelPower'
-- or key ilike 'electrical.batteries%stateOfCharge';
COMMENT ON VIEW
api.monitoring_view3
IS 'Monitoring Timeseries whatever data from json web view';
-- Infotiles web app -- Infotiles web app
CREATE OR REPLACE VIEW api.total_info_view WITH (security_invoker=true,security_barrier=true) AS CREATE OR REPLACE VIEW api.total_info_view WITH (security_invoker=true,security_barrier=true) AS
@@ -409,4 +439,4 @@ CREATE OR REPLACE VIEW api.total_info_view WITH (security_invoker=true,security_
SELECT * FROM l,s,m; SELECT * FROM l,s,m;
COMMENT ON VIEW COMMENT ON VIEW
api.total_info_view api.total_info_view
IS 'Monitoring web view'; IS 'total_info_view web view';