It's been a long time since I've started using Opserver - a monitoring system by the team at Stack Exchange. Opserver gives you a great overview of what's going on with your company's infrastructure, I am still really amazed by it's simplicity and the feature set.
Unfortunately, there is no "wallboard" mode in it, which could be used to show most important metrics at a single screen. So today I'll show how to use OpServer as an API for SolarWinds, and build DevOps dashboards in minutes, simply by accessing existing classes.
In brief, all you need to access SolarWinds data from your app is to:
- Add references to Opserver and Opserver.Core
- Add required sections to the App.config file
- Place /Config folder to the output folder.
The step #1 is self-explanatory, so I'll start from #2 - just add the following lines after the opening <configuration> section:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configSections> | |
<section name="Settings" type="StackExchange.Opserver.SettingsSection, StackExchange.Opserver.Core" /> | |
<section name="SecuritySettings" type="StackExchange.Opserver.SecuritySettings, StackExchange.Opserver.Core" /> | |
<section name="Exceptional" type="StackExchange.Exceptional.Settings, StackExchange.Opserver.Core" /> | |
</configSections> | |
<SecuritySettings configSource="Config\SecuritySettings.config" /> | |
<Settings name="JSON" provider="JSONFile" path="~\Config\" /> | |
<Exceptional applicationName="Status"> | |
<ErrorStore type="Memory" /> | |
</Exceptional> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"providers": [ | |
{ | |
"name": "Orion", | |
"type": "Orion", | |
"host": "monitorXd1:8686", | |
"connectionString": "Data Source=monitorXd1;Initial Catalog=SolarWindsOrion;User ID='SolarWindsOrionDatabaseUser';Password='put the password here';Timeout=10" | |
} | |
] |
var allNodes = DashboardData.AllNodes.Where(s => !s.IsUnwatched).Where(s => s.CPULoad >= 0 || s.MemoryUsed >= 0).ToList();
I've pushed sample project to GitHub, it contains simple console app which outputs the following:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var allNodes = DashboardData.AllNodes.Where(s => !s.IsUnwatched).Where(s => s.CPULoad >= 0 || s.MemoryUsed >= 0).ToList(); | |
var downNodes = allNodes.Where(x => x.Status == NodeStatus.Down); | |
Thread.Sleep(3000); | |
float inBps = 0; | |
float outBps = 0; | |
var totalRam = 0.0; | |
var totalDisk = 0.0; | |
foreach (var node in allNodes) | |
{ | |
// Let's get the metrics from VM hosts only | |
if (!node.IsVMHost) | |
{ | |
continue; | |
} | |
foreach (var i in node.PrimaryInterfaces) | |
{ | |
inBps += i.InBps.HasValue ? i.InBps.Value : 0; | |
outBps += i.OutBps.HasValue ? i.OutBps.Value : 0; | |
} | |
totalRam += node.TotalMemory.HasValue ? node.TotalMemory.Value : 0; | |
totalDisk += node.Volumes.Sum(volume => volume.Size.HasValue ? volume.Size.Value : 0); | |
} | |
inBps = inBps / 1024 / 1024; | |
outBps = outBps / 1024 / 1024; | |
totalRam = totalRam / 1024 / 1024 / 1024; | |
totalDisk = totalDisk / 1024 / 1024 / 1024; | |
Console.WriteLine(string.Format("You have {0} servers", allNodes.Count())); | |
Console.WriteLine(string.Format("{0} of them are down", downNodes.Count())); | |
Console.WriteLine(string.Format("Network Upload: {0:0.00} MB", inBps)); | |
Console.WriteLine(string.Format("Network Download: {0:0.00} MB", outBps)); | |
Console.WriteLine(string.Format("Total RAM: {0:0.00} GB", totalRam)); | |
Console.WriteLine(string.Format("Total HDD: {0:0.00} GB", totalDisk)); | |
You can also output active alerts and many other things. If you come up with some interesting ideas - please share them!
No comments:
Post a Comment