Simplified setup & improved error handling

This commit is contained in:
2016-03-19 21:25:28 +01:00
parent 2ee1087268
commit afa973306d
78 changed files with 1881 additions and 510 deletions
@@ -4,7 +4,7 @@
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// Copyright (c) 2013-2016 Carsten Sonne Larsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -25,13 +25,14 @@
// THE SOFTWARE.
using System;
using System.Linq;
using Ntp.Process;
using Ntp.Analyzer.Log;
using System.Net;
using Ntp.Analyzer.Config.Stats;
using Ntp.Analyzer.Data;
using Ntp.Analyzer.Data.Live;
using Ntp.Analyzer.Log;
using Ntp.Analyzer.Objects;
using Ntp.Analyzer.Objects.Live;
using Ntp.Process;
namespace Ntp.Analyzer.Process.Description
{
@@ -59,14 +60,19 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute ()
{
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Name == config.ServerName);
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
if (host == null) {
Log.WriteLine ("Hostname not found in database: " + config.ServerName, Severity.Warn);
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
IOStatsLiveMapper liveMapper = new IOStatsLiveMapper (new ServerName (config.ServerName));
IOStatsMapper liveMapper = new IOStatsMapper (
new ServerName (config.ServerName),
config.ServerType == ServerType.Ntpq,
Log);
foreach (IOStatsEntry entry in liveMapper) {
HostIOReading reading = new HostIOReading (host, entry, ReadingBulk.Current);
@@ -74,4 +80,4 @@ namespace Ntp.Analyzer.Process.Description
}
}
}
}
}
@@ -4,7 +4,7 @@
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// Copyright (c) 2013-2016 Carsten Sonne Larsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -25,12 +25,13 @@
// THE SOFTWARE.
using System;
using System.Linq;
using System.Net;
using Ntp.Analyzer.Config.Stats;
using Ntp.Analyzer.Data;
using Ntp.Analyzer.Data.Live;
using Ntp.Analyzer.Log;
using Ntp.Analyzer.Objects;
using Ntp.Process;
using Ntp.Analyzer.Data.Live;
namespace Ntp.Analyzer.Process.Description
{
@@ -61,17 +62,21 @@ namespace Ntp.Analyzer.Process.Description
protected override void InternalExecute ()
{
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Name == config.ServerName);
Host host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
if (host == null) {
Log.WriteLine ("Hostname not found in database: " + config.ServerName, Severity.Warn);
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
return;
}
NtpdcImporter imp;
HostValueImporter imp;
try {
// Import from NTP daemon
imp = new NtpdcImporter (host, ReadingBulk.Current);
imp = config.ServerType == ServerType.Ntpdc ?
(HostValueImporter)(new NtpdcImporter (config.ServerName, host, ReadingBulk.Current, Log)) :
(HostValueImporter)(new NtpqHostImporter (config.ServerName, host, ReadingBulk.Current, Log));
imp.Import ();
} catch (Exception e) {
Log.WriteLine ("Could not get data from NTP daemon: " + e.Message, Severity.Warn);
@@ -98,7 +98,7 @@ namespace Ntp.Analyzer.Process.Description
else
peerPageBuilder = new DefaultPeerPageBuilder(peer, page);
SaveStream(peerPageBuilder, peer.OrgId.ToString(CultureInfo.InvariantCulture) + ".html");
SaveStream(peerPageBuilder, peer.OrgId.Value.ToString(CultureInfo.InvariantCulture) + ".html");
}
}
}
+43 -37
View File
@@ -4,7 +4,7 @@
// Author:
// Carsten Sonne Larsen <cs@innolan.dk>
//
// Copyright (c) 2013 Carsten Sonne Larsen
// Copyright (c) 2013-2016 Carsten Sonne Larsen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -26,12 +26,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Ntp.Analyzer.Config.Stats;
using Ntp.Analyzer.Data;
using Ntp.Analyzer.Log;
using Ntp.Analyzer.Objects;
using Ntp.Process;
using Ntp.Analyzer.Objects.Live;
using Ntp.Process;
namespace Ntp.Analyzer.Process.Description
{
@@ -40,17 +41,18 @@ namespace Ntp.Analyzer.Process.Description
/// </summary>
public sealed class PeerStatJob : JobDescription
{
private readonly PeerStatConfiguration config;
private Host host;
private List<Peer> peers;
private List<PeerReading> readings;
public PeerStatJob (PeerStatConfiguration config, LogBase log)
public PeerStatJob (PeerStatConfiguration config, LogBase log)
: base(config, log)
{
this.config = config;
this.readings = new List<PeerReading> ();
}
private readonly PeerStatConfiguration config;
private readonly List<PeerReading> readings;
private Host host;
private List<Peer> peers;
public override bool SingleThread {
get { return false; }
}
@@ -80,34 +82,24 @@ namespace Ntp.Analyzer.Process.Description
/// </summary>
private void Initalize ()
{
// Clear any previouse readings
readings.Clear();
// Get peers from database.
peers = DataFace.Instance.Peers.ToList ();
// Find host in database.
try {
host = DataFace.Instance.Hosts.Single (h => h.Name == config.ServerName);
} catch (Exception e) {
Log.WriteLine ("Hostname not found in database: " + config.ServerName, Severity.Warn);
Log.WriteLine (e, Severity.Trace);
return;
}
host = DataFace.Instance.Hosts.SingleOrDefault (h => h.Id == config.HostId);
// Prepare result.
readings = new List<PeerReading> ();
}
/// <summary>
/// Saves the result of the import to database.
/// </summary>
private void SaveResult ()
{
foreach (PeerReading reading in readings) {
DataFace.Instance.PeerReadings.Save (reading);
if (host == null) {
Log.WriteLine (String.Format (
"Host with ID {0} was not found in database. ", config.HostId),
Severity.Warn);
}
}
/// <summary>
/// Import statistics using the ntpq utility.
/// Import statistics.
/// </summary>
private void Import ()
{
@@ -120,25 +112,39 @@ namespace Ntp.Analyzer.Process.Description
if (peerList.Count () == 1) {
peer = peerList.Single ();
} else if (peerList.Count () == 0) {
Log.WriteLine ("Peer not found in database: " + entry.Remote, Severity.Warn);
Log.WriteLine (String.Format (
"Peer with IP {0} was not found in database.", entry.Remote),
Severity.Warn);
continue;
} else {
Log.WriteLine ("Unexpected number of peers match from database: " + peerList.Count (), Severity.Warn);
Log.WriteLine (String.Format (
"Found more than on peer with IP {0} in database.", entry.Remote),
Severity.Warn);
continue;
}
PeerReading reading = new PeerReading (
host,
peer,
ReadingBulk.Current,
entry.LastPoll,
entry.Reach,
entry.Delay,
entry.Offset,
entry.Jitter);
host,
peer,
ReadingBulk.Current,
entry.LastPoll,
entry.Reach,
entry.Delay,
entry.Offset,
entry.Jitter);
readings.Add (reading);
}
}
/// <summary>
/// Saves the result of the import to database.
/// </summary>
private void SaveResult ()
{
foreach (PeerReading reading in readings) {
DataFace.Instance.PeerReadings.Save (reading);
}
}
}
}