Browse Source
allow longer event type strings in db add graf container w/ pre-built dashboard remove elasticsearch and use db based event logging add init command Co-authored-by: lza_menace <lza_menace@protonmail.com> Reviewed-on: #3add_server_msg
13 changed files with 389 additions and 71 deletions
@ -1,9 +0,0 @@
@@ -1,9 +0,0 @@
|
||||
FROM ubuntu:19.10 |
||||
WORKDIR /srv |
||||
COPY requirements.txt . |
||||
RUN apt-get update && apt-get install python3-pip -y |
||||
RUN python3 -m pip install -r requirements.txt |
||||
COPY wowstash wowstash/ |
||||
COPY bin/ bin/ |
||||
EXPOSE 4001 |
||||
CMD ["/srv/bin/prod-container"] |
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
services: |
||||
kibana: |
||||
image: docker.elastic.co/kibana/kibana:7.1.0 |
||||
ports: |
||||
- 5601:5601 |
||||
environment: |
||||
ELASTICSEARCH_HOSTS: http://elasticsearch:9200 |
||||
elasticsearch: |
||||
image: docker.elastic.co/elasticsearch/elasticsearch:7.1.0 |
||||
environment: |
||||
- discovery.type=single-node |
||||
- node.name=elasticsearch |
||||
- cluster.name=es-docker-cluster |
||||
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" |
||||
ulimits: |
||||
memlock: |
||||
soft: -1 |
||||
hard: -1 |
||||
volumes: |
||||
- ./data/elasticsearch:/usr/share/elasticsearch/data |
||||
ports: |
||||
- 9200:9200 |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
apiVersion: 1 |
||||
|
||||
providers: |
||||
- name: 'default' |
||||
orgId: 1 |
||||
folder: '' |
||||
type: file |
||||
disableDeletion: true |
||||
editable: true |
||||
updateIntervalSeconds: 60 |
||||
allowUiUpdates: true |
||||
options: |
||||
path: /var/lib/grafana/dashboards |
@ -0,0 +1,311 @@
@@ -0,0 +1,311 @@
|
||||
{ |
||||
"annotations": { |
||||
"list": [ |
||||
{ |
||||
"builtIn": 1, |
||||
"datasource": "-- Grafana --", |
||||
"enable": true, |
||||
"hide": true, |
||||
"iconColor": "rgba(0, 211, 255, 1)", |
||||
"name": "Annotations & Alerts", |
||||
"type": "dashboard" |
||||
} |
||||
] |
||||
}, |
||||
"editable": true, |
||||
"gnetId": null, |
||||
"graphTooltip": 0, |
||||
"id": 1, |
||||
"links": [], |
||||
"panels": [ |
||||
{ |
||||
"aliasColors": {}, |
||||
"bars": false, |
||||
"dashLength": 10, |
||||
"dashes": false, |
||||
"datasource": null, |
||||
"fill": 1, |
||||
"fillGradient": 0, |
||||
"gridPos": { |
||||
"h": 9, |
||||
"w": 24, |
||||
"x": 0, |
||||
"y": 0 |
||||
}, |
||||
"hiddenSeries": false, |
||||
"id": 4, |
||||
"legend": { |
||||
"avg": false, |
||||
"current": false, |
||||
"max": false, |
||||
"min": false, |
||||
"show": true, |
||||
"total": false, |
||||
"values": false |
||||
}, |
||||
"lines": true, |
||||
"linewidth": 1, |
||||
"nullPointMode": "null", |
||||
"options": { |
||||
"dataLinks": [] |
||||
}, |
||||
"percentage": false, |
||||
"pointradius": 1, |
||||
"points": true, |
||||
"renderer": "flot", |
||||
"seriesOverrides": [], |
||||
"spaceLength": 10, |
||||
"stack": false, |
||||
"steppedLine": false, |
||||
"targets": [ |
||||
{ |
||||
"format": "time_series", |
||||
"group": [ |
||||
{ |
||||
"params": [ |
||||
"$__interval", |
||||
"none" |
||||
], |
||||
"type": "time" |
||||
} |
||||
], |
||||
"metricColumn": "none", |
||||
"rawQuery": false, |
||||
"rawSql": "SELECT\n $__timeGroupAlias(register_date,$__interval),\n avg(id) AS \"id\"\nFROM users\nWHERE\n $__timeFilter(register_date)\nGROUP BY 1\nORDER BY 1", |
||||
"refId": "A", |
||||
"select": [ |
||||
[ |
||||
{ |
||||
"params": [ |
||||
"id" |
||||
], |
||||
"type": "column" |
||||
}, |
||||
{ |
||||
"params": [ |
||||
"avg" |
||||
], |
||||
"type": "aggregate" |
||||
}, |
||||
{ |
||||
"params": [ |
||||
"id" |
||||
], |
||||
"type": "alias" |
||||
} |
||||
] |
||||
], |
||||
"table": "users", |
||||
"timeColumn": "register_date", |
||||
"timeColumnType": "timestamp", |
||||
"where": [ |
||||
{ |
||||
"name": "$__timeFilter", |
||||
"params": [], |
||||
"type": "macro" |
||||
} |
||||
] |
||||
} |
||||
], |
||||
"thresholds": [], |
||||
"timeFrom": null, |
||||
"timeRegions": [], |
||||
"timeShift": null, |
||||
"title": "User Registrations", |
||||
"tooltip": { |
||||
"shared": true, |
||||
"sort": 0, |
||||
"value_type": "individual" |
||||
}, |
||||
"type": "graph", |
||||
"xaxis": { |
||||
"buckets": null, |
||||
"mode": "time", |
||||
"name": null, |
||||
"show": true, |
||||
"values": [] |
||||
}, |
||||
"yaxes": [ |
||||
{ |
||||
"format": "short", |
||||
"label": null, |
||||
"logBase": 1, |
||||
"max": null, |
||||
"min": null, |
||||
"show": true |
||||
}, |
||||
{ |
||||
"format": "short", |
||||
"label": null, |
||||
"logBase": 1, |
||||
"max": null, |
||||
"min": null, |
||||
"show": true |
||||
} |
||||
], |
||||
"yaxis": { |
||||
"align": false, |
||||
"alignLevel": null |
||||
} |
||||
}, |
||||
{ |
||||
"aliasColors": {}, |
||||
"bars": false, |
||||
"dashLength": 10, |
||||
"dashes": false, |
||||
"datasource": null, |
||||
"fill": 0, |
||||
"fillGradient": 0, |
||||
"gridPos": { |
||||
"h": 11, |
||||
"w": 24, |
||||
"x": 0, |
||||
"y": 9 |
||||
}, |
||||
"hiddenSeries": false, |
||||
"id": 2, |
||||
"legend": { |
||||
"avg": false, |
||||
"current": false, |
||||
"max": false, |
||||
"min": false, |
||||
"show": true, |
||||
"total": false, |
||||
"values": false |
||||
}, |
||||
"lines": true, |
||||
"linewidth": 2, |
||||
"nullPointMode": "null", |
||||
"options": { |
||||
"dataLinks": [] |
||||
}, |
||||
"percentage": false, |
||||
"pointradius": 2, |
||||
"points": false, |
||||
"renderer": "flot", |
||||
"seriesOverrides": [], |
||||
"spaceLength": 10, |
||||
"stack": false, |
||||
"steppedLine": false, |
||||
"targets": [ |
||||
{ |
||||
"format": "time_series", |
||||
"group": [ |
||||
{ |
||||
"params": [ |
||||
"$__interval", |
||||
"0" |
||||
], |
||||
"type": "time" |
||||
} |
||||
], |
||||
"metricColumn": "type", |
||||
"rawQuery": false, |
||||
"rawSql": "SELECT\n $__timeGroupAlias(date,$__interval,0),\n type AS metric,\n count(\"user\") AS \"id\"\nFROM events\nWHERE\n $__timeFilter(date)\nGROUP BY 1,2\nORDER BY 1,2", |
||||
"refId": "A", |
||||
"select": [ |
||||
[ |
||||
{ |
||||
"params": [ |
||||
"\"user\"" |
||||
], |
||||
"type": "column" |
||||
}, |
||||
{ |
||||
"params": [ |
||||
"count" |
||||
], |
||||
"type": "aggregate" |
||||
}, |
||||
{ |
||||
"params": [ |
||||
"id" |
||||
], |
||||
"type": "alias" |
||||
} |
||||
] |
||||
], |
||||
"table": "events", |
||||
"timeColumn": "date", |
||||
"timeColumnType": "timestamp", |
||||
"where": [ |
||||
{ |
||||
"name": "$__timeFilter", |
||||
"params": [], |
||||
"type": "macro" |
||||
} |
||||
] |
||||
} |
||||
], |
||||
"thresholds": [], |
||||
"timeFrom": null, |
||||
"timeRegions": [], |
||||
"timeShift": null, |
||||
"title": "Event Activity", |
||||
"tooltip": { |
||||
"shared": true, |
||||
"sort": 0, |
||||
"value_type": "individual" |
||||
}, |
||||
"type": "graph", |
||||
"xaxis": { |
||||
"buckets": null, |
||||
"mode": "time", |
||||
"name": null, |
||||
"show": true, |
||||
"values": [] |
||||
}, |
||||
"yaxes": [ |
||||
{ |
||||
"format": "short", |
||||
"label": "", |
||||
"logBase": 1, |
||||
"max": null, |
||||
"min": null, |
||||
"show": true |
||||
}, |
||||
{ |
||||
"format": "short", |
||||
"label": null, |
||||
"logBase": 1, |
||||
"max": null, |
||||
"min": null, |
||||
"show": false |
||||
} |
||||
], |
||||
"yaxis": { |
||||
"align": true, |
||||
"alignLevel": null |
||||
} |
||||
} |
||||
], |
||||
"refresh": false, |
||||
"schemaVersion": 21, |
||||
"style": "dark", |
||||
"tags": [], |
||||
"templating": { |
||||
"list": [] |
||||
}, |
||||
"time": { |
||||
"from": "now-6h", |
||||
"to": "now" |
||||
}, |
||||
"timepicker": { |
||||
"refresh_intervals": [ |
||||
"5s", |
||||
"10s", |
||||
"30s", |
||||
"1m", |
||||
"5m", |
||||
"15m", |
||||
"30m", |
||||
"1h", |
||||
"2h", |
||||
"1d" |
||||
] |
||||
}, |
||||
"timezone": "", |
||||
"title": "Wowstash Ops", |
||||
"uid": "zvTlfCbGz", |
||||
"version": 1 |
||||
} |
@ -1,22 +0,0 @@
@@ -1,22 +0,0 @@
|
||||
from datetime import datetime |
||||
from elasticsearch import Elasticsearch |
||||
from wowstash import config |
||||
|
||||
|
||||
def send_es(data): |
||||
if getattr(config, 'ELASTICSEARCH_ENABLED', False): |
||||
try: |
||||
es = Elasticsearch( |
||||
[getattr(config, 'ELASTICSEARCH_HOST', 'localhost')] |
||||
) |
||||
now = datetime.utcnow() |
||||
index_ts = now.strftime('%Y%m%d') |
||||
data['datetime'] = now |
||||
es.index( |
||||
index="{}-{}".format( |
||||
getattr(config, 'ELASTICSEARCH_INDEX_NAME', 'wowstash'), |
||||
index_ts |
||||
), body=data) |
||||
except Exception as e: |
||||
print('Could not capture event in Elasticsearch: ', e) |
||||
pass # I don't really care if this logs... |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
from wowstash.models import Event |
||||
from wowstash.factory import db |
||||
|
||||
|
||||
def capture_event(user_id, event_type): |
||||
event = Event( |
||||
user=user_id, |
||||
type=event_type |
||||
) |
||||
db.session.add(event) |
||||
db.session.commit() |
||||
return |
Loading…
Reference in new issue