-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93287b6
commit 0f1f1ea
Showing
14 changed files
with
282 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package monitoring | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// Define the Prometheus metrics for TCP and UDP connections | ||
var ( | ||
TCPConnections = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "tcp_connections_total", | ||
Help: "Total number of TCP connections.", | ||
}, | ||
[]string{"src_addr", "dst_addr", "src_port", "dst_port", "comm"}, | ||
) | ||
|
||
UDPConnections = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "udp_connections_total", | ||
Help: "Total number of UDP connections.", | ||
}, | ||
[]string{"src_addr", "dst_addr", "src_port", "dst_port", "comm"}, | ||
) | ||
) | ||
|
||
// InitPrometheus registers the Prometheus metrics | ||
func InitPrometheus() { | ||
prometheus.MustRegister(TCPConnections) | ||
prometheus.MustRegister(UDPConnections) | ||
} | ||
|
||
// TrackTCPEvent updates the Prometheus metrics for a TCP event | ||
func TrackTCPEvent(srcAddr, dstAddr, srcPort, dstPort, comm string) { | ||
TCPConnections.With(prometheus.Labels{ | ||
"src_addr": srcAddr, | ||
"dst_addr": dstAddr, | ||
"src_port": srcPort, | ||
"dst_port": dstPort, | ||
"comm": comm, | ||
}).Inc() | ||
} | ||
|
||
// TrackUDPEvent updates the Prometheus metrics for a UDP event | ||
func TrackUDPEvent(srcAddr, dstAddr, srcPort, dstPort, comm string) { | ||
UDPConnections.With(prometheus.Labels{ | ||
"src_addr": srcAddr, | ||
"dst_addr": dstAddr, | ||
"src_port": srcPort, | ||
"dst_port": dstPort, | ||
"comm": comm, | ||
}).Inc() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.