File tree 4 files changed +79
-2
lines changed
4 files changed +79
-2
lines changed Original file line number Diff line number Diff line change @@ -3,16 +3,16 @@ module github.com/pnsafonov/pind
3
3
go 1.19
4
4
5
5
require (
6
- github.com/lrita/numa v1.0.2
6
+ github.com/lrita/numa v1.0.3
7
7
github.com/prometheus/procfs v0.12.0
8
8
github.com/sirupsen/logrus v1.9.3
9
+ github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
9
10
golang.org/x/sys v0.12.0
10
11
gopkg.in/natefinch/lumberjack.v2 v2.2.1
11
12
gopkg.in/yaml.v3 v3.0.1
12
13
)
13
14
14
15
require (
15
16
github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6 // indirect
16
- github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 // indirect
17
17
golang.org/x/sync v0.3.0 // indirect
18
18
)
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ github.com/intel-go/cpuid v0.0.0-20181003105527-1a4a6f06a1c6/go.mod h1:RmeVYf9Xr
7
7
github.com/konsorten/go-windows-terminal-sequences v1.0.1 /go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ =
8
8
github.com/lrita/numa v1.0.2 h1:RzJFNvgHXtzyf+RsGRP9XyMHjNUQFOEypv+2oXaJBj8 =
9
9
github.com/lrita/numa v1.0.2 /go.mod h1:B0HvTeFKP4P+yb/BvVhww9Sx+q/zZEwTfzPL0LhF79M =
10
+ github.com/lrita/numa v1.0.3 h1:9vx+77J1GSYdphcABftzenMTqzYLygLJa5EzZN1wa9w =
11
+ github.com/lrita/numa v1.0.3 /go.mod h1:B0HvTeFKP4P+yb/BvVhww9Sx+q/zZEwTfzPL0LhF79M =
10
12
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM =
11
13
github.com/pmezard/go-difflib v1.0.0 /go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4 =
12
14
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo =
Original file line number Diff line number Diff line change @@ -65,10 +65,38 @@ func (x *HttpApi) serve(l net.Listener) {
65
65
_ = x .Server .Serve (l )
66
66
}
67
67
68
+ func writeStateBytes (w http.ResponseWriter , state * State ) error {
69
+ stateBytes , err := json .MarshalIndent (state , "" , " " )
70
+ if err != nil {
71
+ log .Errorf ("HttpApi writeStateBytes, json.Marshal err = %v" , err )
72
+ return err
73
+ }
74
+
75
+ _ , err = w .Write (stateBytes )
76
+ return err
77
+ }
78
+
68
79
// getApiState - /api/state
69
80
func (x * HttpApi ) getApiState (w http.ResponseWriter , r * http.Request ) {
70
81
header := w .Header ()
71
82
header .Set ("Content-Type" , "application/json; charset=utf-8" )
72
83
84
+ // /api/state?vm_name=my_env_db
85
+ vmName := r .URL .Query ().Get ("vm_name" )
86
+ if vmName != "" {
87
+ state1 := x .state .CloneWithFilter1 (vmName )
88
+ _ = writeStateBytes (w , state1 )
89
+ return
90
+ }
91
+
92
+ // /api/state?vm_prefix=my_env_
93
+ vmPrefix := r .URL .Query ().Get ("vm_prefix" )
94
+ if vmPrefix != "" {
95
+ state1 := x .state .CloneWithFilter2 (vmPrefix )
96
+ _ = writeStateBytes (w , state1 )
97
+ return
98
+ }
99
+
100
+ // /api/state
73
101
_ , _ = w .Write (x .stateBytes )
74
102
}
Original file line number Diff line number Diff line change
1
+ package http_api
2
+
3
+ import "strings"
4
+
5
+ func (x * State ) CloneWithFilter0 (inFilter map [string ]* Proc ) * State {
6
+ procs0 := & Procs {
7
+ NotInFilter : x .Procs .NotInFilter ,
8
+ InFilter : inFilter ,
9
+ }
10
+
11
+ state0 := & State {
12
+ Version : x .Version ,
13
+ GitHash : x .GitHash ,
14
+ Errors : x .Errors ,
15
+ Time : x .Time ,
16
+ Procs : procs0 ,
17
+
18
+ Pool : x .Pool ,
19
+ Numa : x .Numa ,
20
+
21
+ Config : x .Config ,
22
+ }
23
+
24
+ return state0
25
+ }
26
+
27
+ func (x * State ) CloneWithFilter1 (vmName string ) * State {
28
+ inFilter := make (map [string ]* Proc )
29
+ for k , v := range x .Procs .InFilter {
30
+ if v .VmName == vmName {
31
+ inFilter [k ] = v
32
+ }
33
+ }
34
+
35
+ return x .CloneWithFilter0 (inFilter )
36
+ }
37
+
38
+ func (x * State ) CloneWithFilter2 (vmPrefix string ) * State {
39
+ inFilter := make (map [string ]* Proc )
40
+ for k , v := range x .Procs .InFilter {
41
+ if strings .HasPrefix (v .VmName , vmPrefix ) {
42
+ inFilter [k ] = v
43
+ }
44
+ }
45
+
46
+ return x .CloneWithFilter0 (inFilter )
47
+ }
You can’t perform that action at this time.
0 commit comments