Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
django-statistics-dashboard
Advanced tools
A dashboard to display captured metrics and charts, such as devices, pages visited, and page actions. Staff user is required to get chart data and view dashboard. Dashboard is at /(statsurl), usually /stats.
Add 'stats_dashboard'
to INSTALLED_APPS in settings.py.
INSTALLED_APPS = [
...,
"stats_dashboard",
]
Add 'stats_dashboard.middleware.stat_middleware.StatMiddleware'
to MIDDLEWARE in settings.py.
MIDDLEWARE = [
...,
"stats_dashboard.middleware.stat_middleware.StatMiddleware"
]
Optional: Configurate the elements to listen for clicks in settings.py.
STATS_PAGE_CONFIG = {
"*": {
"click": [
{"selector": "button", "name": "this is name"}
],
}
}
"*" is a regex expression for the page to listen for this click. There can be multiple pages.
"click" specifies the event. Currently only click events are available.
"selector" is the CSS selector for the element to listen to clicks on
"name" is the name that the event is saved as
Optional: To use custom charts, create a python file, (commonly chart.py) and set it in settings.py.
STATS_CHART_LOCATION = "yourproject.chart"
This file specifies all of the charts to show on the dashboard. More documentation here.
On pages that you wish to be tracked, add the JavaScript file. Note that axios, a JS library is loaded to send requests to the server on activity (from this script). You can put this in your base template.
{% load static %}
<body>
<script src="{% static 'stats/stats.js' %}"></script>
</body>
Add the urls in urls.py
import stats_dashboard.urls
urlpatterns = [
path("stats/", include(stats_dashboard.urls)),
]
It is recommended to use stats/ as the url as by default,
recorded activity is sent here from the JavaScript file.
If you wish to use another url, specify the data-root attribute on the
script tag e.g.
<script data-root="/otherurl/" src="{% static 'stats/stats.js' %}"></script>
The charts classes and functions are at stats_dashboard.charts
.
Go to /yourstaturl/charts/ to get charts data for troubleshooting.
The flow for creating charts is:
Import the chart manager, at
from stats_dashboard.charts.manager import statistic_charts
Import your chart type
from stats_dashboard.charts.types import LineChart, ScatterChart, BarChart, PieChart
Import the chart dataset class and
from stats_dashboard.charts.dataset import ChartDataset
Optional: Import dataset style class (to add custom styles on datasets)
from stats_dashboard.charts.dataset_styles import DatasetStyle
Create your dataset styles:
my_blue_style = DatasetStyle(background_color="blue")
Styles are based off of chart.js styles, however JavaScript names are changed to Python
names e.g. backgroundColor -> background_color
.
Styles
are here. Some chart specific styles may be found on the documentation for other charts.
Create your datasets:
my_dataset = ChartDataset(values=[10, 20, 30], style=my_blue_style)
my_second_dataset = ChartDataset(values=[20, 30, 35])
Default style is used if not otherwise specified.
Values should be calculated from your own data.
This file is run on each request to the chart dashboard, do that the data can be retrieved
from models.
For scatter graphs, data should be set in this format, with ScatterDataset:
ScatterDataset(values=[
{"x": 1, "y": 3},
{"x": 2, "y": 4},
{"x": 3, "y": 5}
],
style=scatter_style
)
Create your chart object from the datasets.
my_bar_chart = BarChart(
name="My Bar Chart",
labels=["1st Bar", "2nd Bar", "3rd Bar"],
datasets=[
my_dataset,
my_second_dataset
]
)
There should be as many labels as values in each dataset.
Labels: X Axis
Dataset Values: Y Axis
(Except in Pie Charts, and Scatter Charts)
In Scatter Charts, the dataset values contain X and Y values, so the labels
argument shouldn't be set.
Add the chart to your dashboard
statistic_charts.add_chart(my_bar_chart)
There are some pre-made charts at from stats_dashboard.charts.preset import *
They all take an optional style object.
Some examples are visits_time
, displaying visitors to the site, over time.
This takes the number of seconds to look back for visitors, and a scale e.g. month.
Another is common_pages
, abar chart showing most visited pages.
statistic_charts.add_chart(visits_time(58400, "hour", style=my_style))
statistic_charts.add_chart(browser_share(type="pie"))
3 Models, BroswerSession, PageSession and PageEvent is available at stats_dashboard.models. These can be used to retrieve tracked user activity.
STAT_TRACK_IN_DEBUG = False
will disable tracking activity with debug on.
Please report any issues!
FAQs
A stats dashboard and session tracker for Django.
We found that django-statistics-dashboard demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.