mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
cmd/stateth: add flag for dashboards folder. extract json from binary into json file
This commit is contained in:
parent
9e55d310ed
commit
a6ef68fa78
2 changed files with 39 additions and 15 deletions
|
|
@ -1,7 +1,3 @@
|
|||
package main
|
||||
|
||||
var (
|
||||
jsonDashboard = `
|
||||
{
|
||||
"annotations": {
|
||||
"list": [
|
||||
|
|
@ -231,5 +227,5 @@ var (
|
|||
"uid": "dUpKvj7mz",
|
||||
"version": 7
|
||||
}
|
||||
`
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -20,6 +20,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
|
|
@ -33,9 +34,10 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
dockerPrefix string // unique prefix used for the created docker resources
|
||||
grafanaPort int // expose port for the Grafana HTTP interface
|
||||
influxdbPort int // expose port for the InfluxDB HTTP interface
|
||||
dockerPrefix string // unique prefix used for the created docker resources
|
||||
dashboardsFolder string // folder containing all dashboards to be imported in Grafana
|
||||
grafanaPort int // expose port for the Grafana HTTP interface
|
||||
influxdbPort int // expose port for the InfluxDB HTTP interface
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -66,6 +68,11 @@ func main() {
|
|||
Value: 3000,
|
||||
Usage: "default grafana http port",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "grafana-dashboards-folder",
|
||||
Value: os.Getenv("GOPATH") + "/src/github.com/ethereum/go-ethereum/cmd/stateth/grafana_dashboards",
|
||||
Usage: "default grafana dashboards folder",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker-prefix",
|
||||
Value: "stateth",
|
||||
|
|
@ -78,6 +85,7 @@ func main() {
|
|||
dockerPrefix = c.String("docker-prefix")
|
||||
grafanaPort = c.Int("grafana-http-port")
|
||||
influxdbPort = c.Int("influxdb-http-port")
|
||||
dashboardsFolder = c.String("grafana-dashboards-folder")
|
||||
|
||||
if err := runNetwork(c); err != nil {
|
||||
return err
|
||||
|
|
@ -93,7 +101,7 @@ func main() {
|
|||
if err := importGrafanaDatasource(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := importGrafanaDashboard(c); err != nil {
|
||||
if err := importGrafanaDashboards(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +232,7 @@ func importGrafanaDatasource(c *cli.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func importGrafanaDashboard(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))
|
||||
if err != nil {
|
||||
|
|
@ -232,12 +240,32 @@ func importGrafanaDashboard(c *cli.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
model := prepareDashboardModel(jsonDashboard)
|
||||
|
||||
_, err = gclient.SaveDashboard(model, false)
|
||||
files, err := ioutil.ReadDir(dashboardsFolder)
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
name := f.Name()
|
||||
if strings.Contains(name, "json") {
|
||||
log.Info("importing dashboard", "dashboard", name)
|
||||
|
||||
blob, err := ioutil.ReadFile(dashboardsFolder + "/" + name)
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
model := prepareDashboardModel(string(blob))
|
||||
|
||||
_, err = gclient.SaveDashboard(model, false)
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue