Skip to content

Commit

Permalink
added nmon remote file position control and improved measurement buil…
Browse files Browse the repository at this point in the history
…ding process
  • Loading branch information
toni-moreno committed Mar 9, 2018
1 parent 35fbbbd commit e0f98a8
Show file tree
Hide file tree
Showing 9 changed files with 615 additions and 237 deletions.
38 changes: 33 additions & 5 deletions pkg/agent/devices/nmon/import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nmon

import (
"github.com/adejoux/pSeriesCollector/pkg/config"
"github.com/adejoux/pSeriesCollector/pkg/data/pointarray"
)

Expand All @@ -11,18 +12,45 @@ func (d *Server) ImportData(points *pointarray.PointArray) error {
if d.nmonFile == nil {
d.Infof("Initializing Nmon Remote File")
d.nmonFile = NewNmonFile(d.client, d.GetLogger(), d.cfg.NmonFilePath, d.cfg.Name)
d.nmonFile.Init()
filepos, err := d.nmonFile.Init()
if err != nil {
d.Errorf("Something happen on Initialize Nmon file: %s", err)
return err
}
// Got last known position
info, err := db.GetNmonFileInfoByIDFile(d.cfg.ID, d.nmonFile.CurFile)
if err != nil {
d.Debugf("Warning on get file info for ID [%s] and file [%s] ", d.cfg.ID, d.nmonFile.CurFile)
d.Infof("Current File Position %s is: %d", d.nmonFile.CurFile, filepos)
} else {
d.nmonFile.SetPosition(info.LastPosition)
d.Infof("Updated File Position %s now to: %d", d.nmonFile.CurFile, info.LastPosition)
}
d.Debugf("Found Dataseries: %#+v", d.nmonFile.DataSeries)
d.Debugf("Found Content %s", d.nmonFile.TextContent)
}

if d.nmonFile.ReopenIfChanged() {
//if file has been rotated with format like /var/log/nmon/%{hostname}_%Y%m%d_%H%M.nmon
//old file has been closed and a new one opened
// we should now rescan definitions
d.Infof("File %s should be rescanned for new sections/columns ", d.nmonFile.CurFile)
pos, err := d.nmonFile.InitSectionDefs()
if err != nil {
return err
}

// now last file has been closed and a new one created
//PENDING delete from FileInfo last file
db.AddOrUpdateNmonFileInfo(&config.NmonFileInfo{ID: d.cfg.ID, DeviceName: d.cfg.Name, FileName: d.nmonFile.CurFile, LastPosition: pos})

}

d.nmonFile.UpdateContent()
filepos := d.nmonFile.UpdateContent()
// Add last processed lines

d.nmonFile.ProcessPending(points, d.TagMap)

d.Debugf("SFTP status %#+v", d.client)
d.Infof("Current File Position is [%d] last processed Chunk %s ", filepos, d.nmonFile.LastTime.String())
db.AddOrUpdateNmonFileInfo(&config.NmonFileInfo{ID: d.cfg.ID, DeviceName: d.cfg.Name, FileName: d.nmonFile.CurFile, LastPosition: filepos})

return nil
}
Loading

0 comments on commit e0f98a8

Please sign in to comment.