Skip to content

Commit

Permalink
added some more prometheus data
Browse files Browse the repository at this point in the history
  • Loading branch information
realDragonium committed Aug 5, 2021
1 parent decdee3 commit 8f928d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Some notes
### Limited connections when running binary
Because of how linux works the default settings for FD is 1024, this means that you can by default only proxy 1024 connections before it starts refusing connections because it cant open anymore FD's. Because of some internal queues you should consider increasing the limit if you expect to proxy over 900 open connections at the same time.
Because linux the default settings for fd is 1024, this means that you can by default Ultraviolet can have 1024 open connections before it starts refusing connections because it cant open anymore fds. Because of some internal queues you should consider increasing the limit if you expect to proxy over 900 open connections at the same time.

### How to build
Ultraviolet can be ran by using docker or you can also build a binary yourself by running:
Expand All @@ -21,6 +21,7 @@ $ go build
[x] Rate limiting
[x] Status caching (online status only)
[x] Offline status placeholder
[x] Prometheus API
... More coming later?


Expand Down
6 changes: 3 additions & 3 deletions mc/packet_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func (t HandshakeState) String() string {
var text string
switch t {
case UNKNOWN_STATE:
text = "Unknown"
text = "unknown"
case STATUS:
text = "Status"
text = "status"
case LOGIN:
text = "Login"
text = "login"
}
return text
}
Expand Down
10 changes: 5 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func (state BackendAction) String() string {
var text string
switch state {
case PROXY:
text = "Proxy"
text = "proxy"
case DISCONNECT:
text = "Disconnect"
text = "disconnect"
case SEND_STATUS:
text = "Send Status"
text = "send_status"
case CLOSE:
text = "Close"
text = "close"
case ERROR:
text = "Error"
text = "error"
}
return text
}
Expand Down
10 changes: 9 additions & 1 deletion worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"net"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/realDragonium/Ultraviolet/config"
"github.com/realDragonium/Ultraviolet/mc"
)
Expand All @@ -16,6 +18,11 @@ const (
// packetLength:2 + packet ID: 1 + protocol version:2 + max string length:255 + port:2 + state: 1 -> 2+1+2+255+2+1 = 263
)

var (
newConnections = promauto.NewCounterVec(prometheus.CounterOpts{}, []string{"unknown", "login", "status"})
processConnections = promauto.NewCounterVec(prometheus.CounterOpts{}, []string{"proxy", "disconnect", "send_status", "close", "error"})
)

func NewWorker(cfg config.WorkerConfig, reqCh chan net.Conn) BasicWorker {
dict := make(map[string]chan BackendRequest)
defaultStatusPk := cfg.DefaultStatus.Marshal()
Expand Down Expand Up @@ -98,6 +105,7 @@ func (r *BasicWorker) ProcessConnection(conn net.Conn) (BackendRequest, error) {
log.Printf("error while parsing handshake: %v", err)
}
reqType := mc.RequestState(handshake.NextState)
newConnections.WithLabelValues(reqType.String()).Inc()
if reqType == mc.UNKNOWN_STATE {
return BackendRequest{}, ErrNotValidHandshake
}
Expand Down Expand Up @@ -142,6 +150,7 @@ func (w *BasicWorker) ProcessRequest(req BackendRequest) ProcessAnswer {
}

func (w *BasicWorker) ProcessAnswer(conn net.Conn, ans ProcessAnswer) {
processConnections.WithLabelValues(ans.Action().String()).Inc()
clientMcConn := mc.NewMcConn(conn)
switch ans.action {
case PROXY:
Expand All @@ -159,7 +168,6 @@ func (w *BasicWorker) ProcessAnswer(conn net.Conn, ans ProcessAnswer) {
ProxyConnection(client, server)
proxyCh <- PROXY_CLOSE
}(conn, sConn, ans.ProxyCh())

case DISCONNECT:
clientMcConn.WritePacket(ans.Response())
conn.Close()
Expand Down

0 comments on commit 8f928d1

Please sign in to comment.