-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
132 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package driver | ||
|
||
import "github.com/bisoncorps/saido/inspector" | ||
|
||
type fields struct { | ||
// Supported inspectors for specific driver | ||
Supported []inspector.Inspector | ||
// Supported inspector representations for specific driver | ||
Supported []string | ||
// Selected inspector representations | ||
Selected []string | ||
// Polling interval between retrievals | ||
PollInterval int64 | ||
} | ||
|
||
// Driver : specification of functions to be defined by every Driver | ||
type Driver interface { | ||
readFile(path string) (string, error) | ||
runCommand(command string) (string, error) | ||
ReadFile(path string) (string, error) | ||
RunCommand(command string) (string, error) | ||
// shows the driver details, not sure if we should be showing OS name | ||
getDetails() string | ||
GetDetails() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package inspector | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// DF : Parsing the `df` output for memory monitoring | ||
type DF struct { | ||
fields | ||
} | ||
|
||
func (i *DF) Parse(output string) { | ||
log.Debug(output) | ||
} | ||
|
||
// NewDF : Initialize a new DF instance | ||
func NewDF() *DF { | ||
return &DF{ | ||
fields: fields{ | ||
Type: Command, | ||
Command: `df -a`, | ||
}, | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// +build !windows | ||
|
||
package inspector | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestDF(t *testing.T) { | ||
d := NewDF() | ||
if d.Type != Command || d.Command != `df -a` { | ||
t.Error("Initialized df wrongly") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,52 @@ | ||
package inspector | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Mode : This specifies whether an Inspector is a command or a file | ||
type Mode int | ||
|
||
const ( | ||
// Command : Inspector is a command to be executes | ||
Command Mode = iota | ||
// File : Inspector is a file to be read | ||
File | ||
) | ||
|
||
var inspectorMap = map[string]Inspector{ | ||
`df`: NewDF(), | ||
} | ||
|
||
type fields struct { | ||
// Specify a mode for the Inspector | ||
Type Mode | ||
// File path to read | ||
FilePath string | ||
// Command to execute | ||
Command string | ||
} | ||
|
||
func (f *fields) String() string { | ||
value := `None` | ||
if f.Type == Command { | ||
value = f.Command | ||
} else if f.Type == File { | ||
value = f.FilePath | ||
} | ||
return value | ||
} | ||
|
||
// Inspector : defines a particular metric supported by a driver | ||
type Inspector interface{} | ||
type Inspector interface { | ||
Parse(output string) | ||
} | ||
|
||
// GetInspector : obtain an initialized inspector using name | ||
func GetInspector(name string) Inspector { | ||
val, ok := inspectorMap[name] | ||
if !ok { | ||
log.Fatalf(`%s inspector not found`, name) | ||
} | ||
return val | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// +build !windows | ||
|
||
package integration | ||
|
||
import ( | ||
"github.com/bisoncorps/saido/driver" | ||
"github.com/bisoncorps/saido/inspector" | ||
"testing" | ||
) | ||
|
||
func TestDFonLocal(t *testing.T) { | ||
d := driver.Local{} | ||
i := inspector.NewDF() | ||
output, err := d.RunCommand(i.String()) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
i.Parse(output) | ||
} |