Added modification_time field

This commit is contained in:
Michael Travis 2016-12-02 14:21:36 +00:00
parent 504f4e69db
commit fe527ca6d9
3 changed files with 32 additions and 21 deletions

View File

@ -20,6 +20,7 @@ The filestat plugin gathers metrics about file existence, size, and other stats.
- filestat
- exists (int, 0 | 1)
- size_bytes (int, bytes)
- modification_time (int, unixtime)
- md5 (optional, string)
### Tags:
@ -33,5 +34,5 @@ The filestat plugin gathers metrics about file existence, size, and other stats.
$ telegraf -config /etc/telegraf/telegraf.conf -input-filter filestat -test
* Plugin: filestat, Collection 1
> filestat,file=/tmp/foo/bar,host=tyrion exists=0i 1461203374493128216
> filestat,file=/Users/sparrc/ws/telegraf.conf,host=tyrion exists=1i,size=47894i 1461203374493199335
> filestat,file=/Users/sparrc/ws/telegraf.conf,host=tyrion exists=1i,size=47894i,modification_time=1470234221i 1461203374493199335,
```

View File

@ -80,6 +80,7 @@ func (f *FileStat) Gather(acc telegraf.Accumulator) error {
fields := map[string]interface{}{
"exists": int64(1),
"size_bytes": fileInfo.Size(),
"modification_time": fileInfo.ModTime().Unix(),
}
if f.Md5 {

View File

@ -27,6 +27,7 @@ func TestGatherNoMd5(t *testing.T) {
fields1 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
}
acc.AssertContainsTaggedFields(t, "filestat", fields1, tags1)
@ -36,6 +37,7 @@ func TestGatherNoMd5(t *testing.T) {
fields2 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
}
acc.AssertContainsTaggedFields(t, "filestat", fields2, tags2)
@ -67,6 +69,7 @@ func TestGatherExplicitFiles(t *testing.T) {
fields1 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "d41d8cd98f00b204e9800998ecf8427e",
}
acc.AssertContainsTaggedFields(t, "filestat", fields1, tags1)
@ -77,6 +80,7 @@ func TestGatherExplicitFiles(t *testing.T) {
fields2 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "d41d8cd98f00b204e9800998ecf8427e",
}
acc.AssertContainsTaggedFields(t, "filestat", fields2, tags2)
@ -107,6 +111,7 @@ func TestGatherGlob(t *testing.T) {
fields1 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "d41d8cd98f00b204e9800998ecf8427e",
}
acc.AssertContainsTaggedFields(t, "filestat", fields1, tags1)
@ -117,6 +122,7 @@ func TestGatherGlob(t *testing.T) {
fields2 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "d41d8cd98f00b204e9800998ecf8427e",
}
acc.AssertContainsTaggedFields(t, "filestat", fields2, tags2)
@ -139,6 +145,7 @@ func TestGatherSuperAsterisk(t *testing.T) {
fields1 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "d41d8cd98f00b204e9800998ecf8427e",
}
acc.AssertContainsTaggedFields(t, "filestat", fields1, tags1)
@ -149,6 +156,7 @@ func TestGatherSuperAsterisk(t *testing.T) {
fields2 := map[string]interface{}{
"size_bytes": int64(0),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "d41d8cd98f00b204e9800998ecf8427e",
}
acc.AssertContainsTaggedFields(t, "filestat", fields2, tags2)
@ -159,6 +167,7 @@ func TestGatherSuperAsterisk(t *testing.T) {
fields3 := map[string]interface{}{
"size_bytes": int64(104),
"exists": int64(1),
"modification_time": int64(1)
"md5_sum": "5a7e9b77fa25e7bb411dbd17cf403c1f",
}
acc.AssertContainsTaggedFields(t, "filestat", fields3, tags3)