mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
cmd/stateth: check if influxdb and grafana images are present
This commit is contained in:
parent
5051bd59eb
commit
0d0fcb6225
1 changed files with 32 additions and 12 deletions
|
|
@ -44,6 +44,8 @@ var (
|
|||
influxdbPort int // expose port for the InfluxDB HTTP interface
|
||||
influxdbDatabase string // name of database to provision on InfluxDB
|
||||
rm bool // remove stateth containers and stateth network upon startup
|
||||
|
||||
grafanaIP string
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -136,7 +138,7 @@ func main() {
|
|||
|
||||
sigs := make(chan os.Signal, 1)
|
||||
done := make(chan bool, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
||||
|
||||
go func() {
|
||||
sig := <-sigs
|
||||
|
|
@ -149,7 +151,7 @@ func main() {
|
|||
fmt.Println(fmt.Sprintf("username: %s", grafanaUser))
|
||||
fmt.Println(fmt.Sprintf("password: %s", grafanaPass))
|
||||
fmt.Println()
|
||||
fmt.Println("waiting for SIGINT or SIGTERM (CTRL^C) to stop service and remove containers...")
|
||||
fmt.Println("waiting for SIGINT, SIGTERM or SIGHUP to stop service and remove containers...")
|
||||
<-done
|
||||
|
||||
cleanupContainers(c)
|
||||
|
|
@ -170,13 +172,17 @@ func runNetwork(c *cli.Context) {
|
|||
}
|
||||
|
||||
func runInfluxDB(c *cli.Context) error {
|
||||
command := strings.Split("docker image inspect influxdb:1.5.2", " ")
|
||||
r, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Info("pulling influxdb:1.5.2 docker image")
|
||||
command := strings.Split("docker pull influxdb:1.5.2", " ")
|
||||
r, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
_, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Error(err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("running influxdb docker container", "container", fmt.Sprintf("%s_influxdb", dockerPrefix))
|
||||
command = strings.Split(fmt.Sprintf("docker run --network %s --name %s_influxdb -e INFLUXDB_DB=%s -e INFLUXDB_ADMIN_USER=%s -e INFLUXDB_ADMIN_PASSWORD=%s -p %d:8086 -d influxdb:1.5.2", dockerNetwork, dockerPrefix, influxdbDatabase, influxdbAdminUser, influxdbAdminPass, influxdbPort), " ")
|
||||
|
|
@ -189,13 +195,17 @@ func runInfluxDB(c *cli.Context) error {
|
|||
}
|
||||
|
||||
func runGrafana(c *cli.Context) error {
|
||||
command := strings.Split("docker image inspect grafana/grafana:5.1.3", " ")
|
||||
r, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Info("pulling grafana/grafana:5.1.3 docker image")
|
||||
command := strings.Split("docker pull grafana/grafana:5.1.3", " ")
|
||||
r, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
_, err := exec.Command(command[0], command[1:]...).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Error(string(r))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("running grafana docker container", "container", fmt.Sprintf("%s_grafana", dockerPrefix))
|
||||
command = strings.Split(fmt.Sprintf("docker run --network %s --name=%s_grafana -p %d:3000 -e GF_AUTH_ANONYMOUS_ENABLED=true -d grafana/grafana:5.1.3", dockerNetwork, dockerPrefix, grafanaPort), " ")
|
||||
|
|
@ -204,6 +214,16 @@ func runGrafana(c *cli.Context) error {
|
|||
log.Error(string(r))
|
||||
return err
|
||||
}
|
||||
|
||||
r, err = exec.Command("docker", "inspect", "-f", "'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'", "stateth_grafana").CombinedOutput()
|
||||
if err != nil {
|
||||
log.Error(string(r))
|
||||
return err
|
||||
}
|
||||
|
||||
grafanaIP = strings.Trim(string(r), "' \n")
|
||||
|
||||
log.Info("grafana docker container ip", "ip", grafanaIP)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -232,7 +252,7 @@ func cleanupContainers(c *cli.Context) {
|
|||
|
||||
func importGrafanaDatasource(c *cli.Context) error {
|
||||
log.Info("importing grafana datasource")
|
||||
gclient, err := gapi.New(fmt.Sprintf("%s:%s", grafanaUser, grafanaPass), fmt.Sprintf("http://localhost:%d", grafanaPort))
|
||||
gclient, err := gapi.New(fmt.Sprintf("%s:%s", grafanaUser, grafanaPass), fmt.Sprintf("http://%s:%d", grafanaIP, grafanaPort))
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
return nil
|
||||
|
|
@ -261,7 +281,7 @@ func importGrafanaDatasource(c *cli.Context) error {
|
|||
|
||||
func importGrafanaDashboards(c *cli.Context) error {
|
||||
log.Info("importing grafana dashboards")
|
||||
gclient, err := gapi.New(fmt.Sprintf("%s:%s", grafanaUser, grafanaPass), fmt.Sprintf("http://localhost:%d", grafanaPort))
|
||||
gclient, err := gapi.New(fmt.Sprintf("%s:%s", grafanaUser, grafanaPass), fmt.Sprintf("http://%s:%d", grafanaIP, grafanaPort))
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue