Added Load to /status, change Dockerfile build
This commit is contained in:
parent
4cee28b8bb
commit
5b80960420
|
@ -55,10 +55,13 @@ RUN go mod download -x && go mod verify
|
|||
|
||||
COPY . .
|
||||
|
||||
RUN go build -v -ldflags '-linkmode external -extldflags "-Wl,-z,stack-size=2097152 -fno-PIC -static -lstdc++"' -buildmode pie -tags 'osusergo netgo static_build' -o /usr/bin/ignite-encode-libaom git.gammaspectra.live/S.O.N.G/Ignite/cli/encode-libaom
|
||||
RUN go build -v -ldflags '-linkmode external -extldflags "-Wl,-z,stack-size=2097152 -fno-PIC -static -lstdc++"' -buildmode pie -tags 'osusergo netgo static_build' \
|
||||
-o /usr/bin/ git.gammaspectra.live/S.O.N.G/Ignite/cli/encode-libaom git.gammaspectra.live/S.O.N.G/Ignite/cli/encode-server
|
||||
RUN CGO_ENABLED=0 go build -v -tags 'osusergo netgo static_build' \
|
||||
-o /usr/bin/encode-pool git.gammaspectra.live/S.O.N.G/Ignite/cli/encode-pool
|
||||
|
||||
FROM alpine:3.18
|
||||
|
||||
COPY --from=builder /usr/bin/ignite-encode-libaom /usr/bin/ignite-encode-libaom
|
||||
COPY --from=builder /usr/bin/encode-* /usr/bin/
|
||||
|
||||
WORKDIR /
|
|
@ -15,6 +15,7 @@ import (
|
|||
"slices"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -33,6 +34,44 @@ type ServerConfig struct {
|
|||
URL string `yaml:"url"`
|
||||
Key string `yaml:"key"`
|
||||
InsecureSSL bool `yaml:"insecure_ssl"`
|
||||
lastStatus atomic.Pointer[encode_utils.StatusData]
|
||||
nextStatus atomic.Int64
|
||||
}
|
||||
|
||||
func (s *ServerConfig) Status() *encode_utils.StatusData {
|
||||
if time.Unix(s.nextStatus.Load(), 0).Compare(time.Now()) < 0 {
|
||||
defer func() {
|
||||
s.nextStatus.Store(time.Now().Add(time.Second * 30).Unix())
|
||||
}()
|
||||
u, _ := url.Parse(s.URL + "/status?k=" + s.Key)
|
||||
response, err := s.Do(&http.Request{
|
||||
Method: "GET",
|
||||
URL: u,
|
||||
})
|
||||
if err != nil {
|
||||
return s.lastStatus.Load()
|
||||
}
|
||||
defer response.Body.Close()
|
||||
dataBuf, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return s.lastStatus.Load()
|
||||
}
|
||||
var status encode_utils.StatusData
|
||||
err = json.Unmarshal(dataBuf, &status)
|
||||
if err != nil {
|
||||
return s.lastStatus.Load()
|
||||
}
|
||||
s.lastStatus.Store(&status)
|
||||
}
|
||||
return s.lastStatus.Load()
|
||||
}
|
||||
|
||||
func (s *ServerConfig) Do(r *http.Request) (*http.Response, error) {
|
||||
if s.InsecureSSL {
|
||||
return InsecureDefaultClient.Do(r)
|
||||
} else {
|
||||
return DefaultClient.Do(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerConfig) Pass(r *http.Request, replaceValues ...[2]string) (*http.Response, error) {
|
||||
|
@ -47,21 +86,12 @@ func (s *ServerConfig) Pass(r *http.Request, replaceValues ...[2]string) (*http.
|
|||
}
|
||||
urlPath.RawQuery = q.Encode()
|
||||
|
||||
if s.InsecureSSL {
|
||||
return InsecureDefaultClient.Do(&http.Request{
|
||||
Method: r.Method,
|
||||
URL: urlPath,
|
||||
Header: r.Header,
|
||||
Body: r.Body,
|
||||
})
|
||||
} else {
|
||||
return DefaultClient.Do(&http.Request{
|
||||
Method: r.Method,
|
||||
URL: urlPath,
|
||||
Header: r.Header,
|
||||
Body: r.Body,
|
||||
})
|
||||
}
|
||||
return s.Do(&http.Request{
|
||||
Method: r.Method,
|
||||
URL: urlPath,
|
||||
Header: r.Header,
|
||||
Body: r.Body,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *ServerConfig) Redirect(w http.ResponseWriter, r *http.Request, replaceValues ...[2]string) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"git.gammaspectra.live/S.O.N.G/Ignite/encoder/libx264"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io"
|
||||
|
@ -35,11 +36,6 @@ func main() {
|
|||
authKeys = strings.Split(*authKeysStr, ",")
|
||||
}
|
||||
|
||||
type encoderData struct {
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
writeHeaders := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("x-encoder-max-jobs", strconv.FormatUint(*maxJobs, 10))
|
||||
w.Header().Set("x-encoder-current-jobs", strconv.FormatUint(uint64(len(jobs)), 10))
|
||||
|
@ -51,18 +47,13 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
var statusData struct {
|
||||
Encoders []encoderData `json:"encoders"`
|
||||
Host *host.InfoStat `json:"host,omitempty"`
|
||||
CPU []cpu.InfoStat `json:"cpu"`
|
||||
Memory *mem.VirtualMemoryStat `json:"memory,omitempty"`
|
||||
}
|
||||
var statusData encode_utils.StatusData
|
||||
|
||||
statusData.Encoders = append(statusData.Encoders, encoderData{
|
||||
statusData.Encoders = append(statusData.Encoders, encode_utils.StatusEncoderData{
|
||||
Name: encode_utils.EncoderX264,
|
||||
Version: libx264.Version(),
|
||||
})
|
||||
statusData.Encoders = append(statusData.Encoders, encoderData{
|
||||
statusData.Encoders = append(statusData.Encoders, encode_utils.StatusEncoderData{
|
||||
Name: encode_utils.EncoderAOM,
|
||||
Version: libaom.Version(),
|
||||
})
|
||||
|
@ -80,6 +71,11 @@ func main() {
|
|||
statusData.Host = hostInfo
|
||||
}
|
||||
|
||||
loadInfo, err := load.Avg()
|
||||
if err == nil {
|
||||
statusData.Load = loadInfo
|
||||
}
|
||||
|
||||
memInfo, err := mem.VirtualMemory()
|
||||
if err == nil {
|
||||
statusData.Memory = memInfo
|
||||
|
|
22
cli/encode-utils/status.go
Normal file
22
cli/encode-utils/status.go
Normal file
|
@ -0,0 +1,22 @@
|
|||
package encode_utils
|
||||
|
||||
import (
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
"github.com/shirou/gopsutil/host"
|
||||
"github.com/shirou/gopsutil/load"
|
||||
"github.com/shirou/gopsutil/mem"
|
||||
)
|
||||
|
||||
type StatusEncoderData struct {
|
||||
Name string
|
||||
Version string
|
||||
}
|
||||
|
||||
type StatusData struct {
|
||||
Encoders []StatusEncoderData `json:"encoders"`
|
||||
Host *host.InfoStat `json:"host,omitempty"`
|
||||
Load *load.AvgStat `json:"load,omitempty"`
|
||||
CPU []cpu.InfoStat `json:"cpu"`
|
||||
CPULoad float64 `json:"cpu_load"`
|
||||
Memory *mem.VirtualMemoryStat `json:"memory,omitempty"`
|
||||
}
|
Loading…
Reference in a new issue