Skip to content

Commit 83b7c0f

Browse files
committed
refactor agent
1 parent e096bcf commit 83b7c0f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

agent/http.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ func (a *Agent) createAgentProcess(proc *hostProc) *types.AgentProcess {
9898
log.Debugf("Cmdline could not found for %d\n", proc.process.Pid)
9999
}
100100
return &types.AgentProcess{
101-
Laddr: types.IPPort{IP: proc.conn.Laddr.IP, Port: proc.conn.Laddr.Port},
102-
Status: proc.conn.Status,
103-
Pid: proc.conn.Pid,
104-
Name: name,
105-
CmdLine: cl,
106-
Hostname: a.Hostname,
101+
Laddr: types.IPPort{IP: proc.conn.Laddr.IP, Port: proc.conn.Laddr.Port},
102+
Status: proc.conn.Status,
103+
Pid: proc.conn.Pid,
104+
Name: name,
105+
CmdLine: cl,
107106
}
108107
}
109108

@@ -117,11 +116,14 @@ func (a *Agent) Process(w http.ResponseWriter, req *http.Request) {
117116
}
118117
p := a.findProc(port)
119118
ap := a.createAgentProcess(p)
119+
120+
w.Header().Set("Content-Type", "application/json")
120121
if ap == nil {
121-
http.Error(w, "process not found!", http.StatusNotFound)
122+
json.NewEncoder(w).Encode(&types.AgentProcess{
123+
Hostname: a.Hostname,
124+
})
122125
return
123126
}
124-
w.Header().Set("Content-Type", "application/json")
125127
json.NewEncoder(w).Encode(&ap)
126128
return
127129
}

server/agent.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ func (a *Agent) Fetch(ctx context.Context, host string, port uint32) (*types.Age
4444
return nil, errors.New("status code is not 200")
4545
}
4646

47-
dp := types.AgentProcess{}
48-
err = json.NewDecoder(response.Body).Decode(&dp)
47+
ap := types.AgentProcess{}
48+
err = json.NewDecoder(response.Body).Decode(&ap)
4949

5050
// todo: consider NotFound
5151
if err != nil {
5252
log.Errorln(err.Error())
5353
return nil, err
5454
}
5555

56-
return &dp, nil
56+
return &ap, nil
5757
}

server/client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ func (kp *KimoProcess) SetAgentProcess(ctx context.Context, wg *sync.WaitGroup)
4040
host = kp.MysqlProcess.Address.IP
4141
port = kp.MysqlProcess.Address.Port
4242
}
43-
dp, err := kp.Agent.Fetch(ctx, host, port)
43+
ap, err := kp.Agent.Fetch(ctx, host, port)
4444
if err != nil {
4545
log.Debugln(err.Error())
46-
kp.AgentProcess = &types.AgentProcess{}
46+
kp.AgentProcess = &types.AgentProcess{
47+
Hostname: "ERROR",
48+
}
4749
} else {
48-
kp.AgentProcess = dp
50+
kp.AgentProcess = ap
4951
}
5052
}
5153

0 commit comments

Comments
 (0)