Skip to content

Commit

Permalink
fecth process-agent status in core agent
Browse files Browse the repository at this point in the history
  • Loading branch information
mbotarro committed Feb 11, 2022
1 parent ccd5f8b commit 105db35
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 87 deletions.
11 changes: 11 additions & 0 deletions pkg/status/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ func FormatSecurityAgentStatus(data []byte) (string, error) {
return b.String(), nil
}

// FormatProcessAgentStatus takes a json bytestring and prints out the formatted status for process-agent
func FormatProcessAgentStatus(data []byte) (string, error) {
var b = new(bytes.Buffer)

stats := make(map[string]interface{})
json.Unmarshal(data, &stats) //nolint:errcheck
renderStatusTemplate(b, "/process-agent.tmpl", stats)

return b.String(), nil
}

// FormatMetadataMapCLI builds the rendering in the metadataMapper template.
func FormatMetadataMapCLI(data []byte) (string, error) {
var b = new(bytes.Buffer)
Expand Down
43 changes: 25 additions & 18 deletions pkg/status/status_process_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@
package status

import (
"encoding/json"
"fmt"

"github.com/DataDog/datadog-agent/cmd/process-agent/api"
apiutil "github.com/DataDog/datadog-agent/pkg/api/util"
)

// GetProcessAgentStats returns the status command of the process-agent
func GetProcessAgentStatus() map[string]interface{} {
//net.SetSystemProbePath(socketPath)
//probeUtil, err := net.GetRemoteSystemProbeUtil()
//TODO: do not use a global var for this
var httpClient = apiutil.GetClient(false)

//if err != nil {
// return map[string]interface{}{
// "Errors": fmt.Sprintf("%v", err),
// }
//}
// GetProcessAgentStatus returns the status command of the process-agent
func GetProcessAgentStatus() map[string]interface{} {
s := make(map[string]interface{})
addressPort, err := api.GetAPIAddressPort()
if err != nil {
s["error"] = fmt.Sprintf("%v", err.Error())
return s
}

processAgentStatus := map[string]interface{}{
"Errors": fmt.Sprintf("Testing process-agent status"),
statusEndpoint := fmt.Sprintf("http://%s/agent/status", addressPort)
b, err := apiutil.DoGet(httpClient, statusEndpoint)
if err != nil {
s["error"] = fmt.Sprintf("%v", err.Error())
return s
}

//systemProbeDetails, err := probeUtil.GetStats()
//if err != nil {
// return map[string]interface{}{
// "Errors": fmt.Sprintf("issue querying stats from system probe: %v", err),
// }
//}
err = json.Unmarshal(b, &s)
if err != nil {
s["error"] = fmt.Sprintf("%v", err.Error())
return s
}

return processAgentStatus
return s
}
106 changes: 37 additions & 69 deletions pkg/status/templates/process-agent.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,47 @@
Process Agent
=============

{{- if .Errors }}
Status: Testing Process Agent Status on main agent
Error: {{ .Errors }}
{{- if .error }}
Status: Not running or unreachable
{{- else }}
Status: Running
Uptime: {{ .uptime }}
Last Updated: {{ formatUnixTime .updated_at }}
{{- end }}
{{- if .network_tracer }}
Version: {{ .core.version }}
Status date: {{ formatUnixTime .date }}
Process Agent Start: {{ formatUnixTime .expvars.uptime_nano }}
Pid: {{ .expvars.pid }}
Go Version: {{ .core.go_version }}
Build arch: {{ .core.build_arch }}
Log Level: {{ .core.config.log_level }}
Enabled Checks: {{ .expvars.enabled_checks }}
Allocated Memory: {{ .expvars.memstats.alloc }} bytes
Hostname: {{ .core.metadata.meta.hostname }}

NPM
===
{{- if .network_tracer.Error }}
Status: Not running
Error: {{ .network_tracer.Error }}
=================
Process Endpoints
=================
{{- with .expvars.endpoints}}
{{- range $key, $value := .}}
{{$key}} - API Key{{ if gt (len $value) 1}}s{{end}} ending with:
{{- range $idx, $apikey := $value }}
- {{$apikey}}
{{- end}}
{{- end}}
{{- else }}
Status: Running
{{- if .network_tracer.tracer.last_check }}
Last Check: {{ formatUnixTime .network_tracer.tracer.last_check }}
{{- end }}
{{- if .network_tracer.state.clients }}
Client Count: {{ len .network_tracer.state.clients }}
{{- end }}
{{- end }}
{{- end }}
{{- if .oom_kill_probe }}

OOM Kill
========
{{- if .oom_kill_probe.Error }}
Status: Not running
Error: {{ .oom_kill_probe.Error }}
{{- else }}
Status: Running
{{- if .oom_kill_probe.last_check }}
Last Check: {{ formatUnixTime .oom_kill_probe.last_check }}
{{- end }}
{{- end }}
{{- end }}
{{- if .tcp_queue_length_tracer }}

TCP Queue Length
================
{{- if .tcp_queue_length_tracer.Error }}
Status: Not running
Error: {{ .tcp_queue_length_tracer.Error }}
{{- else }}
Status: Running
{{- if .tcp_queue_length_tracer.last_check }}
Last Check: {{ formatUnixTime .tcp_queue_length_tracer.last_check }}
{{- end }}
{{- end }}
{{- end }}
{{- if .security_runtime }}

Runtime Security
================
{{- if .security_runtime.Error }}
Status: Not running
Error: {{ .security_runtime.Error }}
{{- else }}
Status: Running
No endpoints information. The agent may be misconfigured.
{{- end }}
{{- end }}
{{- if .process }}

Process
=======
{{- if .process.Error }}
Status: Not running
Error: {{ .process.Error }}
{{- else }}
Status: Running
{{- end }}
{{- end }}
=========
Collector
=========

Last collection time: {{.expvars.last_collect_time}}
Docker socket: {{.expvars.docker_socket}}
Number of processes: {{.expvars.process_count}}
Number of containers: {{.expvars.container_count}}
Process Queue length: {{.expvars.process_queue_size}}
RTProcess Queue length: {{.expvars.rtprocess_queue_size}}
Pod Queue length: {{.expvars.pod_queue_size}}
Process Bytes enqueued: {{.expvars.process_queue_bytes}}
RTProcess Bytes enqueued: {{.expvars.rtprocess_queue_bytes}}
Pod Bytes enqueued: {{.expvars.pod_queue_bytes}}
{{ end }}

0 comments on commit 105db35

Please sign in to comment.