public void UpdateDataSource(DatabaseData srcDatabase, DsDef updatedDsDef, DsDef originalDsDef) { RrdDb database = null; try { database = new RrdDb(srcDatabase.Definition.Path, false); Datasource datasource = database.getDatasource(originalDsDef.getDsName()); if (datasource == null) { throw new ArgumentException(updatedDsDef.getDsName() + " datasource don't exist"); } if (datasource.DsName != updatedDsDef.DsName) { datasource.setDsName(updatedDsDef.getDsName()); } datasource.setDsType(updatedDsDef.getDsType()); datasource.setHeartbeat(updatedDsDef.getHeartbeat()); datasource.setMaxValue(updatedDsDef.getMaxValue(), true); datasource.setMinValue(updatedDsDef.getMinValue(), true); } catch (FileNotFoundException ex) { Logger.Error("Update datasource failed", ex); throw new ApplicationException("Can't update datasource until database saved!", ex); } finally { if (database != null) { database.close(); } } }
public RrdDb GetDb() { const int heartBeat = 5 * 60; // * 1000 string _dbPath = Settings.Default.GetAppDataPath() + "xgsnapshots.db"; try { var db = new RrdDb(_dbPath); var sourcesToAdd = new HashSet <int>(); for (int a = 0; a <= 29; a++) { if (!db.containsDs(a + "")) { sourcesToAdd.Add(a); } } if (sourcesToAdd.Count > 0) { db.close(); foreach (int a in sourcesToAdd) { var dsDef = new DsDef(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue); RrdToolkit.addDatasource(_dbPath, _dbPath + ".new", dsDef); FileSystem.DeleteFile(_dbPath); FileSystem.MoveFile(_dbPath + ".new", _dbPath); } db = new RrdDb(_dbPath); } return(db); } catch (FileNotFoundException) { var rrdDef = new RrdDef(_dbPath, heartBeat); for (int a = 0; a <= 29; a++) { rrdDef.addDatasource(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue); } rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 1, 12 * 24); // one day > 1 step = 5 minutes, 12 times per hour * 24 hours rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 12, 24 * 7); // one week > 12 steps = 1 hour, 24 times per day * 7 days rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 4 * 12, 6 * 31); // one month > 4 * 12 steps = 4 hours, 6 times per day * 31 days rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 2 * 24 * 12, 183); // one year > 2 * 24 * 12 steps = 2 days, 183 days try { new RrdDb(rrdDef).close(); } catch (NullReferenceException) {} return(new RrdDb(_dbPath)); } }
public RrdDb GetDb() { const int heartBeat = 5 * 60; // * 1000 string _dbPath = Settings.Default.GetAppDataPath() + "xgsnapshots.db"; try { var db = new RrdDb(_dbPath); var sourcesToAdd = new HashSet<int>(); for (int a = 0; a <= 29; a++) { if (!db.containsDs(a + "")) { sourcesToAdd.Add(a); } } if (sourcesToAdd.Count > 0) { db.close(); foreach (int a in sourcesToAdd) { var dsDef = new DsDef(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue); RrdToolkit.addDatasource(_dbPath, _dbPath + ".new", dsDef); FileSystem.DeleteFile(_dbPath); FileSystem.MoveFile(_dbPath + ".new", _dbPath); } db = new RrdDb(_dbPath); } return db; } catch (FileNotFoundException) { var rrdDef = new RrdDef(_dbPath, heartBeat); for (int a = 0; a <= 29; a++) { rrdDef.addDatasource(a + "", DsTypes.DT_GAUGE, heartBeat * 2, 0, Double.MaxValue); } rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 1, 12 * 24); // one day > 1 step = 5 minutes, 12 times per hour * 24 hours rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 12, 24 * 7); // one week > 12 steps = 1 hour, 24 times per day * 7 days rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 4 * 12, 6 * 31); // one month > 4 * 12 steps = 4 hours, 6 times per day * 31 days rrdDef.addArchive(ConsolFuns.CF_AVERAGE, 0.5, 2 * 24 * 12, 183); // one year > 2 * 24 * 12 steps = 2 days, 183 days try { new RrdDb(rrdDef).close(); } catch (NullReferenceException) {} return new RrdDb(_dbPath); } }
public void DatasourceArchiveSelected(DatabaseData database, object datasource, object archiveDefinition) { if (!model.IsDatabase(database.Definition.Path)) { return; } DsDef dsDef = datasource as DsDef; ArcDef selectedArchive = archiveDefinition as ArcDef; FetchData fetchedData = model.GetArchiveData(database, dsDef.DsName, selectedArchive); rrdDbForm.SetArchiveDumpData(fetchedData); rrdDbForm.SetDocumentName(Path.GetFileNameWithoutExtension(database.Definition.getPath())); }
public void UpdateDataSource(string command, DsDef originalDsDef) { RrdDbParser parser = new RrdDbParser(""); model.UpdateDataSource(SrcDatabase, parser.parseDef(command), originalDsDef); }
public void AddDataSource(DsDef dsDef) { EditingDatabaseData.Definition.addDatasource(dsDef); DatabaseDirty = true; }