diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c76778 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# FDLogUp +This project uses [Bun](https://bun.sh/) to build a client executable and to run the server with. To install use this oneliner: +```sh +curl -fsSL https://bun.sh/install | bash +``` + +To build the client: +```sh +cd client +bun run exe +``` + +To run the server: +```sh +cd server +bun start +``` + +The provided docker-compose file sets up a PostgreSQL server and a Grafana instance. +There is also a Grafana dashboard JSON file for an example use of the data. +Make sure to import the `server/schema.sql` into PostgreSQL before using it. diff --git a/grafana-dashboard.json b/grafana-dashboard.json new file mode 100644 index 0000000..37cdc98 --- /dev/null +++ b/grafana-dashboard.json @@ -0,0 +1,852 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 1, + "links": [], + "panels": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 3, + "x": 0, + "y": 0 + }, + "id": 5, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.0.0", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "builder", + "format": "table", + "rawSql": "SELECT COUNT(*) FROM contacts LIMIT 50 ", + "refId": "A", + "sql": { + "columns": [ + { + "name": "COUNT", + "parameters": [ + { + "name": "*", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + }, + "table": "contacts" + } + ], + "title": "Total Contact Count", + "type": "stat" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "#EAB839", + "value": 15 + }, + { + "color": "red", + "value": 30 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 8, + "x": 3, + "y": 0 + }, + "id": 3, + "options": { + "basemap": { + "config": { + "showLabels": true, + "theme": "auto" + }, + "type": "carto" + }, + "controls": { + "mouseWheelZoom": true, + "showAttribution": true, + "showDebug": false, + "showLayercontrol": false, + "showScale": true, + "showZoom": true + }, + "layers": [ + { + "config": { + "cluster": false, + "clusterDistance": 6, + "clusterMinDistance": 0, + "clusterValue": "size", + "color": { + "field": "Contacts", + "fixed": "dark-green" + }, + "enableGradient": false, + "enableShadow": false, + "fillOpacity": 0.2, + "iconSize": 9, + "pinShape": "triangle", + "selectIcon": "", + "shape": "circle", + "showLegend": false, + "showPin": false, + "size": { + "fixed": 1, + "max": 15, + "min": 2 + } + }, + "displayProperties": [ + "Contacts" + ], + "location": { + "geojson": "geojson", + "mode": "geojson" + }, + "name": "Contacts", + "query": "A", + "titleField": "state", + "type": "markers" + } + ], + "view": { + "id": "north-america", + "lat": 40, + "lon": -100, + "zoom": 4 + } + }, + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT s.name as \"state\", s.geojson, COUNT(*) AS \"Contacts\"\r\nFROM contacts c\r\nJOIN states s ON c.state = s.id\r\nGROUP BY s.name, s.geojson;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "*", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50, + "whereJsonTree": { + "children1": [], + "id": "aa8bb9bb-0123-4456-b89a-b19037fa2cf6", + "type": "group" + } + }, + "table": "states" + } + ], + "title": "All Contacts (Map)", + "type": "orchestracities-map-panel" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Contacts" + }, + "properties": [ + { + "id": "custom.width", + "value": 80 + } + ] + } + ] + }, + "gridPos": { + "h": 11, + "w": 4, + "x": 11, + "y": 0 + }, + "id": 4, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "enablePagination": true, + "fields": "", + "reducer": [ + "sum" + ], + "show": true + }, + "showHeader": true + }, + "pluginVersion": "11.0.0", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT s.name as \"State\", COUNT(*) AS \"Contacts\"\r\nFROM contacts c\r\nJOIN states s ON c.state = s.id\r\nGROUP BY s.name;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "All Contacts", + "type": "table" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Contacts" + }, + "properties": [ + { + "id": "custom.width", + "value": 80 + } + ] + } + ] + }, + "gridPos": { + "h": 11, + "w": 4, + "x": 15, + "y": 0 + }, + "id": 9, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "enablePagination": false, + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true + }, + "pluginVersion": "11.0.0", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "builder", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT operator AS \"Operator\", COUNT(*) AS \"Count\" FROM contacts GROUP BY operator ORDER BY COUNT(*) DESC LIMIT 10 ", + "refId": "A", + "sql": { + "columns": [ + { + "alias": "\"Operator\"", + "parameters": [ + { + "name": "operator", + "type": "functionParameter" + } + ], + "type": "function" + }, + { + "alias": "\"Count\"", + "name": "COUNT", + "parameters": [ + { + "name": "*", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "name": "operator", + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 10, + "orderBy": { + "property": { + "name": "COUNT(*)", + "type": "string" + }, + "type": "property" + }, + "orderByDirection": "DESC" + }, + "table": "contacts" + } + ], + "title": "Top Operators", + "type": "table" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 3, + "x": 0, + "y": 11 + }, + "id": 6, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.0.0", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "builder", + "format": "table", + "rawSql": "SELECT COUNT(*) FROM contacts WHERE $__timeFilter(\"time\") LIMIT 50 ", + "refId": "A", + "sql": { + "columns": [ + { + "name": "COUNT", + "parameters": [ + { + "name": "*", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50, + "whereJsonTree": { + "children1": [ + { + "id": "a88a9ba9-4567-489a-bcde-f1903e7c367e", + "properties": { + "field": "\"time\"", + "fieldSrc": "field", + "operator": "macros", + "value": [ + "timeFilter" + ], + "valueSrc": [ + "value" + ], + "valueType": [ + "datetime" + ] + }, + "type": "rule" + } + ], + "id": "98bab9aa-0123-4456-b89a-b1903e74eda4", + "type": "group" + }, + "whereString": "$__timeFilter(\"time\")" + }, + "table": "contacts" + } + ], + "title": "Recent Contact Count", + "type": "stat" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "#EAB839", + "value": 15 + }, + { + "color": "red", + "value": 30 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 8, + "x": 3, + "y": 11 + }, + "id": 7, + "options": { + "basemap": { + "config": { + "showLabels": true, + "theme": "auto" + }, + "type": "carto" + }, + "controls": { + "mouseWheelZoom": true, + "showAttribution": true, + "showDebug": false, + "showLayercontrol": false, + "showScale": true, + "showZoom": true + }, + "layers": [ + { + "config": { + "cluster": false, + "clusterDistance": 6, + "clusterMinDistance": 0, + "clusterValue": "size", + "color": { + "field": "Contacts", + "fixed": "dark-green" + }, + "enableGradient": false, + "enableShadow": false, + "fillOpacity": 0.2, + "iconSize": 9, + "pinShape": "triangle", + "selectIcon": "", + "shape": "circle", + "showLegend": false, + "showPin": false, + "size": { + "fixed": 1, + "max": 15, + "min": 2 + } + }, + "displayProperties": [ + "Contacts" + ], + "location": { + "geojson": "geojson", + "mode": "geojson" + }, + "name": "Contacts", + "query": "A", + "titleField": "state", + "type": "markers" + } + ], + "view": { + "id": "north-america", + "lat": 40, + "lon": -100, + "zoom": 4 + } + }, + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT s.name as \"state\", s.geojson, COUNT(*) AS \"Contacts\"\r\nFROM contacts c\r\nJOIN states s ON c.state = s.id\r\nWHERE $__timeFilter(\"time\")\r\nGROUP BY s.name, s.geojson;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [ + { + "name": "*", + "type": "functionParameter" + } + ], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50, + "whereJsonTree": { + "children1": [], + "id": "aa8bb9bb-0123-4456-b89a-b19037fa2cf6", + "type": "group" + } + }, + "table": "states" + } + ], + "title": "Recent Contacts (Map)", + "type": "orchestracities-map-panel" + }, + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "Contacts" + }, + "properties": [ + { + "id": "custom.width", + "value": 80 + } + ] + } + ] + }, + "gridPos": { + "h": 11, + "w": 4, + "x": 11, + "y": 11 + }, + "id": 8, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "enablePagination": true, + "fields": "", + "reducer": [ + "sum" + ], + "show": true + }, + "showHeader": true + }, + "pluginVersion": "11.0.0", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "edpbbm8hqv9j4e" + }, + "editorMode": "code", + "format": "table", + "rawQuery": true, + "rawSql": "SELECT s.name as \"State\", COUNT(*) AS \"Contacts\"\r\nFROM contacts c\r\nJOIN states s ON c.state = s.id\r\nWHERE $__timeFilter(\"time\")\r\nGROUP BY s.name;", + "refId": "A", + "sql": { + "columns": [ + { + "parameters": [], + "type": "function" + } + ], + "groupBy": [ + { + "property": { + "type": "string" + }, + "type": "groupBy" + } + ], + "limit": 50 + } + } + ], + "title": "Recent Contacts", + "type": "table" + } + ], + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timeRangeUpdatedDuringEditOrView": false, + "timepicker": {}, + "timezone": "browser", + "title": "New dashboard", + "uid": "fdpbhdsbrhs74f", + "version": 10, + "weekStart": "" +} diff --git a/server/pm2.json b/server/pm2.json new file mode 100644 index 0000000..27d0492 --- /dev/null +++ b/server/pm2.json @@ -0,0 +1,10 @@ +{ + "apps": [ + { + "name": "FDLogUp", + "script": "index.ts", + "interpreter": "bun", + "interpreter_args": "run" + } + ] +}