protected override void Run() { //if (VariableRegex == null || VariableRegex.Length == 0) throw new Exception("Performance counter names should be passed in VariableRegex"); //if (Variables != null && Variables.Length > 0 && Variables.Length != VariableRegex.Length) throw new Exception("Number of Variables does not match the length of VariableRegex"); DataRecord dr = new DataRecord { Series = this.DataSeries }; if (Variables == null || Variables.Length == 0) { if (string.IsNullOrEmpty(ScriptName)) throw new Exception("ScriptName parameter should contain perf counter Id if you are not using Variables"); var pv = Counters.GetPerfCounterValuesAndReset(this.ScriptName); dr.Data = new double[] { pv.Count, pv.Sum, pv.Min, pv.Max, pv.Median, pv.Perc90, pv.Perc95, pv.Perc98, pv.Avg, pv.Freq }; } else { if (VariableRegex == null || VariableRegex.Length == 0) { string pcid = this.ScriptName; var pv = Counters.GetPerfCounterValuesAndReset(pcid); dr.DataMap = new Dictionary<string, double>(); for (int i = 0; i < Variables.Length; i++) { var pi = pv.GetType().GetProperty(Variables[i]); if (pi == null) throw new Exception("Invalid variable: " + Variables[i]); dr.DataMap[Variables[i]] = Convert.ToDouble(pi.GetValue(pv, null)); } } else if (VariableRegex.Length != Variables.Length) { throw new Exception("VariableRegex length invalid"); } else { Dictionary<string, PerfCounterStats> d = new Dictionary<string, PerfCounterStats>(); dr.DataMap = new Dictionary<string, double>(); for (int i = 0; i < Variables.Length; i++) { var vn = VariableRegex[i]; int idx = vn.IndexOf('/'); string cid = idx < 0 ? this.ScriptName : vn.Substring(0, idx); PerfCounterStats pv; if (!d.TryGetValue(cid, out pv)) { pv = Counters.GetPerfCounterValuesAndReset(cid); d[cid] = pv; } string cv = idx < 0 ? vn : vn.Substring(idx + 1); var pi = typeof(PerfCounterStats).GetProperty(cv); if (pi == null) throw new Exception("Invalid perf counter statistic: " + vn); dr.DataMap[Variables[i]] = Convert.ToDouble(pi.GetValue(pv, null)); } } } UpdateDataSource(dr); }
protected override void Run() { string hostName = this.Arguments; if (string.IsNullOrEmpty(hostName)) return; if (hostName.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase)) { DoHttpPing(hostName); return; } Ping p = new Ping(); var resp = p.Send(hostName); log.Debug("Pinged {0}. Response: {1}, time: {2} ms", hostName, resp.Status, resp.RoundtripTime); DataRecord dr = new DataRecord { Series = this.DataSeries, Data = new double[] { resp.Status == IPStatus.Success ? resp.RoundtripTime : Double.NaN } }; UpdateDataSource(dr); }
protected override void Run() { string cs = this.Arguments; var cstring = string.IsNullOrEmpty(cs) ? ConfigurationManager.ConnectionStrings[0] : ConfigurationManager.ConnectionStrings[cs]; if (cstring == null) throw new Exception("Connection string not found (Arguments: " + cs + ")"); string pn = string.IsNullOrEmpty(cstring.ProviderName) ? "System.Data.SqlClient" : cstring.ProviderName; if (string.IsNullOrEmpty(this.ScriptName)) throw new Exception("SQL not defined (ScriptName parameter)"); List<DataRecord> lst = new List<DataRecord>(); using (var cn = DbProviderFactories.GetFactory(pn).CreateConnection()) { cn.ConnectionString = cstring.ConnectionString; cn.Open(); using (var cmd = cn.CreateCommand()) { cmd.CommandText = this.ScriptName; using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { var rec = new DataRecord { Series = this.DataSeries, DataMap = new Dictionary<string,double>() }; for (int i = 0; i < dr.FieldCount; i++) { string fn = dr.GetName(i); if (fn == "timestamp") { rec.Ts = dr.GetDateTime(i); } else { rec.DataMap[fn] = dr.IsDBNull(i) ? double.NaN : Convert.ToDouble(dr[i]); } } lst.Add(rec); } } } } if (lst.Count == 0) { log.Warn("Job {0}: No data returned by sql query", this.Id); return; } UpdateDataSource(lst); }
protected void DoHttpPing(string hostName) { DataRecord dr = new DataRecord { Series = this.DataSeries, Data = new double[] { Double.NaN } }; Stopwatch sw = Stopwatch.StartNew(); try { System.Net.WebClient wc = new System.Net.WebClient(); wc.DownloadData(hostName); sw.Stop(); dr.Data[0] = sw.ElapsedMilliseconds; } catch (System.Net.WebException ex) { log.Warn("Http ping error in job {0} ({1}): {2}", Id, hostName, ex); dr.Data[0] = Double.NaN; } UpdateDataSource(dr); }
protected override void Run() { if (VariableRegex == null || VariableRegex.Length == 0) throw new Exception("Performance counter names should be passed in VariableRegex"); if (Variables != null && Variables.Length > 0 && Variables.Length != VariableRegex.Length) throw new Exception("Number of Variables does not match the length of VariableRegex"); DataRecord dr = new DataRecord { Series = this.DataSeries }; if (Variables != null && Variables.Length > 0) dr.DataMap = new Dictionary<string, double>(); else dr.Data = new double[this.VariableRegex.Length]; for (int i = 0; i < VariableRegex.Length; i++) { var val = PerfCounters.GetValue(VariableRegex[i]); log.Debug("PC[{0}]={1}", VariableRegex[i], val); if (dr.Data != null) dr.Data[i] = val; if (dr.DataMap != null) dr.DataMap[Variables[i]] = val; } UpdateDataSource(dr); }
public ActionResult Update(string seriesName) { var si = DataSeries.GetDataSeries(seriesName, false); if (si == null) throw new Exception("Data series not found: " + seriesName); var dr = new DataRecord(); dr.Ts = DateTime.Now; dr.Series = si.Name; List<double> l = new List<double>(); foreach (var f in si.Fields) { string s = Request[f.Name]; if (string.IsNullOrEmpty(s)) throw new Exception("Missing data field: " + f.Name); double v; if (!double.TryParse(s, out v)) throw new Exception("Invalid field: " + f.Name); l.Add(v); } dr.Data = l.ToArray(); DataSeries.AppendData(dr); return new EmptyResult(); }
protected void add_data_record(IDictionary<string, double> values) { DataRecord dr = new DataRecord { DataMap = new Dictionary<string, double>(values) }; DataRecords.Add(dr); }
protected void add_data_record(params double[] values) { DataRecord dr = new DataRecord { Data = values }; DataRecords.Add(dr); }
protected void add_data_record(DataRecord dr) { DataRecords.Add(dr); }
protected void add_data_record(DateTime timestamp, IDictionary<string, double> values) { DataRecord dr = new DataRecord { Ts = timestamp, DataMap = new Dictionary<string, double>(values) }; DataRecords.Add(dr); }
protected void add_data_record(DateTime timestamp, double[] values) { DataRecord dr = new DataRecord { Data = values, Ts = timestamp }; DataRecords.Add(dr); }