Skip to content

Commit 03408fd

Browse files
committed
Fix actor parking example
Signed-off-by: Shubham Sharma <[email protected]>
1 parent a8dd899 commit 03408fd

File tree

14 files changed

+543
-87
lines changed

14 files changed

+543
-87
lines changed
Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
1-
# Examples - Hello World
1+
# Actor Parking Sensor
22

3-
## TODO
3+
This example shows a car parking area where cars (virtual actors) enter and leave randomly. The car sensor data is sent via Dapr actors to InfluxDB and displayed on Grafana.
4+
5+
## Prerequisites
6+
7+
Start influxdb, telegraf and grafana using docker-compose.
48

59
```bash
6-
# Run InfluxDB
7-
# Note: it auto removes after shutdown
8-
# Note: non-persistent volume, add "-v influxdb2:/var/lib/influxdb2" to make it persistent
9-
docker run --rm -it -d \
10-
-e DOCKER_INFLUXDB_INIT_MODE=setup \
11-
-e DOCKER_INFLUXDB_INIT_USERNAME=admin \
12-
-e DOCKER_INFLUXDB_INIT_PASSWORD=MyAdmin@123! \
13-
-e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-token \
14-
-e DOCKER_INFLUXDB_INIT_ORG=my-parking-garage \
15-
-e DOCKER_INFLUXDB_INIT_BUCKET=my-sensors \
16-
--net=host \
17-
--name influxdb \
18-
influxdb:2.0
19-
20-
# Run Telegraf
21-
docker run --rm -it -d \
22-
--net=host \
23-
--name=telegraf \
24-
telegraf
25-
26-
# Run Grafana
27-
# Note: non-persistent volume, add "-v influxdb2:/var/lib/influxdb2" to make it persistent
28-
docker run --rm -it -d \
29-
--name=grafana \
30-
--net=host \
31-
grafana/grafana
10+
docker-compose up
3211
```
3312

3413
## Running
@@ -40,22 +19,18 @@ docker run --rm -it -d \
4019
# Install (from the example directory)
4120
npm install
4221

43-
# Start a RabbitMQ Container (for the binding example part)
44-
# note: mgmt interface at http://localhost:15672
45-
docker run -d --rm --hostname my-rabbitmq --name my-rabbitmq \
46-
-e RABBITMQ_DEFAULT_USER=test-user -e RABBITMQ_DEFAULT_PASS=test-password \
47-
-p 0.0.0.0:5672:5672 -p 0.0.0.0:15672:15672 \
48-
rabbitmq:3-management
49-
50-
# Run the example
22+
# Build and run the example
23+
npm run build
5124
npm run start:dapr
5225
```
5326

54-
```
55-
from(bucket: "my-sensors")
56-
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
57-
|> filter(fn: (r) => r["_measurement"] == "sensor-states")
58-
|> pivot(columnKey: ["_field"], rowKey: ["_time"], valueColumn: "_value")
59-
|> group()
60-
|> yield(name: "last")
61-
```
27+
## Visualize
28+
29+
Start grafana on localhost:3001 and use `admin`/`password` to login and visualize the dashboard!
30+
31+
Sample:
32+
![output.png](./output.png "Sample output")
33+
34+
## References
35+
1. Original blog post: https://xaviergeerinck.com/post/2021/10/09/parking-garage
36+
1. Influx/Telgraf/Grafana setup inspired from: https://github.com/bcremer/docker-telegraf-influx-grafana-stack
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Grafana options
2+
GF_SECURITY_ADMIN_USER=admin
3+
GF_SECURITY_ADMIN_PASSWORD=password
4+
GF_INSTALL_PLUGINS=
5+
6+
7+
# InfluxDB options
8+
DOCKER_INFLUXDB_INIT_MODE=setup
9+
DOCKER_INFLUXDB_INIT_USERNAME=admin
10+
DOCKER_INFLUXDB_INIT_PASSWORD=MyAdmin@123!
11+
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-token
12+
DOCKER_INFLUXDB_INIT_ORG=my-parking-garage
13+
DOCKER_INFLUXDB_INIT_BUCKET=my-sensors
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
version: '3.7'
2+
services:
3+
telegraf:
4+
image: telegraf:1.22.3-alpine
5+
volumes:
6+
- ./telegraf/etc/telegraf.conf:/etc/telegraf/telegraf.conf:ro
7+
depends_on:
8+
- influxdb
9+
links:
10+
- influxdb
11+
ports:
12+
- '127.0.0.1:8125:8125/udp'
13+
14+
influxdb:
15+
image: influxdb:2.2.0-alpine
16+
env_file: configuration.env
17+
ports:
18+
- '127.0.0.1:8086:8086'
19+
volumes:
20+
- ./:/imports
21+
- influxdb_data:/var/lib/influxdb
22+
23+
grafana:
24+
image: grafana/grafana:8.5.1
25+
depends_on:
26+
- influxdb
27+
env_file: configuration.env
28+
links:
29+
- influxdb
30+
ports:
31+
- '127.0.0.1:3001:3000'
32+
volumes:
33+
- grafana_data:/var/lib/grafana
34+
- ./grafana/provisioning/:/etc/grafana/provisioning/
35+
- ./grafana/dashboards/:/var/lib/grafana/dashboards/
36+
37+
volumes:
38+
grafana_data: {}
39+
influxdb_data: {}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": "-- Grafana --",
7+
"enable": true,
8+
"hide": true,
9+
"iconColor": "rgba(0, 211, 255, 1)",
10+
"name": "Annotations & Alerts",
11+
"target": {
12+
"limit": 100,
13+
"matchAny": false,
14+
"tags": [],
15+
"type": "dashboard"
16+
},
17+
"type": "dashboard"
18+
}
19+
]
20+
},
21+
"editable": true,
22+
"fiscalYearStartMonth": 0,
23+
"gnetId": null,
24+
"graphTooltip": 0,
25+
"id": 1,
26+
"links": [],
27+
"liveNow": false,
28+
"panels": [
29+
{
30+
"datasource": null,
31+
"fieldConfig": {
32+
"defaults": {
33+
"color": {
34+
"mode": "thresholds"
35+
},
36+
"mappings": [],
37+
"thresholds": {
38+
"mode": "absolute",
39+
"steps": [
40+
{
41+
"color": "green",
42+
"value": null
43+
},
44+
{
45+
"color": "red",
46+
"value": 1
47+
}
48+
]
49+
}
50+
},
51+
"overrides": []
52+
},
53+
"gridPos": {
54+
"h": 25,
55+
"w": 24,
56+
"x": 0,
57+
"y": 0
58+
},
59+
"id": 2,
60+
"options": {
61+
"basemap": {
62+
"config": {},
63+
"type": "osm-standard"
64+
},
65+
"controls": {
66+
"mouseWheelZoom": true,
67+
"showAttribution": true,
68+
"showDebug": false,
69+
"showScale": false,
70+
"showZoom": true
71+
},
72+
"layers": [
73+
{
74+
"config": {
75+
"color": {
76+
"field": "isParked",
77+
"fixed": "dark-green"
78+
},
79+
"fillOpacity": 0.4,
80+
"shape": "circle",
81+
"showLegend": true,
82+
"size": {
83+
"fixed": 3,
84+
"max": 15,
85+
"min": 2
86+
},
87+
"style": {
88+
"color": {
89+
"field": "isParked",
90+
"fixed": "dark-green"
91+
}
92+
}
93+
},
94+
"location": {
95+
"mode": "auto"
96+
},
97+
"type": "markers"
98+
}
99+
],
100+
"view": {
101+
"id": "coords",
102+
"lat": 47.641728,
103+
"lon": -122.140278,
104+
"zoom": 19.24
105+
}
106+
},
107+
"targets": [
108+
{
109+
"query": "from(bucket: \"my-sensors\")\r\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\r\n |> filter(fn: (r) => r[\"_measurement\"] == \"sensor-states\")\r\n |> pivot(columnKey: [\"_field\"], rowKey: [\"_time\"], valueColumn: \"_value\")\r\n |> group()\r\n |> yield(name: \"last\")",
110+
"refId": "A"
111+
}
112+
],
113+
"title": "Car Parking",
114+
"type": "geomap"
115+
}
116+
],
117+
"refresh": "5s",
118+
"schemaVersion": 31,
119+
"style": "dark",
120+
"tags": [],
121+
"templating": {
122+
"list": []
123+
},
124+
"time": {
125+
"from": "now-6h",
126+
"to": "now"
127+
},
128+
"timepicker": {},
129+
"timezone": "",
130+
"title": "Parking Garage",
131+
"uid": "Px36rBv7z",
132+
"version": 5
133+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: 1
2+
3+
providers:
4+
- name: 'default'
5+
orgId: 1
6+
folder: ''
7+
type: file
8+
disableDeletion: false
9+
updateIntervalSeconds: 3 #how often Grafana will scan for changed dashboards
10+
options:
11+
path: /var/lib/grafana/dashboards
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# config file version
2+
apiVersion: 1
3+
4+
# list of datasources that should be deleted from the database
5+
deleteDatasources:
6+
- name: Influxdb
7+
orgId: 1
8+
9+
# list of datasources to insert/update depending
10+
# whats available in the database
11+
datasources:
12+
# <string, required> name of the datasource. Required
13+
- name: InfluxDB
14+
# <string, required> datasource type. Required
15+
type: influxdb
16+
# <string, required> access mode. direct or proxy. Required
17+
access: proxy
18+
# <int> org id. will default to orgId 1 if not specified
19+
orgId: 1
20+
# <string> url
21+
url: http://influxdb:8086
22+
# <bool> enable/disable basic auth
23+
basicAuth: true
24+
# <bool> mark as default datasource. Max one per org
25+
isDefault: true
26+
# <map> fields that will be converted to json and stored in json_data
27+
jsonData:
28+
version: Flux
29+
organization: my-parking-garage
30+
defaultBucket: my-sensors
31+
tlsSkipVerify: true
32+
secureJsonData:
33+
token: my-token
34+
version: 1
35+
# <bool> allow users to edit datasources from the UI.
36+
editable: false
463 KB
Loading

0 commit comments

Comments
 (0)