Skip to content

Commit

Permalink
Graphs: Introduce daily reqs/bandwidth graph
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed May 17, 2021
1 parent 4be6ef0 commit 4fbc589
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 25 deletions.
2 changes: 1 addition & 1 deletion 2019/cdnjs_December_2019.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Two notes from the author:

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total Number of Requests
> The first important stat that we are given is the total number of requests sent to cdnjs.cloudflare.com.
Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_April_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ An average of 444 million requests each day!**

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_August_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ overall, generating 11.2 billion requests and consuming 361 TB of bandwidth.**

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_December_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ A note from the author:

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_February_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total Number of Requests
> The first important stat that we are given is the total number of requests sent to cdnjs.cloudflare.com.
Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_January_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A note from the author:

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total Number of Requests
> The first important stat that we are given is the total number of requests sent to cdnjs.cloudflare.com.
Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_July_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ requests in the month for the 11 files in the top 100 and consuming over 507 TB

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_June_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_March_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_May_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ the most poplar resource.**

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_November_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_October_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ A note from the author:

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2020/cdnjs_September_2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ over 841 million requests per day on average.**

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2021/cdnjs_February_2021.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2021/cdnjs_January_2021.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
2 changes: 1 addition & 1 deletion 2021/cdnjs_March_2021.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| ![cdnjs requests & bandwidth](../cdnjs_total_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ These reports are created by cdnjs with data provided by Cloudflare.

### Top 5 Resources

![graph](cdnjs_top_5_resources.png)
[![cdnjs top 5 resources graph](cdnjs_top_5_resources.png)](cdnjs_top_5_resources.png)

### Total Requests & Bandwidth Usage

![graph](cdnjs_requests_and_bandwidth.png)
[![cdnjs total requests & bandwidth graph](cdnjs_total_requests_and_bandwidth.png)](cdnjs_total_requests_and_bandwidth.png)

### Avg. Daily Requests & Bandwidth Usage

[![cdnjs avg. daily requests & bandwidth graph](cdnjs_daily_requests_and_bandwidth.png)](cdnjs_daily_requests_and_bandwidth.png)


## Previous Stats

Expand Down
Binary file added cdnjs_daily_requests_and_bandwidth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed cdnjs_requests_and_bandwidth.png
Binary file not shown.
Binary file modified cdnjs_top_5_resources.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cdnjs_total_requests_and_bandwidth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 45 additions & 4 deletions graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def top_5_resources():
fig.savefig("cdnjs_top_5_resources.png")


def requests_and_bandwidth():
def total_requests_and_bandwidth():
# Connect to the DB and get all the total data ever (from the view, not the raw table)
conn = sqlite3.connect("data.db")
conn.row_factory = sqlite3.Row
Expand Down Expand Up @@ -140,12 +140,53 @@ def requests_and_bandwidth():
ax2.set_yticklabels(["{:,.1f} PB".format(x / 1000000) for x in ax2.get_yticks().tolist()])
ax2.legend(loc="upper right", bbox_to_anchor=(1, -0.175), ncol=1, borderpad=0.75, handletextpad=1.5)

ax1.set_title("cdnjs Requests and Bandwidth")
ax1.set_title("cdnjs Total Requests and Bandwidth")
ax1.tick_params(axis="x", labelsize=8, labelrotation=45)
plt.show()
fig.savefig("cdnjs_requests_and_bandwidth.png")
fig.savefig("cdnjs_total_requests_and_bandwidth.png")


def daily_requests_and_bandwidth():
# Connect to the DB and get all the total data ever (from the view, not the raw table)
conn = sqlite3.connect("data.db")
conn.row_factory = sqlite3.Row
c = conn.cursor()
c.execute("SELECT * FROM totals")
rows = c.fetchall()

# Generate the plottable data
requests = [[], []]
bandwidth = [[], []]
months = sorted(rows, key=lambda x: x['date'])
for month in months:
the_date = datetime.strptime(month['date'] + "-01", "%Y-%m-%d").date()
requests[0].append(the_date)
requests[1].append(month['requests_per_day'])
bandwidth[0].append(the_date)
bandwidth[1].append(month['bandwidth_per_day'])

# Do the plot
plt.style.use("dark_background")
fig, ax1 = plt.subplots()

ax1.plot(*requests, label="Avg. Daily Requests", color="#D9643A")
ax1.tick_params(axis="y", labelcolor="#D9643A")
ax1.set_yticklabels(["{:,.0f} bil.".format(x / 1000000000) for x in ax1.get_yticks().tolist()])
ax1.legend(loc="upper left", bbox_to_anchor=(0, -0.175), ncol=1, borderpad=0.75, handletextpad=1.5)

ax2 = ax1.twinx()
ax2.plot(*bandwidth, label="Avg. Daily Bandwidth", color="#1EADAE")
ax2.tick_params(axis="y", labelcolor="#1EADAE")
ax2.set_yticklabels(["{:,.1f} PB".format(x / 1000000) for x in ax2.get_yticks().tolist()])
ax2.legend(loc="upper right", bbox_to_anchor=(1, -0.175), ncol=1, borderpad=0.75, handletextpad=1.5)

ax1.set_title("cdnjs Avg. Daily Requests and Bandwidth")
ax1.tick_params(axis="x", labelsize=8, labelrotation=45)
plt.show()
fig.savefig("cdnjs_daily_requests_and_bandwidth.png")


if __name__ == "__main__":
top_5_resources()
requests_and_bandwidth()
total_requests_and_bandwidth()
daily_requests_and_bandwidth()
6 changes: 3 additions & 3 deletions template/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Information provided directly by Cloudflare for the `cdnjs.cloudflare.com` domai
- 2
- 3

| Requests & Bandwidth | Top 5 Resources |
|---|---|
| ![cdnjs requests & bandwidth](../cdnjs_requests_and_bandwidth.png) | ![cdnjs top 5 resources](../cdnjs_top_5_resources.png) |
| Total Requests & Bandwidth | Avg. Daily Requests & Bandwidth | Top 5 Resources |
|---|---|---|
| [![cdnjs total requests & bandwidth graph](../cdnjs_total_requests_and_bandwidth.png)](../cdnjs_total_requests_and_bandwidth.png) | [![cdnjs avg. daily requests & bandwidth graph](../cdnjs_daily_requests_and_bandwidth.png)](../cdnjs_daily_requests_and_bandwidth.png) | [![cdnjs top 5 resources graph](../cdnjs_top_5_resources.png)](../cdnjs_top_5_resources.png) |

## Total number of requests

Expand Down

0 comments on commit 4fbc589

Please sign in to comment.