Compare commits
8 Commits
2024.0119.
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d726b4673d | ||
|
|
7341b404af | ||
|
|
890b9210c0 | ||
|
|
50233633a5 | ||
|
|
c309a8fc58 | ||
|
|
0cc52eee46 | ||
|
|
8131751045 | ||
|
|
56076bc107 |
2
.github/workflows/docker-hub-description.yml
vendored
2
.github/workflows/docker-hub-description.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
- name: Update Docker Hub description
|
||||
uses: peter-evans/dockerhub-description@v3
|
||||
uses: peter-evans/dockerhub-description@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
||||
|
||||
34
.github/workflows/on-push.yml
vendored
34
.github/workflows/on-push.yml
vendored
@@ -41,11 +41,11 @@ jobs:
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
${{ github.repository }}
|
||||
ghcr.io/${{ github.repository }}
|
||||
${{ github.repository }}-development
|
||||
ghcr.io/${{ github.repository }}-development
|
||||
tags: |
|
||||
type=raw,value=dev-{{date 'X'}}
|
||||
type=raw,value=development
|
||||
type=raw,value=latest
|
||||
type=ref,event=branch
|
||||
type=edge,branch=main
|
||||
- name: Build and push ${{ github.repository }}:${{ steps.git.outputs.image_tag }}
|
||||
@@ -57,32 +57,4 @@ jobs:
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
provenance: false
|
||||
|
||||
clean-ghcr:
|
||||
name: Delete old dev container images
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Delete old dev images
|
||||
uses: snok/container-retention-policy@v2
|
||||
with:
|
||||
image-names: endlessh-go
|
||||
cut-off: One week ago UTC
|
||||
account-type: personal
|
||||
token: ${{ secrets.TOKEN_DELETE_GHCR_IMAGES }}
|
||||
keep-at-least: 5
|
||||
skip-tags: latest, development
|
||||
filter-tags: "dev-*"
|
||||
dry-run: False
|
||||
# # Untagged images could be the images for different OS/Arch. Do not delete them.
|
||||
# - name: Delete untagged images
|
||||
# uses: snok/container-retention-policy@v2
|
||||
# with:
|
||||
# image-names: endlessh-go
|
||||
# cut-off: One hour ago UTC
|
||||
# account-type: personal
|
||||
# token: ${{ secrets.TOKEN_DELETE_GHCR_IMAGES }}
|
||||
# keep-at-least: 0
|
||||
# untagged-only: True
|
||||
# skip-tags: latest, development
|
||||
# dry-run: False
|
||||
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ go build .
|
||||
Alternatively, you can use the [docker image](https://hub.docker.com/r/shizunge/endlessh-go):
|
||||
|
||||
```
|
||||
sudo docker run -d -p 2222:2222 shizunge/endlessh-go -logtostderr -v=1
|
||||
docker run -d -p 2222:2222 shizunge/endlessh-go -logtostderr -v=1
|
||||
```
|
||||
|
||||
It listens to port `2222` by default.
|
||||
|
||||
@@ -5,12 +5,12 @@ This is an example how to setup endlessh-go with the Maxmind GeoIP Database usin
|
||||
To start the stack, in the _examples_ folder, run:
|
||||
|
||||
```
|
||||
sudo docker-compose up -d
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
The GeoIP Database will be saved in a mounted volume in: `./geo-data`. And the endlessh-go container will use this database to do the location lookups.
|
||||
|
||||
This example exposes the following ports. Except the SSH port, you should not expose other ports to public without protections (not included in this example) in production.
|
||||
|
||||
- **2222**: The SSH port. You may test endlessh-go by running `ssh -p 2222 localhost`. Your SSH client should hang. View the log of endlessh-go by running `sudo docker logs endlessh`.
|
||||
- **2222**: The SSH port. You may test endlessh-go by running `ssh -p 2222 localhost`. Your SSH client should hang. View the log of endlessh-go by running `docker logs endlessh`.
|
||||
- **2112**: The Prometheus metrics exported by endlessh-go. Go to [http://localhost:2112/metrics](http://localhost:2112/metrics) in your web browser to view the metrics.
|
||||
|
||||
@@ -9,12 +9,12 @@ This is an example how to setup endlessh-go, Prometheus, and Grafana using [dock
|
||||
To start the stack, in the *examples* folder, run:
|
||||
|
||||
```
|
||||
sudo docker-compose up -d
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
This example exposes the following ports. Except the SSH port, you should not expose other ports to public without protections (not included in this example) in production.
|
||||
|
||||
* **2222**: The SSH port. You may test endlessh-go by running `ssh -p 2222 localhost`. Your SSH client should hang. View the log of endlessh-go by running `sudo docker logs endlessh`.
|
||||
* **2222**: The SSH port. You may test endlessh-go by running `ssh -p 2222 localhost`. Your SSH client should hang. View the log of endlessh-go by running `docker logs endlessh`.
|
||||
* **2112**: The Prometheus metrics exported by endlessh-go. Go to [http://localhost:2112/metrics](http://localhost:2112/metrics) in your web browser to view the metrics.
|
||||
* **9090**: Prometheus web interface. Go to [http://localhost:9090](http://localhost:9090) in your web browser for Prometheus. You can check whether the target of endlessh-go is up (Click Status, then Targets).
|
||||
* **3000**: Grafana. Go to [http://localhost:3000](http://localhost:3000) in your web browser for Grafana. Use username *examples* and password *examples* to login.
|
||||
|
||||
2
go.mod
2
go.mod
@@ -20,5 +20,5 @@ require (
|
||||
github.com/prometheus/common v0.45.0 // indirect
|
||||
github.com/prometheus/procfs v0.12.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
google.golang.org/protobuf v1.33.0 // indirect
|
||||
)
|
||||
|
||||
8
go.sum
8
go.sum
@@ -14,8 +14,6 @@ github.com/fanixk/geohash v0.0.0-20150324002647-c1f9b5fa157a h1:Fyfh/dsHFrC6nkX7
|
||||
github.com/fanixk/geohash v0.0.0-20150324002647-c1f9b5fa157a/go.mod h1:UgNw+PTmmGN8rV7RvjvnBMsoTU8ZXXnaT3hYsDTBlgQ=
|
||||
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
|
||||
github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
|
||||
@@ -52,9 +50,7 @@ github.com/the42/cartconvert v1.0.0 h1:g8kt6ic2GEhdcZ61ZP9GsWwhosVo5nCnH1n2/oAQX
|
||||
github.com/the42/cartconvert v1.0.0/go.mod h1:fWO/msnJVhHqN1yX6OBoxSyfj7TEj1hHiL8bJSQsK30=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
|
||||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
11
main.go
11
main.go
@@ -42,23 +42,24 @@ func startSending(maxClients int64, bannerMaxLength int64, records chan<- metric
|
||||
bytesSent, err := c.Send(bannerMaxLength)
|
||||
remoteIpAddr := c.RemoteIpAddr()
|
||||
localPort := c.LocalPort()
|
||||
millisecondsSpent := c.MillisecondsSinceLast()
|
||||
if err != nil {
|
||||
c.Close()
|
||||
records <- metrics.RecordEntry{
|
||||
RecordType: metrics.RecordEntryTypeStop,
|
||||
IpAddr: remoteIpAddr,
|
||||
LocalPort: localPort,
|
||||
RecordType: metrics.RecordEntryTypeStop,
|
||||
IpAddr: remoteIpAddr,
|
||||
LocalPort: localPort,
|
||||
MillisecondsSpent: millisecondsSpent,
|
||||
}
|
||||
return
|
||||
}
|
||||
millisecondsSpent := c.MillisecondsSinceLast()
|
||||
clients <- c
|
||||
records <- metrics.RecordEntry{
|
||||
RecordType: metrics.RecordEntryTypeSend,
|
||||
IpAddr: remoteIpAddr,
|
||||
LocalPort: localPort,
|
||||
BytesSent: bytesSent,
|
||||
MillisecondsSpent: millisecondsSpent,
|
||||
BytesSent: bytesSent,
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -106,8 +106,8 @@ type RecordEntry struct {
|
||||
RecordType int
|
||||
IpAddr string
|
||||
LocalPort string
|
||||
BytesSent int
|
||||
MillisecondsSpent int64
|
||||
BytesSent int
|
||||
}
|
||||
|
||||
func StartRecording(maxClients int64, prometheusEnabled bool, prometheusCleanUnseenSeconds int, geoOption geoip.GeoOption) chan RecordEntry {
|
||||
@@ -140,10 +140,15 @@ func StartRecording(maxClients int64, prometheusEnabled bool, prometheusCleanUns
|
||||
clientSeconds.With(prometheus.Labels{
|
||||
"ip": r.IpAddr,
|
||||
"local_port": r.LocalPort}).Add(secondsSpent)
|
||||
totalBytes.With(prometheus.Labels{"local_port": r.LocalPort}).Add(float64(r.BytesSent))
|
||||
totalSeconds.With(prometheus.Labels{"local_port": r.LocalPort}).Add(secondsSpent)
|
||||
totalBytes.With(prometheus.Labels{"local_port": r.LocalPort}).Add(float64(r.BytesSent))
|
||||
pq.Update(r.IpAddr, time.Now())
|
||||
case RecordEntryTypeStop:
|
||||
secondsSpent := float64(r.MillisecondsSpent) / 1000
|
||||
clientSeconds.With(prometheus.Labels{
|
||||
"ip": r.IpAddr,
|
||||
"local_port": r.LocalPort}).Add(secondsSpent)
|
||||
totalSeconds.With(prometheus.Labels{"local_port": r.LocalPort}).Add(secondsSpent)
|
||||
totalClientsClosed.With(prometheus.Labels{"local_port": r.LocalPort}).Inc()
|
||||
pq.Update(r.IpAddr, time.Now())
|
||||
case RecordEntryTypeClean:
|
||||
|
||||
Reference in New Issue
Block a user