-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gains visibility over export creation. This is also usful for the offline collector too (when --debug is specified).
- Loading branch information
Showing
11 changed files
with
218 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package reporting | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
"time" | ||
|
||
"github.com/Velocidex/ordereddict" | ||
api_proto "www.velocidex.com/golang/velociraptor/api/proto" | ||
"www.velocidex.com/golang/velociraptor/services/debug" | ||
"www.velocidex.com/golang/vfilter" | ||
) | ||
|
||
var ( | ||
ContainerTracker = NewContainerTracker() | ||
) | ||
|
||
type WriterInfo struct { | ||
Name string | ||
TmpFile string | ||
CompressedSize int | ||
UncompressedSize int | ||
Created time.Time | ||
LastWrite time.Time | ||
Closed time.Time | ||
} | ||
|
||
type ContainerInfo struct { | ||
Name string | ||
BackingFile string | ||
Stats *api_proto.ContainerStats | ||
InFlightWriters map[uint64]*WriterInfo | ||
CreateTime time.Time | ||
CloseTime time.Time | ||
} | ||
|
||
type _ContainerTracker struct { | ||
mu sync.Mutex | ||
containers map[uint64]*ContainerInfo | ||
} | ||
|
||
func (self *_ContainerTracker) UpdateContainerWriter( | ||
container_id, writer_id uint64, cb func(info *WriterInfo)) { | ||
|
||
self.UpdateContainer(container_id, func(info *ContainerInfo) { | ||
writer_info, pres := info.InFlightWriters[writer_id] | ||
if !pres { | ||
writer_info = &WriterInfo{} | ||
info.InFlightWriters[writer_id] = writer_info | ||
} | ||
|
||
cb(writer_info) | ||
}) | ||
} | ||
|
||
func (self *_ContainerTracker) UpdateContainer( | ||
id uint64, cb func(info *ContainerInfo)) { | ||
self.mu.Lock() | ||
defer self.mu.Unlock() | ||
|
||
record, pres := self.containers[id] | ||
if !pres { | ||
record = &ContainerInfo{ | ||
InFlightWriters: make(map[uint64]*WriterInfo), | ||
} | ||
self.containers[id] = record | ||
} | ||
|
||
cb(record) | ||
} | ||
|
||
func (self *_ContainerTracker) WriteMetrics( | ||
ctx context.Context, scope vfilter.Scope, | ||
output_chan chan vfilter.Row) { | ||
|
||
self.mu.Lock() | ||
defer self.mu.Unlock() | ||
|
||
for _, container := range self.containers { | ||
for _, w := range container.InFlightWriters { | ||
output_chan <- ordereddict.NewDict(). | ||
Set("ContainerName", container.Name). | ||
Set("ZipCreateTime", container.CreateTime). | ||
Set("ZipCloseTime", container.CloseTime). | ||
Set("MemberName", w.Name). | ||
Set("MemberTmpFile", w.TmpFile). | ||
Set("MemberCreate", w.Created). | ||
Set("MemberCompressedSize", w.CompressedSize). | ||
Set("MemberUncompressedSize", w.UncompressedSize). | ||
Set("MemberLastWrite", w.LastWrite). | ||
Set("MemberClosed", w.Closed) | ||
} | ||
} | ||
} | ||
|
||
func NewContainerTracker() *_ContainerTracker { | ||
return &_ContainerTracker{ | ||
containers: make(map[uint64]*ContainerInfo), | ||
} | ||
} | ||
|
||
func init() { | ||
debug.RegisterProfileWriter(debug.ProfileWriterInfo{ | ||
Name: "ExportContainers", | ||
Description: "Report the state of current exports", | ||
ProfileWriter: ContainerTracker.WriteMetrics, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package reporting | ||
|
||
import ( | ||
"os" | ||
|
||
concurrent_zip "github.com/Velocidex/zip" | ||
"www.velocidex.com/golang/velociraptor/utils/tempfile" | ||
) | ||
|
||
type TmpfileFactory int | ||
|
||
func (self TmpfileFactory) TempFile() (*os.File, error) { | ||
tmpfile, err := tempfile.TempFile("zip") | ||
if err != nil { | ||
return nil, err | ||
} | ||
tempfile.AddTmpFile(tmpfile.Name()) | ||
|
||
return tmpfile, nil | ||
} | ||
|
||
func (self TmpfileFactory) RemoveTempFile(filename string) { | ||
err := os.Remove(filename) | ||
tempfile.RemoveTmpFile(filename, err) | ||
} | ||
|
||
func init() { | ||
concurrent_zip.SetTmpfileProvider(TmpfileFactory(0)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters