Documentation
¶
Index ¶
- Constants
- func NewHTTPClient(timeout time.Duration, transport http.RoundTripper) *http.Client
- func NewRouter(dt *Dt) *mux.Router
- func StartPullWithInterval(dt *Dt)
- type CommandProvider
- type DCOSHelper
- type DCOSTools
- func (st *DCOSTools) CloseDBUSConnection() error
- func (st *DCOSTools) DetectIP() (string, error)
- func (st *DCOSTools) Get(url string, timeout time.Duration) (body []byte, httpResponseCode int, err error)
- func (st *DCOSTools) GetAgentNodes() (nodes []Node, err error)
- func (st *DCOSTools) GetHostname() (string, error)
- func (st *DCOSTools) GetJournalOutput(unit string) (string, error)
- func (st *DCOSTools) GetMasterNodes() (nodesResponse []Node, err error)
- func (st *DCOSTools) GetMesosNodeID() (string, error)
- func (st *DCOSTools) GetNodeRole() (string, error)
- func (st *DCOSTools) GetTimestamp() time.Time
- func (st *DCOSTools) GetUnitNames() (units []string, err error)
- func (st *DCOSTools) GetUnitProperties(pname string) (result map[string]interface{}, err error)
- func (st *DCOSTools) InitializeDBUSConnection() (err error)
- func (st *DCOSTools) Post(url string, timeout time.Duration) (body []byte, httpResponseCode int, err error)
- type DiagnosticsJob
- type Dt
- type FileProvider
- type HTTPProvider
- type HTTPRequester
- type HealthResponseValues
- type LogProviders
- type MonitoringResponse
- func (mr *MonitoringResponse) GetAllUnits() UnitsResponseJSONStruct
- func (mr *MonitoringResponse) GetLastUpdatedTime() string
- func (mr *MonitoringResponse) GetMasterAgentNodes() ([]Node, []Node, error)
- func (mr *MonitoringResponse) GetNodeByID(nodeIP string) (NodeResponseFieldsStruct, error)
- func (mr *MonitoringResponse) GetNodeUnitByNodeIDUnitID(nodeIP string, unitID string) (HealthResponseValues, error)
- func (mr *MonitoringResponse) GetNodeUnitsID(nodeIP string) (UnitsResponseJSONStruct, error)
- func (mr *MonitoringResponse) GetNodes() NodesResponseJSONStruct
- func (mr *MonitoringResponse) GetNodesForUnit(unitName string) (NodesResponseJSONStruct, error)
- func (mr *MonitoringResponse) GetSpecificNodeForUnit(unitName string, nodeIP string) (NodeResponseFieldsWithErrorStruct, error)
- func (mr *MonitoringResponse) GetUnit(unitName string) (UnitResponseFieldsStruct, error)
- func (mr *MonitoringResponse) UpdateMonitoringResponse(r *MonitoringResponse)
- type Node
- type NodeResponseFieldsStruct
- type NodeResponseFieldsWithErrorStruct
- type NodesNotFoundError
- type NodesResponseJSONStruct
- type SystemdUnits
- type Unit
- type UnitPropertiesResponse
- type UnitResponseFieldsStruct
- type UnitsHealthResponseJSONStruct
- type UnitsResponseJSONStruct
Constants ¶
const ( // All stands for collecting logs from all discovered nodes. All = "all" // Masters stand for collecting from discovered master nodes. Masters = "masters" // Agents stand for collecting from discovered agent/agent_public nodes. Agents = "agents" )
const ( // MasterRole DC/OS role for a master. MasterRole = dcos.RoleMaster // AgentRole DC/OS role for an agent. AgentRole = dcos.RoleAgent // AgentPublicRole DC/OS role for a public agent. AgentPublicRole = dcos.RoleAgentPublic )
const BaseRoute string = "/system/health/v1"
BaseRoute a base 3dt endpoint location.
Variables ¶
This section is empty.
Functions ¶
func NewHTTPClient ¶
NewHTTPClient creates a new instance of http.Client
func StartPullWithInterval ¶
func StartPullWithInterval(dt *Dt)
StartPullWithInterval will start to pull a DC/OS cluster health status
Types ¶
type CommandProvider ¶
type CommandProvider struct {
Command []string
Role []string
// contains filtered or unexported fields
}
CommandProvider is a local command to execute.
type DCOSHelper ¶
type DCOSHelper interface {
// open dbus connection
InitializeDBUSConnection() error
// close dbus connection
CloseDBUSConnection() error
// function to get Connection.GetUnitProperties(pname)
// returns a maps of properties https://github.com/coreos/go-systemd/blob/master/dbus/methods.go#L176
GetUnitProperties(string) (map[string]interface{}, error)
// A wrapper to /opt/mesosphere/bin/detect_ip script
// should return empty string if script fails.
DetectIP() (string, error)
// get system's hostname
GetHostname() (string, error)
// Detect node role: master/agent
GetNodeRole() (string, error)
// Get DC/OS systemd units on a system
GetUnitNames() ([]string, error)
// Get journal output
GetJournalOutput(string) (string, error)
// Get mesos node id, first argument is a function to determine a role.
GetMesosNodeID() (string, error)
// Get makes HTTP GET request, return read arrays of bytes
Get(string, time.Duration) ([]byte, int, error)
// Post makes HTTP GET request, return read arrays of bytes
Post(string, time.Duration) ([]byte, int, error)
// LookupMaster will lookup a masters in DC/OS cluster.
// Initial lookup will be done by making HTTP GET request to exhibitor.If GET request fails, the next lookup
// will failover to history service for one minute, it this fails or no nodes found, masters will be looked up
// in history service for last hour.
GetMasterNodes() ([]Node, error)
//
//// GetAgentsFromMaster will lookup agents in DC/OS cluster.
GetAgentNodes() ([]Node, error)
// Get timestamp
GetTimestamp() time.Time
}
DCOSHelper DC/OS specific tools interface.
type DCOSTools ¶
type DCOSTools struct {
sync.Mutex
ExhibitorURL string
Role string
ForceTLS bool
NodeInfo nodeutil.NodeInfo
Transport http.RoundTripper
// contains filtered or unexported fields
}
DCOSTools is implementation of DCOSHelper interface.
func (*DCOSTools) CloseDBUSConnection ¶
CloseDBUSConnection closes a dbus connection.
func (*DCOSTools) DetectIP ¶
DetectIP returns a detected IP by running /opt/mesosphere/bin/detect_ip. It will run only once and cache the result. When the function is called again, ip will be taken from cache.
func (*DCOSTools) Get ¶
func (st *DCOSTools) Get(url string, timeout time.Duration) (body []byte, httpResponseCode int, err error)
Get HTTP request.
func (*DCOSTools) GetAgentNodes ¶
GetAgentNodes finds DC/OS agents.
func (*DCOSTools) GetHostname ¶
GetHostname return a localhost hostname.
func (*DCOSTools) GetJournalOutput ¶
GetJournalOutput returns last 50 lines of journald command output for a specific systemd Unit.
func (*DCOSTools) GetMasterNodes ¶
GetMasterNodes finds DC/OS masters.
func (*DCOSTools) GetMesosNodeID ¶
GetMesosNodeID return a mesos node id.
func (*DCOSTools) GetNodeRole ¶
GetNodeRole returns a nodes role. It will run only once and cache the result. When the function is called again, ip will be taken from cache.
func (*DCOSTools) GetTimestamp ¶
GetTimestamp return time.Now()
func (*DCOSTools) GetUnitNames ¶
GetUnitNames read a directory /etc/systemd/system/dcos.target.wants and return a list of found systemd units.
func (*DCOSTools) GetUnitProperties ¶
GetUnitProperties return a map of systemd Unit properties received from dbus.
func (*DCOSTools) InitializeDBUSConnection ¶
InitializeDBUSConnection opens a dbus connection. The connection is available via st.dcon
type DiagnosticsJob ¶
type DiagnosticsJob struct {
sync.Mutex
Transport http.RoundTripper `json:"-"`
Running bool `json:"is_running"`
Status string `json:"status"`
Errors []string `json:"errors"`
LastBundlePath string `json:"last_bundle_dir"`
JobStarted time.Time `json:"job_started"`
JobEnded time.Time `json:"job_ended"`
JobDuration time.Duration `json:"job_duration"`
JobProgressPercentage float32 `json:"job_progress_percentage"`
// contains filtered or unexported fields
}
DiagnosticsJob is the main structure for a logs collection job.
func (*DiagnosticsJob) Init ¶
func (j *DiagnosticsJob) Init(cfg *config.Config, DCOSTools DCOSHelper) error
Init will prepare diagnostics job, read config files etc.
type Dt ¶
type Dt struct {
Cfg *config.Config
DtDCOSTools DCOSHelper
DtDiagnosticsJob *DiagnosticsJob
RunPullerChan chan bool
RunPullerDoneChan chan bool
SystemdUnits *SystemdUnits
MR *MonitoringResponse
}
Dt is a struct of dependencies used in 3dt code. There are 2 implementations, the one runs on a real system and the one used for testing.
type FileProvider ¶
type FileProvider struct {
Location string
Role []string
// contains filtered or unexported fields
}
FileProvider is a local file provider.
type HTTPProvider ¶
HTTPProvider is a provider for fetching an HTTP endpoint.
type HTTPRequester ¶
type HTTPRequester interface {
Init(*config.Config, DCOSHelper) error
Do(*http.Request, time.Duration) (*http.Response, error)
Transport() http.RoundTripper
}
HTTPRequester is an interface to make HTTP requests
type HealthResponseValues ¶
type HealthResponseValues struct {
UnitID string `json:"id"`
UnitHealth int `json:"health"`
UnitOutput string `json:"output"`
UnitTitle string `json:"description"`
Help string `json:"help"`
PrettyName string `json:"name"`
}
HealthResponseValues is a health values json response.
type LogProviders ¶
type LogProviders struct {
HTTPEndpoints []HTTPProvider
LocalFiles []FileProvider
LocalCommands []CommandProvider
}
LogProviders a structure defines a list of Providers
type MonitoringResponse ¶
type MonitoringResponse struct {
sync.RWMutex
Units map[string]Unit
Nodes map[string]Node
UpdatedTime time.Time
}
MonitoringResponse top level global variable to store the entire units/nodes status tree.
func (*MonitoringResponse) GetAllUnits ¶
func (mr *MonitoringResponse) GetAllUnits() UnitsResponseJSONStruct
GetAllUnits returns all systemd units from status tree.
func (*MonitoringResponse) GetLastUpdatedTime ¶
func (mr *MonitoringResponse) GetLastUpdatedTime() string
GetLastUpdatedTime returns timestamp of latest updated monitoring response.
func (*MonitoringResponse) GetMasterAgentNodes ¶
func (mr *MonitoringResponse) GetMasterAgentNodes() ([]Node, []Node, error)
GetMasterAgentNodes returns a list of master and agent nodes available in status tree.
func (*MonitoringResponse) GetNodeByID ¶
func (mr *MonitoringResponse) GetNodeByID(nodeIP string) (NodeResponseFieldsStruct, error)
GetNodeByID returns a node by IP address from a status tree.
func (*MonitoringResponse) GetNodeUnitByNodeIDUnitID ¶
func (mr *MonitoringResponse) GetNodeUnitByNodeIDUnitID(nodeIP string, unitID string) (HealthResponseValues, error)
GetNodeUnitByNodeIDUnitID returns a Unit status by node IP address and Unit ID.
func (*MonitoringResponse) GetNodeUnitsID ¶
func (mr *MonitoringResponse) GetNodeUnitsID(nodeIP string) (UnitsResponseJSONStruct, error)
GetNodeUnitsID returns a Unit status for a given node from status tree.
func (*MonitoringResponse) GetNodes ¶
func (mr *MonitoringResponse) GetNodes() NodesResponseJSONStruct
GetNodes gets all available nodes in status tree.
func (*MonitoringResponse) GetNodesForUnit ¶
func (mr *MonitoringResponse) GetNodesForUnit(unitName string) (NodesResponseJSONStruct, error)
GetNodesForUnit get all hosts for a specific Unit available in status tree.
func (*MonitoringResponse) GetSpecificNodeForUnit ¶
func (mr *MonitoringResponse) GetSpecificNodeForUnit(unitName string, nodeIP string) (NodeResponseFieldsWithErrorStruct, error)
GetSpecificNodeForUnit gets a specific node for a given Unit from a status tree.
func (*MonitoringResponse) GetUnit ¶
func (mr *MonitoringResponse) GetUnit(unitName string) (UnitResponseFieldsStruct, error)
GetUnit gets a specific Unit from a status tree.
func (*MonitoringResponse) UpdateMonitoringResponse ¶
func (mr *MonitoringResponse) UpdateMonitoringResponse(r *MonitoringResponse)
UpdateMonitoringResponse will update the status tree.
type Node ¶
type Node struct {
Leader bool
Role string
IP string
Host string
Health int
Output map[string]string
Units []Unit `json:",omitempty"`
MesosID string
}
Node for DC/OS node.
type NodeResponseFieldsStruct ¶
type NodeResponseFieldsStruct struct {
HostIP string `json:"host_ip"`
NodeHealth int `json:"health"`
NodeRole string `json:"role"`
}
NodeResponseFieldsStruct contains a response from a node.
type NodeResponseFieldsWithErrorStruct ¶
type NodeResponseFieldsWithErrorStruct struct {
HostIP string `json:"host_ip"`
NodeHealth int `json:"health"`
NodeRole string `json:"role"`
UnitOutput string `json:"output"`
Help string `json:"help"`
}
NodeResponseFieldsWithErrorStruct contains node response with errors.
type NodesNotFoundError ¶
type NodesNotFoundError struct {
// contains filtered or unexported fields
}
NodesNotFoundError is a custom error called when nodes are not found.
func (NodesNotFoundError) Error ¶
func (n NodesNotFoundError) Error() string
type NodesResponseJSONStruct ¶
type NodesResponseJSONStruct struct {
Array []*NodeResponseFieldsStruct `json:"nodes"`
}
NodesResponseJSONStruct contains an array of responses from nodes.
type SystemdUnits ¶
SystemdUnits used to make GetUnitsProperties thread safe.
func (*SystemdUnits) GetUnits ¶
func (s *SystemdUnits) GetUnits(tools DCOSHelper) (allUnits []HealthResponseValues, err error)
GetUnits returns a list of found unit properties.
func (*SystemdUnits) GetUnitsProperties ¶
func (s *SystemdUnits) GetUnitsProperties(cfg *config.Config, tools DCOSHelper) (healthReport UnitsHealthResponseJSONStruct, err error)
GetUnitsProperties return a structured units health response of UnitsHealthResponseJsonStruct type.
type Unit ¶
type Unit struct {
UnitName string
Nodes []Node `json:",omitempty"`
Health int
Title string
Timestamp time.Time
PrettyName string
}
Unit for stands for systemd unit.
type UnitPropertiesResponse ¶
type UnitPropertiesResponse struct {
ID string `json:"Id"`
LoadState string
ActiveState string
SubState string
Description string
ExecMainStatus int
InactiveExitTimestampMonotonic uint64
ActiveEnterTimestampMonotonic uint64
ActiveExitTimestampMonotonic uint64
InactiveEnterTimestampMonotonic uint64
}
UnitPropertiesResponse is a structure to unmarshal dbus.GetunitProperties response
func (*UnitPropertiesResponse) CheckUnitHealth ¶
func (u *UnitPropertiesResponse) CheckUnitHealth() (int, string, error)
CheckUnitHealth tells if the Unit is healthy
type UnitResponseFieldsStruct ¶
type UnitResponseFieldsStruct struct {
UnitID string `json:"id"`
PrettyName string `json:"name"`
UnitHealth int `json:"health"`
UnitTitle string `json:"description"`
}
UnitResponseFieldsStruct contains systemd unit health report.
type UnitsHealthResponseJSONStruct ¶
type UnitsHealthResponseJSONStruct struct {
Array []HealthResponseValues `json:"units"`
System sysMetrics `json:"system"`
Hostname string `json:"hostname"`
IPAddress string `json:"ip"`
DcosVersion string `json:"dcos_version"`
Role string `json:"node_role"`
MesosID string `json:"mesos_id"`
TdtVersion string `json:"3dt_version"`
}
UnitsHealthResponseJSONStruct json response /system/health/v1
type UnitsResponseJSONStruct ¶
type UnitsResponseJSONStruct struct {
Array []UnitResponseFieldsStruct `json:"units"`
}
UnitsResponseJSONStruct contains health overview, collected from all hosts