### Paginate Hosts List Source: https://context7.com/emikulic/darkstat/llms.txt Use the 'start' parameter with the /hosts/ endpoint to control pagination and display hosts starting from a specific index. ```bash curl "http://localhost:667/hosts/?start=20" ``` -------------------------------- ### Start Darkstat with Matching Base Path Source: https://context7.com/emikulic/darkstat/llms.txt Starts darkstat with a specified base path, intended to be used with a reverse proxy configuration like the Nginx example. The base path must match the location block in the proxy configuration. ```bash darkstat -i eth0 --base /network -b 127.0.0.1 ``` -------------------------------- ### Manage Systemd Service for Darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Commands to enable, start, reload, and view logs for the darkstat systemd service. Use 'systemctl enable' to start on boot and 'journalctl' to monitor logs. ```bash # Enable and start service systemctl enable darkstat systemctl start darkstat # Trigger database export systemctl reload darkstat # View logs journalctl -u darkstat -f ``` -------------------------------- ### GET /hosts/ Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve a list of hosts with various sorting and pagination options. ```APIDOC ## GET /hosts/ ### Description Retrieve the list of tracked hosts. Supports sorting by traffic volume or time, and pagination. ### Method GET ### Endpoint /hosts/ ### Parameters #### Query Parameters - **sort** (string) - Optional - Sort criteria: 'out', 'total', or 'lastseen' - **start** (integer) - Optional - Pagination start index - **full** (string) - Optional - Set to 'yes' to retrieve all hosts without pagination ``` -------------------------------- ### Get Stylesheet Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve the CSS stylesheet for the web interface. ```bash curl "http://localhost:667/style.css" ``` -------------------------------- ### GET /metrics Source: https://context7.com/emikulic/darkstat/llms.txt Export host statistics in Prometheus text format. ```APIDOC ## GET /metrics ### Description Export host statistics in Prometheus text format for integration with monitoring systems. ### Method GET ### Endpoint /metrics ``` -------------------------------- ### Basic Interface Capture with darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Start darkstat to capture traffic on a network interface and serve statistics on the default HTTP port 667. Use --verbose and --no-daemon for foreground debugging. ```bash # Basic usage - capture on eth0 interface darkstat -i eth0 ``` ```bash # Capture on multiple interfaces darkstat -i eth0 -i eth1 ``` ```bash # Run in foreground with verbose output (useful for debugging) darkstat -i eth0 --verbose --no-daemon ``` ```bash # Capture traffic and serve web interface on port 8080 darkstat -i eth0 -p 8080 ``` ```bash # Bind web interface to specific IP address darkstat -i eth0 -b 192.168.1.1 -p 80 ``` -------------------------------- ### Get Prometheus Metrics Source: https://context7.com/emikulic/darkstat/llms.txt Export host statistics in Prometheus text format from the /metrics endpoint for monitoring integration. ```bash curl "http://localhost:667/metrics" ``` -------------------------------- ### Get Favicon Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve the favicon for the Darkstat web interface. ```bash curl "http://localhost:667/favicon.ico" ``` -------------------------------- ### Get Graph Data as XML Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve raw graph data in XML format from the /graphs.xml endpoint for custom visualization. ```bash curl "http://localhost:667/graphs.xml" ``` -------------------------------- ### Get Graph Rendering JavaScript Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve the JavaScript file responsible for rendering graphs in the web interface. ```bash curl "http://localhost:667/graph.js" ``` -------------------------------- ### Get Host Details (IPv6) Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve detailed traffic breakdown for a specific IPv6 host using the /hosts/{ip}/ endpoint. ```bash curl "http://localhost:667/hosts/2001:db8::1/" ``` -------------------------------- ### Reverse Proxy Configuration for darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Configure the base URL path for deployment behind a reverse proxy. An example Apache mod_proxy configuration is provided. ```bash # Set base path for reverse proxy darkstat -i eth0 --base /stats ``` ```apache # Apache mod_proxy configuration example: # ProxyPass /stats/ http://localhost:667/stats/ # ProxyPassReverse /stats/ http://localhost:667/stats/ ``` -------------------------------- ### GET /hosts/{ip}/ Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve detailed traffic statistics for a specific host. ```APIDOC ## GET /hosts/{ip}/ ### Description View detailed traffic breakdown for a specific host including per-port and per-protocol statistics. ### Method GET ### Endpoint /hosts/{ip}/ ### Parameters #### Path Parameters - **ip** (string) - Required - The IPv4 or IPv6 address of the host ``` -------------------------------- ### GET /graphs.xml Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve raw graph data in XML format. ```APIDOC ## GET /graphs.xml ### Description Retrieve raw graph data in XML format for custom visualization or monitoring integration. ### Method GET ### Endpoint /graphs.xml ``` -------------------------------- ### Get Host Details (IPv4) Source: https://context7.com/emikulic/darkstat/llms.txt Retrieve detailed traffic breakdown for a specific IPv4 host using the /hosts/{ip}/ endpoint. ```bash curl "http://localhost:667/hosts/192.168.1.100/" ``` -------------------------------- ### BPF Packet Filtering with darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Apply Berkeley Packet Filter expressions to capture only specific traffic types using tcpdump filter syntax. Examples include excluding ARP, monitoring SSH or web traffic, excluding internal traffic, and monitoring a specific host. ```bash # Exclude ARP traffic darkstat -i eth0 -f "not arp" ``` ```bash # Monitor only SSH traffic darkstat -i eth0 -f "port 22" ``` ```bash # Monitor only web traffic (HTTP and HTTPS) darkstat -i eth0 -f "port 80 or port 443" ``` ```bash # Exclude internal-to-internal traffic darkstat -i eth0 -f "not (src net 192.168.0 and dst net 192.168.0)" ``` ```bash # Monitor specific host only darkstat -i eth0 -f "host 10.0.0.50" ``` -------------------------------- ### View All Hosts (No Pagination) Source: https://context7.com/emikulic/darkstat/llms.txt Use the 'full=yes' parameter with the /hosts/ endpoint to retrieve a complete list of all hosts without pagination. ```bash curl "http://localhost:667/hosts/?full=yes" ``` -------------------------------- ### Database Persistence and Signal Handling in darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Export and import statistics databases to preserve data across restarts with chroot directory for security. Demonstrates signal handling for exporting, resetting, and graceful shutdown. ```bash # Setup with database persistence darkstat -i eth0 \ --chroot /var/lib/darkstat \ --export darkstat.db \ --import darkstat.db \ --pidfile darkstat.pid ``` ```bash # Export database without stopping (send SIGUSR2) kill -USR2 $(cat /var/lib/darkstat/darkstat.pid) ``` ```bash # Reset statistics and export (send SIGUSR1) kill -USR1 $(cat /var/lib/darkstat/darkstat.pid) ``` ```bash # Graceful shutdown (exports database automatically) kill $(cat /var/lib/darkstat/darkstat.pid) ``` -------------------------------- ### Enable Day Logging with Darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Enables daily traffic logging with darkstat. The log format includes timestamp, time_t, bytes in/out, and packets in/out. Ensure the specified directory exists and has write permissions. ```bash # Enable day logging darkstat -i eth0 --chroot /var/lib/darkstat --daylog daylog.txt ``` -------------------------------- ### Security Configuration for darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Configure privilege dropping and chroot jail for secure operation. Options include specifying an unprivileged user and setting up a chroot directory. ```bash # Run with custom unprivileged user darkstat -i eth0 --user darkstat --chroot /var/empty ``` ```bash # Full security configuration with all options darkstat -i eth0 \ --chroot /var/lib/darkstat \ --user nobody \ --pidfile darkstat.pid \ --daylog daylog.txt \ --export darkstat.db \ --syslog ``` -------------------------------- ### Export Database using SIGUSR2 Source: https://context7.com/emikulic/darkstat/llms.txt Send a SIGUSR2 signal to export a snapshot of the current database without clearing statistics. ```bash kill -USR2 $(cat /var/lib/darkstat/darkstat.pid) ``` -------------------------------- ### Systemd Service Configuration for Darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Configuration for a systemd service to manage the darkstat daemon. This includes settings for startup, restart behavior, and PID file location. Ensure the user 'darkstat' exists and has necessary permissions. ```ini # /etc/systemd/system/darkstat.service [Unit] Description=darkstat network statistics gatherer After=network-online.target Wants=network-online.target [Service] Type=forking ExecStart=/usr/sbin/darkstat -i eth0 \ --chroot /var/lib/darkstat \ --user darkstat \ --pidfile darkstat.pid \ --export darkstat.db \ --import darkstat.db \ --syslog ExecReload=/bin/kill -USR2 $MAINPID PIDFile=/var/lib/darkstat/darkstat.pid Restart=on-failure [Install] WantedBy=multi-user.target ``` -------------------------------- ### Sort Hosts by Last Seen Time Source: https://context7.com/emikulic/darkstat/llms.txt Use the /hosts/ endpoint with the 'sort=lastseen' parameter to list hosts sorted by their last seen timestamp. ```bash curl "http://localhost:667/hosts/?sort=lastseen" ``` -------------------------------- ### Graceful Shutdown using PID File Source: https://context7.com/emikulic/darkstat/llms.txt Send a SIGTERM signal to the Darkstat process using its PID file for a graceful shutdown. ```bash kill $(cat /var/lib/darkstat/darkstat.pid) ``` -------------------------------- ### Local Network Configuration for darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Define a local network for graphing all traffic entering and leaving the subnet, not just the host running darkstat. Supports PPPoE connections with manual IP specification. ```bash # Monitor entire 192.168.1.0/24 subnet darkstat -i eth0 -l 192.168.1.0/255.255.255.0 ``` ```bash # Monitor with local-only host display (hide external hosts) darkstat -i eth0 -l 192.168.1.0/255.255.255.0 --local-only ``` ```bash # PPPoE connection with manual local IP specification darkstat -i nas0 --pppoe -l 192.168.1.1/255.255.255.255 ``` -------------------------------- ### Access darkstat Front Page (Traffic Graphs) Source: https://context7.com/emikulic/darkstat/llms.txt Access the root endpoint to view traffic graphs showing bandwidth usage over four time periods: 60 seconds, 60 minutes, 24 hours, and 31 days. The response is an HTML page with interactive JavaScript graphs. ```bash # Access the graphs page curl http://localhost:667/ ``` ```text # Response: HTML page with interactive JavaScript graphs # Graphs show bytes in (green) and bytes out (red) # Hover over bars to see exact byte counts ``` -------------------------------- ### Parse Binary Format and Output CSV Source: https://context7.com/emikulic/darkstat/llms.txt This script parses a binary database file and outputs its contents in CSV format. It's useful for exporting darkstat's collected data for further analysis. ```bash od -Ad -v -tx1 -tu1 -ta -w1 < "$DBFILE" | awk ' # ... parsing logic ... END { printf("IP address;MAC address;bytes_in;bytes_out;TCP_ports;UDP_ports\n") # Output host records as CSV } ' > "$CSVFILE" ``` ```bash echo "Exported to $CSVFILE" ``` -------------------------------- ### Export Database to CSV Script Source: https://context7.com/emikulic/darkstat/llms.txt A bash script to convert the binary Darkstat database file (.db) to a CSV format for spreadsheet analysis. ```bash #!/bin/bash # darkstat_export - Convert .db file to .csv DBFILE="$1" CSVFILE="${DBFILE%%.*}.csv" ``` -------------------------------- ### Access darkstat Hosts List Source: https://context7.com/emikulic/darkstat/llms.txt View all tracked hosts with traffic statistics via the /hosts/ endpoint. The list is sortable by various criteria, including total traffic and incoming traffic. ```bash # Get hosts list (default sort by total traffic) curl "http://localhost:667/hosts/" ``` ```bash # Sort by incoming traffic curl "http://localhost:667/hosts/?sort=in" ``` -------------------------------- ### Prometheus Scrape Configuration for Darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Prometheus configuration to scrape metrics from darkstat. It specifies the target address, scrape interval, and metrics path. Relabeling is used to set the 'instance' label to 'gateway'. ```yaml # prometheus.yml scrape_configs: - job_name: 'darkstat' scrape_interval: 30s static_configs: - targets: ['192.168.1.1:667'] metrics_path: '/metrics' relabel_configs: - source_labels: [__address__] target_label: instance replacement: 'gateway' ``` -------------------------------- ### Graceful Shutdown using pgrep Source: https://context7.com/emikulic/darkstat/llms.txt Send a SIGINT signal to the Darkstat process by finding its PID using pgrep, useful if running in the foreground. ```bash kill -INT $(pgrep darkstat) ``` -------------------------------- ### Memory and Resource Limits in darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Control memory usage by limiting tracked hosts and ports. Options include setting maximum hosts, ports per host, highest tracked port, and disabling DNS resolution. ```bash # Limit maximum hosts tracked (default: 1000) darkstat -i eth0 --hosts-max 5000 --hosts-keep 2500 ``` ```bash # Limit ports tracked per host (default: 60 max, 30 keep) darkstat -i eth0 --ports-max 100 --ports-keep 50 ``` ```bash # Hide ephemeral ports (only track ports below 1024) darkstat -i eth0 --highest-port 1024 ``` ```bash # Disable DNS resolution to reduce memory usage darkstat -i eth0 --no-dns ``` -------------------------------- ### Sort Hosts by Outgoing Traffic Source: https://context7.com/emikulic/darkstat/llms.txt Use the /hosts/ endpoint with the 'sort=out' parameter to list hosts sorted by their outgoing traffic. ```bash curl "http://localhost:667/hosts/?sort=out" ``` -------------------------------- ### Reset Statistics using SIGUSR1 Source: https://context7.com/emikulic/darkstat/llms.txt Send a SIGUSR1 signal to export the database (if configured) and then clear all in-memory statistics. ```bash kill -USR1 $(cat /var/lib/darkstat/darkstat.pid) ``` -------------------------------- ### Sort Hosts by Total Traffic Source: https://context7.com/emikulic/darkstat/llms.txt Use the /hosts/ endpoint with the 'sort=total' parameter to list hosts sorted by their total traffic (incoming + outgoing). ```bash curl "http://localhost:667/hosts/?sort=total" ``` -------------------------------- ### Verify Darkstat Metrics Endpoint Source: https://context7.com/emikulic/darkstat/llms.txt Uses curl to fetch and display metrics from the darkstat '/metrics' endpoint. It filters the output to show lines containing 'darkstat', useful for verifying the Prometheus integration. ```bash curl -s http://localhost:667/metrics | grep darkstat ``` -------------------------------- ### Parse Daily Traffic Log with Awk Source: https://context7.com/emikulic/darkstat/llms.txt Parses the daily traffic log generated by darkstat using awk. It calculates and prints the total bytes in and out for each day. The log file must be pipe-delimited. ```awk awk -F'|' '!/^#/ { date=$1; in_bytes+=$3; out_bytes+=$4 printf "%s: IN=%s OUT=%s\n", date, in_bytes, out_bytes }' /var/lib/darkstat/daylog.txt ``` -------------------------------- ### Nginx Reverse Proxy Configuration for Darkstat Source: https://context7.com/emikulic/darkstat/llms.txt Nginx configuration to serve darkstat behind a reverse proxy with SSL and basic authentication. The proxy_pass directive should match the IP and port darkstat is listening on. Ensure the .htpasswd file is correctly set up. ```nginx # /etc/nginx/conf.d/darkstat.conf server { listen 443 ssl; server_name monitor.example.com; location /network/ { auth_basic "Network Statistics"; auth_basic_user_file /etc/nginx/.htpasswd; proxy_pass http://127.0.0.1:667/network/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.