mirror of
https://bitbucket.org/anguist/ntpa
synced 2025-11-23 12:00:07 +00:00
Drift file statistics
This commit is contained in:
@ -86,6 +86,12 @@ namespace Ntp.Analyzer.Data
|
||||
/// <value>The peer readings.</value>
|
||||
public PeerReadingDatabaseMapper PeerReadings => new PeerReadingDatabaseMapper(Hosts, Peers, log);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the host drift reading mapper.
|
||||
/// </summary>
|
||||
/// <value>The host drift reading mapper.</value>
|
||||
public DriftReadingDatabaseMapper DriftReadings => new DriftReadingDatabaseMapper(Hosts, log);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the peer activity mapper.
|
||||
/// </summary>
|
||||
|
||||
@ -87,6 +87,7 @@ namespace Ntp.Analyzer.Data
|
||||
initializers.Add(new HostReadingDatabaseMapper(hostMapper, peerMapper, log));
|
||||
initializers.Add(new PeerReadingDatabaseMapper(hostMapper, peerMapper, log));
|
||||
initializers.Add(new HostIoReadingDatabaseMapper(hostMapper, log));
|
||||
initializers.Add(new DriftReadingDatabaseMapper(hostMapper, log));
|
||||
initializers.Add(new PeerActivityDatabaseMapper(hostMapper, peerMapper, log));
|
||||
initializers.Add(new AssociationEntryMapper(log));
|
||||
|
||||
|
||||
@ -41,6 +41,7 @@
|
||||
<Compile Include="Import\TimeServerImporter.cs" />
|
||||
<Compile Include="Import\TimeServerLoader.cs" />
|
||||
<Compile Include="Log\LogExtensions.cs" />
|
||||
<Compile Include="Sql\DriftReadingDatabaseMapper.cs" />
|
||||
<Compile Include="Sql\HostDatabaseMapper.cs" />
|
||||
<Compile Include="Sql\HostReadingDatabaseMapper.cs" />
|
||||
<Compile Include="Sql\PeerDatabaseMapper.cs" />
|
||||
|
||||
142
Ntp.Analyzer.Data/Sql/DriftReadingDatabaseMapper.cs
Normal file
142
Ntp.Analyzer.Data/Sql/DriftReadingDatabaseMapper.cs
Normal file
@ -0,0 +1,142 @@
|
||||
//
|
||||
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Ntp.Analyzer.Data.Log;
|
||||
using Ntp.Analyzer.Objects;
|
||||
using Ntp.Common.Log;
|
||||
|
||||
namespace Ntp.Analyzer.Data.Sql
|
||||
{
|
||||
/// <summary>
|
||||
/// ORM mapper for table driftReading.
|
||||
/// </summary>
|
||||
public sealed class DriftReadingDatabaseMapper : FilteredSqlDatabaseMapper<DriftReading>
|
||||
{
|
||||
internal DriftReadingDatabaseMapper(HostDatabaseMapper hostMapper, LogBase log)
|
||||
: base(log)
|
||||
{
|
||||
this.hostMapper = hostMapper;
|
||||
}
|
||||
|
||||
private const string SelectSql =
|
||||
"SELECT " +
|
||||
" id, time, hostId, drift" +
|
||||
" FROM driftReading ";
|
||||
|
||||
private const string InsertSql =
|
||||
"INSERT INTO driftReading (time, hostId, drift) " +
|
||||
"VALUES ( @time, @hostId, @drift );{0};";
|
||||
|
||||
private readonly HostDatabaseMapper hostMapper;
|
||||
|
||||
protected override bool UseCache => false;
|
||||
|
||||
protected override string TableName => "driftReading";
|
||||
|
||||
protected override string CreateSql => "CREATE TABLE driftReading ( " +
|
||||
" id {0} PRIMARY KEY, " +
|
||||
" time TIMESTAMP NOT NULL, " +
|
||||
" hostId INT NOT NULL, " +
|
||||
" drift DOUBLE PRECISION NOT NULL, " +
|
||||
" FOREIGN KEY (hostId) REFERENCES host(id) " +
|
||||
"){1};";
|
||||
|
||||
/// <summary>
|
||||
/// Read all data from table in a sequential manner.
|
||||
/// </summary>
|
||||
/// <returns>The enumerator.</returns>
|
||||
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
|
||||
public override IEnumerator<DriftReading> GetEnumerator()
|
||||
{
|
||||
lock (MapperLocker)
|
||||
{
|
||||
bool error = false;
|
||||
string sql = PrepareSql(SelectSql);
|
||||
|
||||
try
|
||||
{
|
||||
Open();
|
||||
Command.CommandText = sql;
|
||||
Reader = Command.ExecuteReader();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.ReadError(TableName, e);
|
||||
error = true;
|
||||
}
|
||||
|
||||
if (error)
|
||||
yield break;
|
||||
|
||||
while (Reader.Read())
|
||||
{
|
||||
int id = Convert.ToInt32(Reader["id"]);
|
||||
var time = Convert.ToDateTime(Reader["time"]);
|
||||
int hostId = Convert.ToInt32(Reader["hostId"]);
|
||||
var host = hostMapper[hostId];
|
||||
double drift = Convert.ToDouble(Reader["drift"]);
|
||||
yield return new DriftReading(id, time, host, drift, null);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities")]
|
||||
protected override void Insert(DriftReading item)
|
||||
{
|
||||
lock (MapperLocker)
|
||||
{
|
||||
try
|
||||
{
|
||||
Open();
|
||||
Command.CommandText = PrepareInsertSql(InsertSql);
|
||||
Command.Parameters.Add(CreateParameter("@time", item.Time));
|
||||
Command.Parameters.Add(CreateParameter("@hostId", item.Host.Id));
|
||||
Command.Parameters.Add(CreateParameter("@drift", item.Value));
|
||||
var idObject = Command.ExecuteScalar();
|
||||
item.SetId(Convert.ToInt32(idObject));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.InsertError(TableName, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ReadContent()
|
||||
{
|
||||
throw new NotSupportedException(LogMessages.DatabaseCacheError);
|
||||
}
|
||||
|
||||
protected override void Update(DriftReading item)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(LogMessages.DatabaseNoUpdate, TableName));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user