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

Added profile_memory() and profile_goroutines() VQL functions #2887

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions actions/query_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ func (self *QueryLogEntry) Close() {
self.mu.Lock()
defer self.mu.Unlock()

// Query was already closed - allow Close to be called multiple
// times.
if self.Duration > 0 {
return
}

self.Duration = time.Now().UnixNano() - self.Start.UnixNano()

// We represent Duration == 0 as not yet complete but sometimes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Elastic.Events.Upload
aliases:
- Elastic.Events.Clients

description: |
This server monitoring artifact will watch a selection of client or
server monitoring artifacts for new events and push those to an
Expand Down
56 changes: 56 additions & 0 deletions artifacts/definitions/Generic/Client/Profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ description: |
at the same time since this artifacts itself will not be doing very
much other than just measuring the state of the process.

NOTE: As of 0.7.0 release, this artifact will also collect
goroutines and heap profiles as distinct sources in a more readable
way.

parameters:
- name: Allocs
Expand Down Expand Up @@ -66,6 +69,11 @@ parameters:
description: Duration of sampling for Profile and Trace.
default: "30"

export: |
LET CleanUp(Name) = regex_replace(
re="www.velocidex.com/golang/velociraptor/",
replace="", source=Name)

sources:
- query: |
SELECT Type,
Expand All @@ -77,3 +85,51 @@ sources:
logs=Logs, queries=QueryLogs, metrics=Metrics,
debug=if(condition=Verbose, then=2, else=1),
duration=atoi(string=Duration))

- name: Goroutines
query: |
SELECT *, {
SELECT format(format="%v (%v:%v)",
args=[CleanUp(Name=Name), basename(path=File), Line])
FROM CallStack
WHERE File =~ 'velociraptor|vfilter|go-ntfs'
LIMIT 10
} AS CallStack
FROM profile_goroutines()
WHERE CallStack

- name: Memory
query: |
SELECT InUseBytes, InUseObjects, {
SELECT format(format="%v (%v:%v)",
args=[CleanUp(Name=Name), basename(path=File), Line])
FROM CallStack
WHERE File =~ 'velociraptor|vfilter|go-ntfs'
LIMIT 10
} AS CallStack
FROM profile_memory()
ORDER BY InUseBytes DESC

- name: Logs
query: |
SELECT * FROM profile(logs=TRUE)

- name: RunningQueries
query: |
SELECT Line.Start AS Timestamp, Line.Query AS Query
FROM profile(queries=TRUE)
WHERE NOT Line.Duration

- name: AllQueries
query: |
SELECT Line.Start AS Timestamp, int(int = Line.Duration / 1000000) AS DurationSec, Line.Query AS Query
FROM profile(queries=TRUE)

- name: Metrics
query: |
SELECT Line.name AS Name, Line.value as value
FROM profile(metrics=TRUE)

column_types:
- name: InUseBytes
type: mb
5 changes: 1 addition & 4 deletions artifacts/definitions/Server/Monitor/Health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type: SERVER_EVENT

sources:
- name: Prometheus

# This artifact is populated by the frontend service using the
# total of all frontend metrics.
query: SELECT * FROM info() WHERE FALSE
query: SELECT sleep(time=10000000) FROM scope()

reports:
- type: SERVER_EVENT
Expand Down
58 changes: 58 additions & 0 deletions artifacts/definitions/Server/Monitor/Profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ description: |
kcachegrind profile.grind
```

NOTE: As of 0.7.0 release, this artifact will also collect
goroutines and heap profiles as distinct sources in a more readable
way.

type: SERVER

parameters:
Expand Down Expand Up @@ -63,6 +67,11 @@ parameters:
description: Duration of sampling for Profile and Trace.
default: "30"

export: |
LET CleanUp(Name) = regex_replace(
re="www.velocidex.com/golang/velociraptor/",
replace="", source=Name)

sources:
- query: |
SELECT Type,
Expand All @@ -74,3 +83,52 @@ sources:
logs=Logs, queries=QueryLogs, metrics=Metrics,
debug=if(condition=Verbose, then=2, else=1),
duration=atoi(string=Duration))

- name: Goroutines
query: |
SELECT *, {
SELECT format(format="%v (%v:%v)",
args=[CleanUp(Name=Name), basename(path=File), Line])
FROM CallStack
WHERE File =~ 'velociraptor|vfilter|go-ntfs'
LIMIT 10
} AS CallStack
FROM profile_goroutines()
WHERE CallStack

- name: Memory
query: |
SELECT InUseBytes, InUseObjects, {
SELECT format(format="%v (%v:%v)",
args=[CleanUp(Name=Name), basename(path=File), Line])
FROM CallStack
WHERE File =~ 'velociraptor|vfilter|go-ntfs'
LIMIT 10
} AS CallStack
FROM profile_memory()
ORDER BY InUseBytes DESC

- name: Logs
query: |
SELECT * FROM profile(logs=TRUE)

- name: RunningQueries
query: |
SELECT Line.Start AS Timestamp, Line.Query AS Query
FROM profile(queries=TRUE)
WHERE NOT Line.Duration

- name: AllQueries
query: |
SELECT Line.Start AS Timestamp, int(int = Line.Duration / 1000000) AS DurationSec, Line.Query AS Query
FROM profile(queries=TRUE)

- name: Metrics
query: |
SELECT Line.name AS Name, Line.value as value
FROM profile(metrics=TRUE)


column_types:
- name: InUseBytes
type: mb
Loading