You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Draft to extend metrics with daily/monthly/yearly stats (#3)
* First draft to extend metrics with daily/monthly/yearly stats
* Use TypeScript
* Update `series` and `ranking` functions
* Add types
* Remove unused tests
* Update README.md
* Update dashboard
* Update README.md
* Use sls-analytics name again
Copy file name to clipboardExpand all lines: README.md
+73-18Lines changed: 73 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,33 @@
5
5
6
6
Example project for a personal [serverless](https://serverless.com)*Google Analytics* clone to track website visitors.
7
7
8
-
After deploying the service you will have a HTTP endpoint using API Gateway that accepts requests and puts them into a Kinesis Stream. A Lambda function processes the stream and writes a basic metric about how many visitors you have per absolute URL to DynamoDB.
8
+
After deploying the service you will have an HTTP endpoint using Amazon API Gateway that accepts requests and puts them into a Kinesis Stream. A Lambda function processes the stream and writes basic metrics about how many visitors you have per absolute URL to DynamoDB.
9
+
10
+
To access the tracked data, a basic dashboard with a JSON API is included as well. This should be a perfect starting point for you to create your own analytics service.
9
11
10
12
## Components
11
13
12
14
#### Tracking Service
13
15
14
16
- Amazon Kinesis to stream visitor events
15
-
- Amazon API Gateway as HTTP proxy for Kinesis
17
+
- Amazon API Gateway for Kinesis HTTP proxy
16
18
- Amazon DynamoDB for data storage
17
19
- AWS Lambda to process visitor events
18
20
19
-
#### Examples
21
+
#### Dashboard
22
+
23
+
- Amazon API Gateway for JSON API
24
+
-[Dashboard w/ API to show metrics](http://sls-analytics-website-dashboard.s3-website-us-east-1.amazonaws.com/)
25
+
26
+
#### Example
20
27
21
28
-[Static website to track visitors](http://sls-analytics-website-example.s3-website-us-east-1.amazonaws.com)
22
-
-[API & Dashboard to show metrics](http://sls-analytics-website-dashboard.s3-website-us-east-1.amazonaws.com/)
29
+
30
+
*The use of two API Gateways (data tracking and reading) is intended. You might have different settings for tracking and data access when you build something meaningful out of this example.*
23
31
24
32
## Configuration
25
33
26
-
All settings can be changes in the `serverless.yml` configuration file. You can easily change the DynamoDB Table, Kinesis Stream and API Gateway Resource names:
34
+
All settings can be customized in the `serverless.yml` configuration file. You can easily change the DynamoDB Table, Kinesis Stream and API Gateway tracking resource name:
27
35
28
36
```yaml
29
37
service: sls-analytics
@@ -38,13 +46,13 @@ custom:
38
46
kinesis: ${self:service}-stream
39
47
```
40
48
41
-
The S3 Bucket configuration is only needed for the included example website. If you don't need the example sites, have a look at the `scripts/deploy.sh` file and disable the deployment and remove the CloudFormation resources from the `serverless.yml` file.
49
+
The S3 Bucket configuration is only needed for the included example website and dashboard. If you don't need the examples, have a look at the `scripts/deploy.sh` file and disable the deployment and remove the CloudFormation resources from the `serverless.yml` file.
42
50
43
51
*Amazon requires unique names for S3 buckets and other resources. Please rename at least the service before you try to deploy the example!*
44
52
45
53
## Deployment
46
54
47
-
Running `yarn deploy` will trigger a default [serverless](https://serverless.com) deployment. After the output of the CloudFormation Stack is available, the included static websites will be generated *(Using the hostname from the stack output)* and uploaded to the configured S3 buckets. As the final step, the deploy process will display the URL of the example website and data dashboard:
55
+
Running `yarn deploy` will trigger a [serverless](https://serverless.com) deployment. After the output of your CloudFormation Stack is available, the included static websites will be generated *(using the hostname from the stack output)* and uploaded to the configured S3 buckets. As the last step, the deploy process will display the URLs of the example website and dashboard:
The **website** includes a simple HTML file, some stylings, and a few JavaScript lines that send a request to your API on every page load. Visit your URL, hit a few times the refresh button and take a look at the DynamoDB table or the **dashboard** URL.
69
+
The **website** includes a simple HTML file, some stylings, and a few JavaScript lines that send a request to the tracking API on every page load. Open the URL in a web browser, hit a few times the refresh button and take a look at the DynamoDB table or the **dashboard** URL.
62
70
63
71
## Tracking
64
72
65
-
Basically tracking is nothing more than a HTTP request to the API Gateway with a set of payload information *(currently just `url` and `name`)*. Normally you would have a non-JS fallback, like an image e.g., but a simple `fetch` call does the job for now:
73
+
Basically, tracking is nothing more than sending a HTTP request to the API with a set of payload information *(currently `url`, `date`, `name`, and a `websiteId`)*. Normally you would have an additional non-JS fallback, like an image e.g., but a simple `fetch` call does the job for now:
headers: new Headers({ "Content-Type": "application/json" })
78
89
}
79
90
)
80
91
```
81
92
82
93
## Data Access
83
94
84
-
You can get a list of all tracked data by invoking the `list` function, or just have a look into your DynamoDB or use the included dashboard.
95
+
An example [dashboard to access tracked data](http://sls-analytics-website-dashboard.s3-website-us-east-1.amazonaws.com/) is included and deployed to S3. The URL will be displayed after the `deploy` task. You can access the metrics using basic `curl` requests as well. Just provide the `website` and `date` parameters:
96
+
97
+
### Top Content
98
+
99
+
The `ranking` resource scans the DynamoDB for pages with the most hits on a specific `date` value:
The DynamoDB stores the absolute hits number for the dimensions `YEAR`, `MONTH`, `DATE`, `HOUR`, and `MINUTE` per default. This may cause lots of write capacities when processing events, but with the [serverless-dynamodb-autoscaling](https://github.com/sbstjn/serverless-dynamodb-autoscaling) plugin DynamoDB will scale the capacities when needed.
0 commit comments