Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prometheus monitoring service #95

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
mapAllPorts bool
noMev bool
noValidator bool
noProm bool
)

const (
Expand Down Expand Up @@ -250,6 +251,7 @@ func runCliCmd(cmd *cobra.Command, args []string) []error {
VlExtraFlags: *vlExtraFlags,
MapAllPorts: mapAllPorts,
Mev: !noMev && !noValidator,
Prom: !noProm,
}
elPort, clPort, err := generate.GenerateScripts(gd)
if err != nil {
Expand Down Expand Up @@ -334,6 +336,8 @@ func init() {

cliCmd.Flags().BoolVar(&noMev, "no-mev-boost", false, "Not use mev-boost if supported")

cliCmd.Flags().BoolVar(&noProm, "no-prometheus", false, "Not use prometheus monitoring")

cliCmd.Flags().BoolVar(&noValidator, "no-validator", false, "Exclude the validator from the full node setup. Designed for execution and consensus nodes setup without a validator node. Exclude also the validator from other flags. If set, mev-boost will not be used.")

cliCmd.Flags().StringVar(&jwtPath, "jwt-secret-path", "", "Path to the JWT secret file")
Expand Down
2 changes: 2 additions & 0 deletions configs/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
DependenciesOK = "All dependencies are installed on host machine"
GeneratingDockerComposeScript = "Generating docker-compose script for current selection of clients"
GeneratingEnvFile = "Generating environment file for current selection of clients"
GeneratingPrometheusFile = "Generating prometheus.yml file for the enabled prometheus service"
Exiting = "Exiting..."
InstructionsFor = "Instructions for %s"
OSNotSupported = "installation not supported for %s"
Expand Down Expand Up @@ -103,6 +104,7 @@ Follow https://launchpad.ethereum.org/ and happy staking!`
DefaultAdditionalApiPortCL = "4001"
DefaultMetricsPortVL = "5056"
DefaultMevPort = "18550"
DefaultPrometheusPort = "9090"
MapAllPortsWarning = "You are mapping all ports for the clients!!! Make sure this is intended. This could make the clients vulnerable to attacks. Be sure to setup a firewall."
CheckpointUrlUsedWarning = "A Checkpoint Sync Url will be used for the consensus node. Using %s ."
NoBootnodesFound = "No bootnodes found for %s/%s/%s"
Expand Down
62 changes: 62 additions & 0 deletions internal/pkg/generate/generate_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func GenerateScripts(gd GenerationData) (elPort, clPort string, err error) {
return "", "", err
}

log.Info(configs.GeneratingPrometheusFile)
err = generatePromFile(gd)
if err != nil {
return "", "", err
}

return ports["ELApi"], ports["CLApi"], nil
}

Expand Down Expand Up @@ -234,6 +240,7 @@ func generateDockerComposeScripts(gd GenerationData) (err error) {
ElExtraFlags: gd.ElExtraFlags,
ClExtraFlags: gd.ClExtraFlags,
VlExtraFlags: gd.VlExtraFlags,
Prom: gd.Prom,
Bootnodes: bootnodes,
MapAllPorts: gd.MapAllPorts,
SplittedNetwork: splittedNetwork,
Expand Down Expand Up @@ -352,6 +359,61 @@ func generateEnvFile(gd GenerationData) (err error) {
return nil
}

/*
generatePromFile :
This function is responsible for generating the prometheus.yml file needed for
the prometheus service to run

params :-
a. executionClient string
Execution client whose script was generated
b. consensusClient string
Execution client whose script was generated
c. validatorClient string
Execution client whose script was generated
d. path string
Path of generated scripts
salaheldinsoliman marked this conversation as resolved.
Show resolved Hide resolved

returns :-
a. error
Error if any
*/
func generatePromFile(gd GenerationData) (err error) {
rawBaseTmp, err := templates.Prometheus.ReadFile(filepath.Join("prometheus", "prometheus.tmpl"))
if err != nil {
return
}

baseTmp, err := template.New("prometheus").Parse(string(rawBaseTmp))
if err != nil {
return
}

// TODO: Use OS wise delimiter for these data structs
data := PrometheusData{
ExecutionClient: gd.ExecutionClient.Name,
ClMetricsPort: gd.Ports["CLMetrics"],
VlMetricsPort: gd.Ports["VLMetrics"],
ElMetricsPort: gd.Ports["ELMetrics"],
}

// Print prometheus configuration file
log.Infof(configs.PrintingFile, "prometheus.yml")
err = baseTmp.Execute(os.Stdout, data)
if err != nil {
return fmt.Errorf(configs.PrintingFileError, ".yml", err)
}
fmt.Println()

err = writeTemplateToFile(baseTmp, filepath.Join(gd.GenerationPath, "prometheus.yml"), data, false)
if err != nil {
return fmt.Errorf(configs.GeneratingScriptsError, gd.ExecutionClient.Name, gd.ConsensusClient.Name, gd.ValidatorClient.Name, err)
}
log.Infof(configs.CreatedFile, filepath.Join(gd.GenerationPath, "prometheus.yml"))

return nil
}

/*
writeTemplateToFile :
Write template to `file`.
Expand Down
9 changes: 9 additions & 0 deletions internal/pkg/generate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type GenerationData struct {
MapAllPorts bool
Mev bool
Ports map[string]string
Prom bool
}

// DockerComposeData : Struct Data object to be applied to docker-compose script
Expand All @@ -67,6 +68,7 @@ type DockerComposeData struct {
VlRemoteDpl bool
XeeVersion bool
Mev bool
Prom bool
MevPort string
CheckpointSyncUrl string
FeeRecipient string
Expand All @@ -89,3 +91,10 @@ type DockerComposeData struct {
SplittedNetwork bool
ClCheckpointSyncUrl bool
}

type PrometheusData struct {
salaheldinsoliman marked this conversation as resolved.
Show resolved Hide resolved
ExecutionClient string
ElMetricsPort string
ClMetricsPort string
VlMetricsPort string
}
15 changes: 15 additions & 0 deletions templates/prometheus/prometheus.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_configs:
- job_name: 'validator'
static_configs:
- targets: ['localhost:{{.VlMetricsPort}}']
- job_name: 'execution'
static_configs:
- targets: ['localhost:{{.ElMetricsPort}}']
{{if eq .ExecutionClient "geth"}}metrics_path: /debug/metrics/prometheus{{end}}
- job_name: 'consensus'
static_configs:
- targets: ['localhost:{{.ClMetricsPort}}']
9 changes: 9 additions & 0 deletions templates/services/docker-compose_base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ services:
sh -c "{{if or .CcRemoteCfg .VlRemoteCfg }}wget -O /tmp/app/config.yml ${CONFIG_URL};{{end}}{{if or .CcRemoteGen .VlRemoteGen }}wget -O /tmp/app/genesis.ssz ${GENESIS_URL};{{end}}{{if or .CcRemoteDpl .VlRemoteDpl }}echo -n ${DEPLOY_BLOCK} > /tmp/app/deploy_block.txt;{{end}}"{{end}}
{{template "consensus" .}}
{{template "validator" .}}
{{if .Prom}}
prometheus:
image: ubuntu/prometheus
network_mode: host
container_name: prometheus-container
volumes:
- './prometheus.yml:/etc/prometheus/prometheus.yml'
environment:
- TZ=UTC{{ end }}

networks:
sedge:
Expand Down
1 change: 1 addition & 0 deletions templates/services/merge/execution/geth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- --syncmode=${EC_SYNC_MODE}
- --http
- --http.addr=0.0.0.0
{{if .Prom}}- --metrics.addr=0.0.0.0{{end}}
- --http.vhosts=*
salaheldinsoliman marked this conversation as resolved.
Show resolved Hide resolved
- --http.corsdomain=*
- --http.api
Expand Down
3 changes: 3 additions & 0 deletions templates/services/merge/execution/nethermind.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- ${EC_DATA_DIR}:/nethermind/data
- ${EC_JWT_SECRET_PATH}:/tmp/jwt/jwtsecret
ports:
- "{{.ElMetricsPort}}:{{.ElMetricsPort}}"
- "{{.ElDiscoveryPort}}:{{.ElDiscoveryPort}}/tcp"
- "{{.ElDiscoveryPort}}:{{.ElDiscoveryPort}}/udp"{{if .MapAllPorts}}
- "{{.ElApiPort}}:{{.ElApiPort}}"
salaheldinsoliman marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -19,6 +20,8 @@
- {{.ElApiPort}}
- {{.ElAuthPort}}
command:
{{if .Prom}}- --Metrics.ExposePort={{.ElMetricsPort}}
- --Metrics.Enabled=true{{end}}
- --config={{if .SplittedNetwork}}${EL_NETWORK}{{else}}${NETWORK}{{end}}
salaheldinsoliman marked this conversation as resolved.
Show resolved Hide resolved
- --datadir=/nethermind/data
- --log=${NETHERMIND_LOG_LEVEL}{{with .TTD}}
Expand Down
3 changes: 3 additions & 0 deletions templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ var DepositCLI embed.FS

//go:embed scripts
var Scripts embed.FS

//go:embed prometheus
var Prometheus embed.FS