summaryrefslogtreecommitdiff
path: root/cmd/_____/utils
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/_____/utils')
-rw-r--r--cmd/_____/utils/size.go28
-rw-r--r--cmd/_____/utils/workers.go37
2 files changed, 65 insertions, 0 deletions
diff --git a/cmd/_____/utils/size.go b/cmd/_____/utils/size.go
new file mode 100644
index 00000000..176cc9e1
--- /dev/null
+++ b/cmd/_____/utils/size.go
@@ -0,0 +1,28 @@
+package utils
+
+import (
+ "strconv"
+ "strings"
+)
+
+func ParseSize(size string) int64 {
+ if len(size) == 0 {
+ return 0
+ }
+
+ s, err := strconv.Atoi(size[:len(size)-1])
+ if err != nil {
+ return 0
+ }
+
+ switch strings.ToLower(size[len(size)-1:]) {
+ case "k", "kb":
+ return int64(s * 1024)
+ case "m", "mb":
+ return int64(s * 1024 * 1024)
+ case "g", "gb":
+ return int64(s * 1024 * 1024 * 1024)
+ }
+
+ return 0
+}
diff --git a/cmd/_____/utils/workers.go b/cmd/_____/utils/workers.go
new file mode 100644
index 00000000..1024b4c6
--- /dev/null
+++ b/cmd/_____/utils/workers.go
@@ -0,0 +1,37 @@
+package utils
+
+import "github.com/spiral/roadrunner"
+
+// Worker provides information about specific worker.
+type Worker struct {
+ // Pid contains process id.
+ Pid int `json:"pid"`
+
+ // Status of the worker.
+ Status string `json:"status"`
+
+ // Number of worker executions.
+ NumExecs uint64 `json:"numExecs"`
+
+ // Created is unix nano timestamp of worker creation time.
+ Created int64 `json:"created"`
+
+ // Updated is unix nano timestamp of last worker execution.
+ Updated int64 `json:"updated"`
+}
+
+// FetchWorkers fetches list of workers from RR Server.
+func FetchWorkers(srv *roadrunner.Server) (result []Worker) {
+ for _, w := range srv.Workers() {
+ state := w.State()
+ result = append(result, Worker{
+ Pid: *w.Pid,
+ Status: state.String(),
+ NumExecs: state.NumExecs(),
+ Created: w.Created.UnixNano(),
+ Updated: state.Updated().UnixNano(),
+ })
+ }
+
+ return
+} \ No newline at end of file