Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
33f2d0c1
Commit
33f2d0c1
authored
9 years ago
by
Diptanu Choudhury
Browse files
Options
Download
Email Patches
Plain Diff
Added a stats api for retreiving node stats
parent
6132ccc2
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/allocations.go
+3
-3
api/allocations.go
api/nodes.go
+57
-0
api/nodes.go
with
60 additions
and
3 deletions
+60
-3
api/allocations.go
+
3
-
3
View file @
33f2d0c1
...
...
@@ -46,7 +46,7 @@ func (a *Allocations) Info(allocID string, q *QueryOptions) (*Allocation, *Query
}
func
(
a
*
Allocations
)
Stats
(
alloc
*
Allocation
,
q
*
QueryOptions
)
(
map
[
string
]
*
TaskResourceUsage
,
error
)
{
node
,
_
,
err
:=
a
.
client
.
Nodes
()
.
Info
(
alloc
.
NodeID
,
&
QueryOptions
{}
)
node
,
_
,
err
:=
a
.
client
.
Nodes
()
.
Info
(
alloc
.
NodeID
,
q
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -71,7 +71,7 @@ func (a *Allocations) Stats(alloc *Allocation, q *QueryOptions) (map[string]*Tas
return
nil
,
err
}
if
resp
.
StatusCode
!=
200
{
return
nil
,
a
.
getErrorMsg
(
resp
)
return
nil
,
getErrorMsg
(
resp
)
}
decoder
:=
json
.
NewDecoder
(
resp
.
Body
)
var
stats
map
[
string
]
*
TaskResourceUsage
...
...
@@ -81,7 +81,7 @@ func (a *Allocations) Stats(alloc *Allocation, q *QueryOptions) (map[string]*Tas
return
stats
,
nil
}
func
(
a
*
Allocations
)
getErrorMsg
(
resp
*
http
.
Response
)
error
{
func
getErrorMsg
(
resp
*
http
.
Response
)
error
{
if
errMsg
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
);
err
==
nil
{
return
fmt
.
Errorf
(
string
(
errMsg
))
}
else
{
...
...
This diff is collapsed.
Click to expand it.
api/nodes.go
+
57
-
0
View file @
33f2d0c1
package
api
import
(
"encoding/json"
"fmt"
"net/http"
"net/url"
"sort"
"strconv"
)
...
...
@@ -71,6 +75,39 @@ func (n *Nodes) ForceEvaluate(nodeID string, q *WriteOptions) (string, *WriteMet
return
resp
.
EvalID
,
wm
,
nil
}
func
(
n
*
Nodes
)
Stats
(
nodeID
string
,
q
*
QueryOptions
)
(
*
HostStats
,
error
)
{
node
,
_
,
err
:=
n
.
client
.
Nodes
()
.
Info
(
nodeID
,
q
)
if
err
!=
nil
{
return
nil
,
err
}
if
node
.
HTTPAddr
==
""
{
return
nil
,
fmt
.
Errorf
(
"http addr of the node %q is running is not advertised"
,
nodeID
)
}
u
:=
&
url
.
URL
{
Scheme
:
"http"
,
Host
:
node
.
HTTPAddr
,
Path
:
"/v1/client/stats/"
,
}
req
:=
&
http
.
Request
{
Method
:
"GET"
,
URL
:
u
,
}
c
:=
http
.
Client
{}
resp
,
err
:=
c
.
Do
(
req
)
if
err
!=
nil
{
return
nil
,
err
}
if
resp
.
StatusCode
!=
200
{
return
nil
,
getErrorMsg
(
resp
)
}
decoder
:=
json
.
NewDecoder
(
resp
.
Body
)
var
stats
*
HostStats
if
err
:=
decoder
.
Decode
(
&
stats
);
err
!=
nil
{
return
nil
,
err
}
return
stats
,
nil
}
// Node is used to deserialize a node entry.
type
Node
struct
{
ID
string
...
...
@@ -90,6 +127,26 @@ type Node struct {
ModifyIndex
uint64
}
// HostStats represents resource usage stats of the host running a Nomad client
type
HostStats
struct
{
Memory
*
HostMemoryStats
CPU
[]
*
HostCPUStats
}
type
HostMemoryStats
struct
{
Total
uint64
Available
uint64
Used
uint64
Free
uint64
}
type
HostCPUStats
struct
{
CPU
string
User
float64
System
float64
Idle
float64
}
// NodeListStub is a subset of information returned during
// node list operations.
type
NodeListStub
struct
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help