Hello again,
I need your professional help on adding ascx file with codebehind as custom ressources for NetPerMon.
this is the code that i pulled from this thread Custom Graphing: Fun With Highcharts - Forum - Network Performance Monitor (NPM) - THWACK (solarwinds.com) by @wluther
<%@ Control Language="C#" ClassName="MemoryUseWindows24" Inherits="SolarWinds.Orion.Web.UI.BaseResourceControl" %>
<%@ Import Namespace="SolarWinds.Orion.Common" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<%@ import namespace="Newtonsoft.Json" %>
<%@ import namespace="System.IO" %>
protected override string DefaultTitle
{
get { return "Memory Use Last 24"; }
}
public void Page_Load()
{
string NetObject = Request.Params["NetObject"];
string NodeID = NetObject.TrimStart('N', ':');
string query = @SELECT DATEPART(YEAR,DateTime)as Year,
DATEPART(MONTH,DateTime)as Month,
DATEPART(DAY,DateTime)as Day,
DATEPART(HOUR,DateTime)as Hour,
DATEPART(MINUTE,DateTime)as Minute,
DATEPART(SECOND,DateTime)as Second,
AvgPercentMemoryUsed
FROM CPULoad
WHERE DateTime >= DATEADD( d, -1, GETDATE() ) AND DateTime < GETDATE()
AND NodeID = " + NodeID +
" ORDER BY DateTime";
using (System.Data.SqlClient.SqlCommand command = SqlHelper.GetTextCommand(query))
{
grid.DataSource = SqlHelper.ExecuteDataTable(command);
DataTable tblResourceProperties = SqlHelper.ExecuteDataTable(command);
List SeriesList = new List();
foreach (DataRow row in tblResourceProperties.Rows)
{
object measurement = row["AvgPercentMemoryUsed"];
int measurementint = Convert.ToInt32(measurement);
SeriesList.Add(measurementint);
}
string JSONresult;
JSONresult = JsonConvert.SerializeObject(tblResourceProperties);
string[] dataseries;
string output = JsonConvert.SerializeObject(SeriesList);
//lblText.Text = JSONresult;
string path = @c:\inetpub\SolarWinds\Orion\OrionImprovement\JSON\Mem24Data.txt;
File.WriteAllText(path, JSONresult);
}
//grid.DataBind();
}
$.ajax({
async: true,
url: '/Orion/OrionImprovement/JSON/Mem24Data.txt',
type: 'GET',
cache: false,
dataype: 'json',
success: function (data)
{
//Create data object from input file. Object is a JSON construct, so not an array or anything useful yet.
//Orion appends a footer to http://.../GraphData.js so cut it off by stopping when we hit the '/' character.
var sqlobject = "";
$.each(data, function(key, value)
{
if (value === "/") {return false;}
sqlobject = sqlobject.concat(value);
})
//console.log(sqlobject);
var book = JSON.parse(sqlobject);
timearray = [];
for (var page in book)
{
var datapoint = [];
var onepage = book[page];
var words = Object.keys(onepage);
var datetime = Date.UTC( onepage[words[0]],
onepage[words[1]] - 1,
onepage[words[2]],
onepage[words[3]],
onepage[words[4]],
onepage[words[5]]);
datapoint[0] = datetime;
datapoint[1] = onepage[words[6]];
//console.log(datapoint);
timearray.push(datapoint);
}
console.log(timearray);
//x-axis categories gets nodename because graphs with no categories are squished to the middle third of the graph.
//highcharts 'series' requires an array in an object in an array. [{[]}].
//Only one series, so we hardcode array, and send it an array of objects: nodeid and measure.
//Highcharts parameters.
Highcharts.chart('MemoryUseWindows24',
{
chart: {type: 'area',
height: 150,
width: 1400},
legend: {enabled: false},
plotOptions: {series: {marker: {symbol: 'circle',
radius: 1
}
}
},
title: {text: null},
tooltip: {pointFormat: '{point.y:,.0f}% Memory Used'},
xAxis: {type: 'datetime'},
yAxis: {
ceiling: 100,
title: {
text: 'Percent'
}
},
series: [{data: timearray}]
});
}
});
adding the ressources as he says works perfectly but since i am not a big fan of inline code i am trying to transforme it to codebehind one so i am ending with those code
1- The ascx file:
<%@ Control Language="C#" ClassName="MemoryUseWindows" codeFile="MemoryUseWindows.ascx.cs" Inherits="Orion_NetPerfMon_Resources_Misc_MemoryUseWindows" %>
<%--<%@ Control Language="C#" ClassName="MemoryUseWindows" Inherits="SolarWinds.Orion.Web.UI.BaseResourceControl" %>
<%@ Import Namespace="SolarWinds.Orion.Common" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>
<%@ import namespace="Newtonsoft.Json" %>
<%@ import namespace="System.IO" %>--%>
<%--<script runat="server">
protected override string DefaultTitle
{
get { return "Memory Use "; }
}
public void Page_Load()
{
string NetObject = Request.Params["NetObject"];
string NodeID = NetObject.TrimStart('N', ':');
string query = @SELECT DATEPART(YEAR,DateTime)as Year,
DATEPART(MONTH,DateTime)as Month,
DATEPART(DAY,DateTime)as Day,
DATEPART(HOUR,DateTime)as Hour,
DATEPART(MINUTE,DateTime)as Minute,
DATEPART(SECOND,DateTime)as Second,
AvgPercentMemoryUsed
FROM CPULoad
WHERE DateTime >= DATEADD( d, -1, GETDATE() ) AND DateTime < GETDATE()
AND NodeID = " + NodeID +
" ORDER BY DateTime";
using (System.Data.SqlClient.SqlCommand command = SqlHelper.GetTextCommand(query))
{
grid.DataSource = SqlHelper.ExecuteDataTable(command);
DataTable tblResourceProperties = SqlHelper.ExecuteDataTable(command);
List SeriesList = new List();
foreach (DataRow row in tblResourceProperties.Rows)
{
object measurement = row["AvgPercentMemoryUsed"];
int measurementint = Convert.ToInt32(measurement);
SeriesList.Add(measurementint);
}
string JSONresult;
JSONresult = JsonConvert.SerializeObject(tblResourceProperties);
string[] dataseries;
string output = JsonConvert.SerializeObject(SeriesList);
//lblText.Text = JSONresult;
string path = @c:\inetpub\SolarWinds\Orion\OrionImprovement\JSON\Mem24Data.txt;
File.WriteAllText(path, JSONresult);
}
//grid.DataBind();
}
--%>
$.ajax({
async: true,
url: '/Orion/OrionImprovement/JSON/Mem24Data.txt',
type: 'GET',
cache: false,
dataype: 'json',
success: function (data)
{
//Create data object from input file. Object is a JSON construct, so not an array or anything useful yet.
//Orion appends a footer to http://.../GraphData.js so cut it off by stopping when we hit the '/' character.
var sqlobject = "";
$.each(data, function(key, value)
{
if (value === "/") {return false;}
sqlobject = sqlobject.concat(value);
})
//console.log(sqlobject);
var book = JSON.parse(sqlobject);
timearray = [];
for (var page in book)
{
var datapoint = [];
var onepage = book[page];
var words = Object.keys(onepage);
var datetime = Date.UTC( onepage[words[0]],
onepage[words[1]] - 1,
onepage[words[2]],
onepage[words[3]],
onepage[words[4]],
onepage[words[5]]);
datapoint[0] = datetime;
datapoint[1] = onepage[words[6]];
//console.log(datapoint);
timearray.push(datapoint);
}
console.log(timearray);
//x-axis categories gets nodename because graphs with no categories are squished to the middle third of the graph.
//highcharts 'series' requires an array in an object in an array. [{[]}].
//Only one series, so we hardcode array, and send it an array of objects: nodeid and measure.
//Highcharts parameters.
Highcharts.chart('MemoryUseWindows',
{
chart: {type: 'area',
height: 150,
width: 1400},
legend: {enabled: false},
plotOptions: {series: {marker: {symbol: 'circle',
radius: 1
}
}
},
title: {text: null},
tooltip: {pointFormat: '{point.y:,.0f}% Memory Used'},
xAxis: {type: 'datetime'},
yAxis: {
ceiling: 100,
title: {
text: 'Percent'
}
},
series: [{data: timearray}]
});
}
});
2-the ascx.cs file:
using System;
using Newtonsoft.Json.Linq;
using OrionSwis;
public partial class Orion_NetPerfMon_Resources_Misc_MemoryUseWindows : SolarWinds.Orion.Web.UI.BaseResourceControl
{
private const string host = "localhost:17778";
private const string user = "admin";
private const string pass = "admin";
protected override string DefaultTitle
{
get { return "Memory Use Last 24 hours"; }
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
var swisClient = new SwisClient(host, user, pass);
JToken cpuLoad = GetCpuLoad(swisClient);
//lblText.Text = cpuLoad.ToString();
}
catch(Exception )
{
}
}
private JToken GetCpuLoad(SwisClient swisClient)
{
string query = @SELECT Year(DateTime) as Year,
Month(DateTime) as Month,
Day(DateTime) as Day,
Hour(DateTime) as Hour,
Minute(DateTime) as Minute,
Second(DateTime) as Second,
AvgPercentMemoryUsed
FROM Orion.CPULoad
WHERE NodeID=1
ORDER BY DateTime";
JToken getResult = swisClient.QueryAsync(query).Result;
return getResult;
}
}
Now trying I am trying to add it as custom ressources like i did before but SolarWind can't find it I know it's possible cause there is some customressources with codebehind in solarwind but i don't find the reason why it isn't loaded so i am asking for help here
Thanks in advance,
kind Regrads