Skip to content

Commit

Permalink
upload dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez committed Jun 26, 2024
1 parent c0d0e66 commit f6c3866
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion node/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ func WritePromtailConfig(filePath string, lokiIP string, lokiPort string, host s
}

// GetGrafanaUrl returns the URL of the Grafana dashboard.
func GetGrafanaUrl(monitoringHostIP string) string {
func GetGrafanaURL(monitoringHostIP string) string {
return fmt.Sprintf("http://%s:%d/dashboards", monitoringHostIP, constants.AvalanchegoGrafanaPort)
}
43 changes: 43 additions & 0 deletions node/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,21 @@ func (h *Node) RegisterWithMonitoring(targets []Node, chainID string) error {
wg.Wait()
if wgResults.HasErrors() {
return wgResults.Error()
}
// provide dashboards for targets
tmpdir, err := os.MkdirTemp("", constants.ServiceGrafana)
if err != nil {
return err
}
defer os.RemoveAll(tmpdir)
if err := monitoring.Setup(tmpdir); err != nil {
return err
}
if err := h.RunSSHSetupMonitoringFolders(); err != nil {
return err
}
if err := h.RunSSHCopyMonitoringDashboards(tmpdir); err != nil {

Check failure on line 335 in node/ssh.go

View workflow job for this annotation

GitHub Actions / Lint

SA9003: empty branch (staticcheck)

Check failure on line 336 in node/ssh.go

View workflow job for this annotation

GitHub Actions / Lint

File is not `gofumpt`-ed (gofumpt)
}
avalancheGoPorts, machinePorts, ltPorts := getPrometheusTargets(targets)
h.Logger.Infof("avalancheGoPorts: %v, machinePorts: %v, ltPorts: %v", avalancheGoPorts, machinePorts, ltPorts)
Expand All @@ -338,3 +353,31 @@ func (h *Node) RegisterWithMonitoring(targets []Node, chainID string) error {

return nil
}

func (h *Node) RunSSHCopyMonitoringDashboards(monitoringDashboardPath string) error {
// TODO: download dashboards from github instead
remoteDashboardsPath := utils.GetRemoteComposeServicePath("grafana", "dashboards")
if !utils.DirectoryExists(monitoringDashboardPath) {
return fmt.Errorf("%s does not exist", monitoringDashboardPath)
}
if err := h.MkdirAll(remoteDashboardsPath, constants.SSHFileOpsTimeout); err != nil {
return err
}
dashboards, err := os.ReadDir(monitoringDashboardPath)
if err != nil {
return err
}
for _, dashboard := range dashboards {
if err := h.Upload(
filepath.Join(monitoringDashboardPath, dashboard.Name()),
filepath.Join(remoteDashboardsPath, dashboard.Name()),
constants.SSHFileOpsTimeout,
); err != nil {
return err
}
}
if composeFileExists, err := h.FileExists(utils.GetRemoteComposeFile()); err == nil && composeFileExists {
return h.RestartDockerComposeService(utils.GetRemoteComposeFile(), constants.ServiceGrafana, constants.SSHScriptTimeout)
}
return nil
}
12 changes: 12 additions & 0 deletions utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ func FileExists(filename string) bool {
return !info.IsDir()
}

// DirectoryExists checks if a directory exists.
//
// dirName: the name of the directory to check.
// bool: returns true if the directory exists, false otherwise.
func DirectoryExists(dirName string) bool {
info, err := os.Stat(dirName)
if os.IsNotExist(err) {
return false
}
return info.IsDir()
}

// ExpandHome expands ~ symbol to home directory
func ExpandHome(path string) string {
if path == "" {
Expand Down

0 comments on commit f6c3866

Please sign in to comment.