Skip to content

Commit

Permalink
Merge pull request #122 from audebert/master
Browse files Browse the repository at this point in the history
journal: implement GetUsage() (sd_journal_get_usage())
  • Loading branch information
vcaputo committed Nov 4, 2015
2 parents db04588 + 8d9fef8 commit b4a58d9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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)
}
}

0 comments on commit b4a58d9

Please sign in to comment.