public RrdDef CreateDatabaseDef() { long start; DateTime startDateTime; string startOption = getOptionValue("b", "start", DEFAULT_START); try { if (DateTime.TryParse(startOption, out startDateTime)) { start = Util.getTimestamp(startDateTime); } else { start = long.Parse(startOption); } } catch (FormatException ex) { throw new ApplicationException("Bad date format:[" + startOption + "]." + ex.Message); } String stepOption = getOptionValue("s", "step", DEFAULT_STEP); long step = long.Parse(stepOption); String[] words = getRemainingWords(); if (words.Length < 3) { throw new ArgumentException("To few arguments! Use: create name DS:name:heartbeat:min:max [RRAdef]"); } if (words[0] != "create") { throw new ArgumentException("Wrong command format! Use: create name DS:name:heartbeat:min:max [RRAdef]"); } RrdDef rrdDef = new RrdDef(words[1], start, step); for (int i = 2; i < words.Length; i++) { if (words[i].StartsWith("DS:")) { rrdDef.addDatasource(parseDef(words[i])); } else if (words[i].StartsWith("RRA:")) { rrdDef.addArchive(parseRra(words[i])); } else { throw new ArgumentException("Invalid rrdcreate syntax. Not a DSDef or RRADef " + words[i] + "\nUse: create name DS:name:heartbeat:min:max [RRAdef]"); } } if (rrdDef.getDsCount() == 0) { throw new ArgumentException("No a Data source defined.\nUse: create name DS:name:heartbeat:min:max [RRAdef]"); } return(rrdDef); }
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); } }