Add option to disable statistic collection per endpoint

This commit is contained in:
Toby Chui
2025-11-05 21:38:50 +08:00
parent c1acbe7f9d
commit fc6cfd102e
4 changed files with 35 additions and 3 deletions

View File

@@ -361,7 +361,7 @@ func (router *Router) logRequest(r *http.Request, succ bool, statusCode int, for
// in that case we will log it by default and will not enter this routine // in that case we will log it by default and will not enter this routine
return return
} }
if router.Option.StatisticCollector != nil { if router.Option.StatisticCollector != nil && !endpoint.DisableStatisticCollection {
go func() { go func() {
requestInfo := statistic.RequestInfo{ requestInfo := statistic.RequestInfo{
IpAddr: netutils.GetRequesterIP(r), IpAddr: netutils.GetRequesterIP(r),
@@ -377,6 +377,7 @@ func (router *Router) logRequest(r *http.Request, succ bool, statusCode int, for
} }
router.Option.StatisticCollector.RecordRequest(requestInfo) router.Option.StatisticCollector.RecordRequest(requestInfo)
}() }()
} }
router.Option.Logger.LogHTTPRequest(r, forwardType, statusCode, originalHostname, upstreamHostname) router.Option.Logger.LogHTTPRequest(r, forwardType, statusCode, originalHostname, upstreamHostname)
} }

View File

@@ -207,8 +207,9 @@ type ProxyEndpoint struct {
RateLimit int64 // Rate limit in requests per second RateLimit int64 // Rate limit in requests per second
//Uptime Monitor //Uptime Monitor
DisableUptimeMonitor bool //Disable uptime monitor for this endpoint DisableUptimeMonitor bool //Disable uptime monitor for this endpoint
DisableLogging bool //Disable logging of reverse proxy requests DisableLogging bool //Disable logging of reverse proxy requests
DisableStatisticCollection bool //Disable statistic collection for this endpoint
// Chunked Transfer Encoding // Chunked Transfer Encoding
DisableChunkedTransferEncoding bool //Disable chunked transfer encoding for this endpoint DisableChunkedTransferEncoding bool //Disable chunked transfer encoding for this endpoint

View File

@@ -577,6 +577,9 @@ func ReverseProxyHandleEditEndpoint(w http.ResponseWriter, r *http.Request) {
// Disable logging // Disable logging
disableLogging, _ := utils.PostBool(r, "dLogging") disableLogging, _ := utils.PostBool(r, "dLogging")
// Disable statistic collection
disableStatisticCollection, _ := utils.PostBool(r, "dStatisticCollection")
//Load the previous basic auth credentials from current proxy rules //Load the previous basic auth credentials from current proxy rules
targetProxyEntry, err := dynamicProxyRouter.LoadProxy(rootNameOrMatchingDomain) targetProxyEntry, err := dynamicProxyRouter.LoadProxy(rootNameOrMatchingDomain)
if err != nil { if err != nil {
@@ -619,6 +622,7 @@ func ReverseProxyHandleEditEndpoint(w http.ResponseWriter, r *http.Request) {
newProxyEndpoint.DisableUptimeMonitor = disbleUtm newProxyEndpoint.DisableUptimeMonitor = disbleUtm
newProxyEndpoint.DisableChunkedTransferEncoding = disableChunkedEncoding newProxyEndpoint.DisableChunkedTransferEncoding = disableChunkedEncoding
newProxyEndpoint.DisableLogging = disableLogging newProxyEndpoint.DisableLogging = disableLogging
newProxyEndpoint.DisableStatisticCollection = disableStatisticCollection
newProxyEndpoint.Tags = tags newProxyEndpoint.Tags = tags
//Prepare to replace the current routing rule //Prepare to replace the current routing rule

View File

@@ -290,6 +290,13 @@
<label>Disable Requests Logging<br> <label>Disable Requests Logging<br>
<small>Disable logging for all incoming requests for this hostname</small></label> <small>Disable logging for all incoming requests for this hostname</small></label>
</div> </div>
<br>
<div class="ui checkbox" style="margin-top: 0.4em;">
<input type="checkbox" class="DisableStatisticCollection">
<label>Disable Statistic Collection<br>
<small>Disable collecting statistics for this hostname but keep request logging</small></label>
</div>
<br>
</div> </div>
</div> </div>
@@ -892,6 +899,7 @@
let bypassGlobalTLS = $(editor).find(".BypassGlobalTLS")[0].checked; let bypassGlobalTLS = $(editor).find(".BypassGlobalTLS")[0].checked;
let disableChunkedTransferEncoding = $(editor).find(".DisableChunkedTransferEncoding")[0].checked; let disableChunkedTransferEncoding = $(editor).find(".DisableChunkedTransferEncoding")[0].checked;
let disableLogging = $(editor).find(".DisableLogging")[0].checked; let disableLogging = $(editor).find(".DisableLogging")[0].checked;
let disableStatisticCollection = $(editor).find(".DisableStatisticCollection")[0].checked;
let tags = getTagsArrayFromEndpoint(uuid); let tags = getTagsArrayFromEndpoint(uuid);
if (tags.length > 0){ if (tags.length > 0){
tags = tags.join(","); tags = tags.join(",");
@@ -909,6 +917,7 @@
"rate" :requireRateLimit, "rate" :requireRateLimit,
"dChunkedEnc": disableChunkedTransferEncoding, "dChunkedEnc": disableChunkedTransferEncoding,
"dLogging": disableLogging, "dLogging": disableLogging,
"dStatisticCollection": disableStatisticCollection,
"ratenum" :rateLimit, "ratenum" :rateLimit,
"tags": tags, "tags": tags,
}; };
@@ -1250,8 +1259,25 @@
editor.find(".DisableLogging").off('change'); editor.find(".DisableLogging").off('change');
editor.find(".DisableLogging").prop("checked", subd.DisableLogging); editor.find(".DisableLogging").prop("checked", subd.DisableLogging);
editor.find(".DisableLogging").on("change", function() { editor.find(".DisableLogging").on("change", function() {
// When logging is disabled, also disable statistic collection
if ($(this).is(':checked')) {
editor.find(".DisableStatisticCollection").prop("checked", true).prop("disabled", true);
} else {
editor.find(".DisableStatisticCollection").prop("disabled", false);
}
saveProxyInlineEdit(uuid); saveProxyInlineEdit(uuid);
}); });
editor.find(".DisableStatisticCollection").off('change');
editor.find(".DisableStatisticCollection").prop("checked", subd.DisableStatisticCollection);
editor.find(".DisableStatisticCollection").on("change", function() {
saveProxyInlineEdit(uuid);
});
// Handle initial state: if logging is disabled, disable statistic collection
if (subd.DisableLogging) {
editor.find(".DisableStatisticCollection").prop("checked", true).prop("disabled", true);
}
//Bind the edit button //Bind the edit button
editor.find(".downstream_primary_hostname_edit_btn").off("click").on("click", function(){ editor.find(".downstream_primary_hostname_edit_btn").off("click").on("click", function(){