@@ -38,8 +38,9 @@ import (
3838)
3939
4040const (
41- CARADNO_NODE_BINARY = "cardano-node"
4241 AMARU_BINARY = "amaru"
42+ CARDANO_NODE_BINARY = "cardano-node"
43+ DINGO_BINARY = "dingo"
4344)
4445
4546// Global command line flags
@@ -1187,14 +1188,45 @@ func getResourceText(ctx context.Context) string {
11871188func getProcessMetrics (ctx context.Context ) (* process.Process , error ) {
11881189 cfg := config .GetConfig ()
11891190
1190- if cfg .Node .Binary == AMARU_BINARY {
1191- return getProcessMetricsByPidFile (cfg , ctx )
1192- } else {
1193- return getProcessMetricsByNameAndPort (cfg , ctx )
1191+ switch cfg .Node .Binary {
1192+ case AMARU_BINARY :
1193+ return getProcessMetricsByPidFile (ctx , cfg )
1194+ case DINGO_BINARY :
1195+ return getProcessMetricsByPid (ctx , 1 )
1196+ default :
1197+ return getProcessMetricsByNameAndPort (ctx , cfg )
11941198 }
11951199}
11961200
1197- func getProcessMetricsByPidFile (cfg * config.Config , ctx context.Context ) (* process.Process , error ) {
1201+ func getProcessMetricsByPid (
1202+ ctx context.Context ,
1203+ pid int32 ,
1204+ ) (* process.Process , error ) {
1205+ proc , err := process .NewProcessWithContext (ctx , pid )
1206+ if err != nil {
1207+ return nil , fmt .Errorf ("failed to get process %d: %w" , pid , err )
1208+ }
1209+
1210+ exists , err := proc .IsRunning ()
1211+ if err != nil {
1212+ return nil , fmt .Errorf (
1213+ "failed to check if process %d is running: %w" ,
1214+ pid ,
1215+ err ,
1216+ )
1217+ }
1218+
1219+ if ! exists {
1220+ return nil , fmt .Errorf ("process %d is not running" , pid )
1221+ }
1222+
1223+ return proc , nil
1224+ }
1225+
1226+ func getProcessMetricsByPidFile (
1227+ ctx context.Context ,
1228+ cfg * config.Config ,
1229+ ) (* process.Process , error ) {
11981230 data , err := os .ReadFile (cfg .Node .PidFile )
11991231 if err != nil {
12001232 return nil , fmt .Errorf ("failed to read pid file: %w" , err )
@@ -1207,8 +1239,6 @@ func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*proce
12071239 if pid <= 0 || pid > math .MaxInt32 {
12081240 return nil , fmt .Errorf ("invalid pid %d: out of int32 range" , pid )
12091241 }
1210-
1211- // the overflow is checked above
12121242 //nolint:gosec
12131243 proc , err := process .NewProcessWithContext (ctx , int32 (pid ))
12141244 if err != nil {
@@ -1217,7 +1247,11 @@ func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*proce
12171247
12181248 exists , err := proc .IsRunning ()
12191249 if err != nil {
1220- return nil , fmt .Errorf ("failed to check if process %d is running: %w" , pid , err )
1250+ return nil , fmt .Errorf (
1251+ "failed to check if process %d is running: %w" ,
1252+ pid ,
1253+ err ,
1254+ )
12211255 }
12221256
12231257 if ! exists {
@@ -1227,7 +1261,10 @@ func getProcessMetricsByPidFile(cfg *config.Config, ctx context.Context) (*proce
12271261 return proc , nil
12281262}
12291263
1230- func getProcessMetricsByNameAndPort (cfg * config.Config , ctx context.Context ) (* process.Process , error ) {
1264+ func getProcessMetricsByNameAndPort (
1265+ ctx context.Context ,
1266+ cfg * config.Config ,
1267+ ) (* process.Process , error ) {
12311268 r , _ := process .NewProcessWithContext (ctx , 0 )
12321269 processes , err := process .ProcessesWithContext (ctx )
12331270 if err != nil {
0 commit comments