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

journal: implement GetUsage() (sd_journal_get_usage()) #122

Merged
merged 1 commit into from
Nov 4, 2015
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
14 changes: 14 additions & 0 deletions sdjournal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,17 @@ func (j *Journal) Wait(timeout time.Duration) int {

return int(r)
}

// GetUsage returns the journal disk space usage, in bytes.
func (j *Journal) GetUsage() (uint64, error) {
var out C.uint64_t
j.mu.Lock()
err := C.sd_journal_get_usage(j.cjournal, &out)
j.mu.Unlock()

if err != 0 {
return 0, fmt.Errorf("failed to get journal disk space usage: %d", err)
}

return uint64(out), nil
}
20 changes: 20 additions & 0 deletions sdjournal/journal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,23 @@ func TestJournalFollow(t *testing.T) {
t.Fatalf("Error during follow: %s", err)
}
}

func TestJournalGetUsage(t *testing.T) {
j, err := NewJournal()

if err != nil {
t.Fatalf("Error opening journal: %s", err)
}

if j == nil {
t.Fatal("Got a nil journal")
}

defer j.Close()

_, err = j.GetUsage()

if err != nil {
t.Fatalf("Error getting journal size: %s", err)
}
}