|
| 1 | +Use Grafana |
| 2 | +=========== |
| 3 | + |
| 4 | +Mysql |
| 5 | +----- |
| 6 | +Add user and give SELECT rights : sudo mysql -uroot -p -e "GRANT SELECT ON PyScada_db.* TO 'Grafana-user'@'localhost' IDENTIFIED BY 'Grafana-user-password';" |
| 7 | + |
| 8 | +Nginx |
| 9 | +----- |
| 10 | +Add in /etc/nginx/nginx.conf after http { ... } : |
| 11 | +:: |
| 12 | +include /etc/nginx/grafana-access.conf; |
| 13 | +Create /etc/nginx/grafana-access.conf with : |
| 14 | +:: |
| 15 | +stream { |
| 16 | +# MySQL server |
| 17 | +server { |
| 18 | +listen 3305; |
| 19 | +proxy_pass 127.0.0.1:3306; |
| 20 | +proxy_timeout 60s; |
| 21 | +proxy_connect_timeout 30s; |
| 22 | +} |
| 23 | +} |
| 24 | +Restart Nginx : |
| 25 | +:: |
| 26 | +sudo systemctl restart nginx |
| 27 | + |
| 28 | +Grafana |
| 29 | +------- |
| 30 | +Add DB : |
| 31 | + - Host : |
| 32 | + - Local : /run/mysqld/mysqld.sock |
| 33 | + - Remote : remote_ip:3305 |
| 34 | + - Database : PyScada_db |
| 35 | + - User : Grafana-user |
| 36 | + - Password : Grafana-user-password |
| 37 | + |
| 38 | +Import the exported dashboard (json file in extras directory). |
| 39 | + |
| 40 | +Or for example, add theses variables : set refresh on dashboard load, multi-value and all option : |
| 41 | + - Add mysql datasource variable (type Datasource). |
| 42 | + - Add variables with type query using $Datasource : |
| 43 | + - Protocols : SELECT protocol AS __text, id AS __value FROM pyscada_deviceprotocol |
| 44 | + - Devices : SELECT d.short_name AS __text, d.id AS __value FROM pyscada_device d WHERE d.protocol_id IN (${Protocols}) AND d.active = 1 |
| 45 | + - Units : SELECT u.unit AS __text, u.id AS __value FROM pyscada_unit u |
| 46 | + - Variables : SELECT v.name AS __text, v.id AS __value FROM pyscada_variable v WHERE v.device_id IN (${Devices}) AND v.unit_id IN (${Units}) AND v.active = 1 |
| 47 | + - Time group (type Interval) : 1s,10s,1m,10m,30m,1h,6h,12h,1d,7d,14d,30d,1M |
| 48 | + - Null as (type custom) : 0, NULL, previous |
| 49 | + |
| 50 | +Example query : |
| 51 | +:: |
| 52 | +SELECT |
| 53 | +$__timeGroupAlias(r.date_saved,$time_group), |
| 54 | +avg(IFNULL(r.value_float64, 0.0) + IFNULL(r.value_int64, 0.0) + IFNULL(r.value_int32, 0.0) + IFNULL(r.value_int16, 0.0) + IFNULL(r.value_boolean, 0.0)), |
| 55 | +v.name AS metric |
| 56 | +FROM pyscada_recordeddata as r |
| 57 | +JOIN pyscada_variable v ON r.variable_id = v.id |
| 58 | +WHERE |
| 59 | +$__timeFilter(r.date_saved) AND |
| 60 | +r.variable_id IN (${Variables}) |
| 61 | +GROUP BY time, metric |
| 62 | +ORDER BY $__timeGroup(r.date_saved,$time_group,$null_as) |
| 63 | + |
| 64 | +Embed in pyscada HMI |
| 65 | +-------------------- |
| 66 | +Edit Grafana config file: |
| 67 | +:: |
| 68 | +sudo nano /etc/grafana/grafana.ini |
| 69 | + |
| 70 | +Find and set : |
| 71 | + - allow_embedding = true |
| 72 | + - For localhost grafana : root_url = http://localhost:3000/grafana/ |
| 73 | + |
| 74 | +For localhost grafana add in /etc/nginx/sites-enabled/pyscada.conf : |
| 75 | +:: |
| 76 | +location /grafana/ { |
| 77 | +proxy_pass http://127.0.0.1:3000/; |
| 78 | +} |
| 79 | +Restart Grafana server: |
| 80 | +:: |
| 81 | +sudo systemctl restart grafana-server.service |
| 82 | +Create a custom html panel with the code from a dashboard or a panel from sharing options in grafana |
| 83 | + |
| 84 | +Other |
| 85 | +----- |
| 86 | +use ssl : http://www.turbogeek.co.uk/2020/09/30/grafana-how-to-configure-ssl-https-in-grafana/ |
0 commit comments