Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cc2d2376e | ||
|
|
30dc4bf67d |
174
Real-Time Traffic Monitoring Commands.md
Normal file
174
Real-Time Traffic Monitoring Commands.md
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
# Real-Time Traffic Monitoring Commands (Direct Server Use)
|
||||||
|
|
||||||
|
Copy and paste these commands directly on your server.
|
||||||
|
|
||||||
|
## Quick Status Checks
|
||||||
|
|
||||||
|
### See IPs visiting in the last few minutes:
|
||||||
|
```bash
|
||||||
|
sudo tail -500 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
|
||||||
|
```
|
||||||
|
|
||||||
|
### See what status codes they're getting:
|
||||||
|
```bash
|
||||||
|
sudo tail -500 /var/log/nginx/access.log | awk '{print $1, $9}' | grep '216.73.216.38'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Count status codes (200 vs 403):
|
||||||
|
```bash
|
||||||
|
sudo tail -500 /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c
|
||||||
|
```
|
||||||
|
|
||||||
|
## Real-Time Monitoring
|
||||||
|
|
||||||
|
### Watch live traffic (updates every 2 seconds):
|
||||||
|
```bash
|
||||||
|
watch -n 2 'sudo tail -200 /var/log/nginx/access.log | awk "{print \$1}" | sort | uniq -c | sort -rn | head -15'
|
||||||
|
```
|
||||||
|
|
||||||
|
### See live log entries as they happen:
|
||||||
|
```bash
|
||||||
|
sudo tail -f /var/log/nginx/access.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### Live GoAccess dashboard:
|
||||||
|
```bash
|
||||||
|
sudo tail -f /var/log/nginx/access.log | goaccess -
|
||||||
|
```
|
||||||
|
|
||||||
|
## Active Connections
|
||||||
|
|
||||||
|
### See who's connected RIGHT NOW:
|
||||||
|
```bash
|
||||||
|
sudo netstat -tn | grep ':443' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn
|
||||||
|
```
|
||||||
|
|
||||||
|
### Alternative (using ss command):
|
||||||
|
```bash
|
||||||
|
sudo ss -tn | grep ':443' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn
|
||||||
|
```
|
||||||
|
|
||||||
|
## Detailed Analysis
|
||||||
|
|
||||||
|
### Last 100 requests with timestamps:
|
||||||
|
```bash
|
||||||
|
sudo tail -100 /var/log/nginx/access.log | awk '{print $4, $1}' | sed 's/\[//'
|
||||||
|
```
|
||||||
|
|
||||||
|
### See what blocked IPs are trying to access:
|
||||||
|
```bash
|
||||||
|
sudo tail -500 /var/log/nginx/access.log | grep '216.73.216.38' | awk '{print $7}' | head -10
|
||||||
|
```
|
||||||
|
|
||||||
|
### Show all 403 (blocked) requests:
|
||||||
|
```bash
|
||||||
|
sudo tail -500 /var/log/nginx/access.log | awk '$9==403 {print $1}' | sort | uniq -c | sort -rn
|
||||||
|
```
|
||||||
|
|
||||||
|
### Show all successful (200) requests:
|
||||||
|
```bash
|
||||||
|
sudo tail -500 /var/log/nginx/access.log | awk '$9==200 {print $1}' | sort | uniq -c | sort -rn | head -10
|
||||||
|
```
|
||||||
|
|
||||||
|
## Comprehensive Monitoring Script
|
||||||
|
|
||||||
|
### Create a monitoring script:
|
||||||
|
```bash
|
||||||
|
cat > /tmp/monitor-traffic.sh << 'EOF'
|
||||||
|
#!/bin/bash
|
||||||
|
echo "=== Traffic in last 5 minutes ==="
|
||||||
|
echo "Time: $(date)"
|
||||||
|
echo ""
|
||||||
|
echo "Top IPs:"
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10
|
||||||
|
echo ""
|
||||||
|
echo "Blocked IPs (403 errors):"
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk '$9==403 {print $1}' | sort | uniq -c | sort -rn
|
||||||
|
echo ""
|
||||||
|
echo "Successful requests (200):"
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk '$9==200 {print $1}' | sort | uniq -c | sort -rn | head -5
|
||||||
|
echo ""
|
||||||
|
echo "Status Code Summary:"
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c | sort -rn
|
||||||
|
EOF
|
||||||
|
chmod +x /tmp/monitor-traffic.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Run the monitoring script:
|
||||||
|
```bash
|
||||||
|
/tmp/monitor-traffic.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Auto-Refreshing Dashboard
|
||||||
|
|
||||||
|
### Live dashboard (refreshes every 5 seconds):
|
||||||
|
```bash
|
||||||
|
watch -n 5 'echo "=== Last 5 minutes ==="
|
||||||
|
date
|
||||||
|
echo ""
|
||||||
|
echo "Top IPs:"
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk "{print \$1}" | sort | uniq -c | sort -rn | head -10
|
||||||
|
echo ""
|
||||||
|
echo "Status Codes:"
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk "{print \$9}" | sort | uniq -c | sort -rn'
|
||||||
|
```
|
||||||
|
|
||||||
|
Press `Ctrl+C` to exit.
|
||||||
|
|
||||||
|
## GoAccess HTML Report (Live Updating)
|
||||||
|
|
||||||
|
### Generate live HTML report:
|
||||||
|
```bash
|
||||||
|
sudo goaccess /var/log/nginx/access.log -o /var/www/html/live-stats.html --real-time-html --daemonize
|
||||||
|
```
|
||||||
|
|
||||||
|
Then visit: https://git.laantungir.net/live-stats.html
|
||||||
|
|
||||||
|
### Stop the live report:
|
||||||
|
```bash
|
||||||
|
sudo pkill -f "goaccess.*live-stats"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Filter by Time
|
||||||
|
|
||||||
|
### Get timestamp from 5 minutes ago:
|
||||||
|
```bash
|
||||||
|
date -d '5 minutes ago' '+%d/%b/%Y:%H:%M'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Analyze only recent logs (replace timestamp):
|
||||||
|
```bash
|
||||||
|
sudo awk '/01\/Feb\/2026:19:09/,0' /var/log/nginx/access.log | goaccess -
|
||||||
|
```
|
||||||
|
|
||||||
|
## Check Gitea CPU
|
||||||
|
|
||||||
|
### Current CPU usage:
|
||||||
|
```bash
|
||||||
|
ps aux | grep gitea | grep -v grep
|
||||||
|
```
|
||||||
|
|
||||||
|
### Watch CPU in real-time:
|
||||||
|
```bash
|
||||||
|
watch -n 2 'ps aux | grep gitea | grep -v grep'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Most Useful Command for Quick Check
|
||||||
|
|
||||||
|
This one-liner shows everything you need:
|
||||||
|
```bash
|
||||||
|
|
||||||
|
echo "=== Quick Status ===" && \
|
||||||
|
echo "Time: $(date)" && \
|
||||||
|
echo "" && \
|
||||||
|
echo "Top 10 IPs (last 1000 requests):" && \
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10 && \
|
||||||
|
echo "" && \
|
||||||
|
echo "Status Codes:" && \
|
||||||
|
sudo tail -1000 /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c && \
|
||||||
|
echo "" && \
|
||||||
|
echo "Gitea CPU:" && \
|
||||||
|
ps aux | grep gitea | grep -v grep
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy any of these commands and run them directly on your server!
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
// Using CRELAY_ prefix to avoid conflicts with nostr_core_lib VERSION macros
|
// Using CRELAY_ prefix to avoid conflicts with nostr_core_lib VERSION macros
|
||||||
#define CRELAY_VERSION_MAJOR 1
|
#define CRELAY_VERSION_MAJOR 1
|
||||||
#define CRELAY_VERSION_MINOR 1
|
#define CRELAY_VERSION_MINOR 1
|
||||||
#define CRELAY_VERSION_PATCH 4
|
#define CRELAY_VERSION_PATCH 6
|
||||||
#define CRELAY_VERSION "v1.1.4"
|
#define CRELAY_VERSION "v1.1.6"
|
||||||
|
|
||||||
// Relay metadata (authoritative source for NIP-11 information)
|
// Relay metadata (authoritative source for NIP-11 information)
|
||||||
#define RELAY_NAME "C-Relay"
|
#define RELAY_NAME "C-Relay"
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ void add_subscription_to_kind_index(subscription_t* sub) {
|
|||||||
|
|
||||||
int has_kind_filter = 0;
|
int has_kind_filter = 0;
|
||||||
|
|
||||||
|
// Track which kinds we've already added to avoid duplicates
|
||||||
|
// Use a bitmap for memory efficiency: 65536 bits = 8192 bytes
|
||||||
|
unsigned char added_kinds[8192] = {0}; // 65536 / 8 = 8192 bytes
|
||||||
|
|
||||||
// Iterate through all filters in this subscription
|
// Iterate through all filters in this subscription
|
||||||
subscription_filter_t* filter = sub->filters;
|
subscription_filter_t* filter = sub->filters;
|
||||||
while (filter) {
|
while (filter) {
|
||||||
@@ -82,6 +86,17 @@ void add_subscription_to_kind_index(subscription_t* sub) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if we've already added this kind (deduplication)
|
||||||
|
int byte_index = kind / 8;
|
||||||
|
int bit_index = kind % 8;
|
||||||
|
if (added_kinds[byte_index] & (1 << bit_index)) {
|
||||||
|
DEBUG_TRACE("KIND_INDEX: Skipping duplicate kind %d for subscription '%s'", kind, sub->id);
|
||||||
|
continue; // Already added this kind
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark this kind as added
|
||||||
|
added_kinds[byte_index] |= (1 << bit_index);
|
||||||
|
|
||||||
// Create new index node
|
// Create new index node
|
||||||
kind_subscription_node_t* node = malloc(sizeof(kind_subscription_node_t));
|
kind_subscription_node_t* node = malloc(sizeof(kind_subscription_node_t));
|
||||||
if (!node) {
|
if (!node) {
|
||||||
@@ -100,10 +115,17 @@ void add_subscription_to_kind_index(subscription_t* sub) {
|
|||||||
filter = filter->next;
|
filter = filter->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If subscription has no kind filter, add to no-kind-filter list
|
// If subscription has no kind filter, add to no-kind-filter list using wrapper node
|
||||||
if (!has_kind_filter) {
|
if (!has_kind_filter) {
|
||||||
sub->next = g_subscription_manager.no_kind_filter_subs;
|
no_kind_filter_node_t* node = malloc(sizeof(no_kind_filter_node_t));
|
||||||
g_subscription_manager.no_kind_filter_subs = sub;
|
if (!node) {
|
||||||
|
DEBUG_ERROR("add_subscription_to_kind_index: failed to allocate no-kind-filter node");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
node->subscription = sub;
|
||||||
|
node->next = g_subscription_manager.no_kind_filter_subs;
|
||||||
|
g_subscription_manager.no_kind_filter_subs = node;
|
||||||
DEBUG_TRACE("KIND_INDEX: Added subscription '%s' to no-kind-filter list", sub->id);
|
DEBUG_TRACE("KIND_INDEX: Added subscription '%s' to no-kind-filter list", sub->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,11 +152,13 @@ void remove_subscription_from_kind_index(subscription_t* sub) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove from no-kind-filter list
|
// Remove from no-kind-filter list if present
|
||||||
subscription_t** current = &g_subscription_manager.no_kind_filter_subs;
|
no_kind_filter_node_t** current = &g_subscription_manager.no_kind_filter_subs;
|
||||||
while (*current) {
|
while (*current) {
|
||||||
if (*current == sub) {
|
if ((*current)->subscription == sub) {
|
||||||
|
no_kind_filter_node_t* to_free = *current;
|
||||||
*current = (*current)->next;
|
*current = (*current)->next;
|
||||||
|
free(to_free);
|
||||||
DEBUG_TRACE("KIND_INDEX: Removed subscription '%s' from no-kind-filter list", sub->id);
|
DEBUG_TRACE("KIND_INDEX: Removed subscription '%s' from no-kind-filter list", sub->id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -797,12 +821,12 @@ int broadcast_event_to_subscriptions(cJSON* event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add subscriptions with no kind filter (must check against all events)
|
// Add subscriptions with no kind filter (must check against all events)
|
||||||
subscription_t* no_kind_sub = g_subscription_manager.no_kind_filter_subs;
|
no_kind_filter_node_t* no_kind_node = g_subscription_manager.no_kind_filter_subs;
|
||||||
while (no_kind_sub && candidate_count < MAX_TOTAL_SUBSCRIPTIONS) {
|
while (no_kind_node && candidate_count < MAX_TOTAL_SUBSCRIPTIONS) {
|
||||||
if (no_kind_sub->active) {
|
if (no_kind_node->subscription && no_kind_node->subscription->active) {
|
||||||
candidates_to_check[candidate_count++] = no_kind_sub;
|
candidates_to_check[candidate_count++] = no_kind_node->subscription;
|
||||||
}
|
}
|
||||||
no_kind_sub = no_kind_sub->next;
|
no_kind_node = no_kind_node->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_TRACE("BROADCAST: Checking %d candidate subscriptions (kind index optimization)", candidate_count);
|
DEBUG_TRACE("BROADCAST: Checking %d candidate subscriptions (kind index optimization)", candidate_count);
|
||||||
|
|||||||
@@ -69,6 +69,12 @@ typedef struct kind_subscription_node {
|
|||||||
struct kind_subscription_node* next; // Next subscription for this kind
|
struct kind_subscription_node* next; // Next subscription for this kind
|
||||||
} kind_subscription_node_t;
|
} kind_subscription_node_t;
|
||||||
|
|
||||||
|
// No-kind-filter list entry - wrapper to avoid corrupting subscription->next pointer
|
||||||
|
typedef struct no_kind_filter_node {
|
||||||
|
subscription_t* subscription; // Pointer to subscription
|
||||||
|
struct no_kind_filter_node* next; // Next subscription in no-kind list
|
||||||
|
} no_kind_filter_node_t;
|
||||||
|
|
||||||
// Per-IP connection tracking
|
// Per-IP connection tracking
|
||||||
typedef struct ip_connection_info {
|
typedef struct ip_connection_info {
|
||||||
char ip_address[CLIENT_IP_MAX_LENGTH]; // IP address
|
char ip_address[CLIENT_IP_MAX_LENGTH]; // IP address
|
||||||
@@ -87,7 +93,7 @@ struct subscription_manager {
|
|||||||
|
|
||||||
// Kind-based index for fast subscription lookup (10x performance improvement)
|
// Kind-based index for fast subscription lookup (10x performance improvement)
|
||||||
kind_subscription_node_t* kind_index[65536]; // Array of subscription lists, one per kind
|
kind_subscription_node_t* kind_index[65536]; // Array of subscription lists, one per kind
|
||||||
subscription_t* no_kind_filter_subs; // Subscriptions with no kind filter (must check all events)
|
no_kind_filter_node_t* no_kind_filter_subs; // Subscriptions with no kind filter (wrapper nodes)
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
int max_subscriptions_per_client; // Default: 20
|
int max_subscriptions_per_client; // Default: 20
|
||||||
|
|||||||
Reference in New Issue
Block a user