예제 #1
0
        public void SaveMetric(Metric_ metric, Measure_[] measures)
        {
            const string updateMetric = @"
UPDATE mon.""Metric"" SET
    ""Name"" = @Name
    ,""InstanceID"" = @InstanceID
    ,""Aggregation"" = @Aggregation
    
    ,""RangeHeadID"" = @RangeHeadID
    ,""RangeTailID"" = @RangeTailID
    
    ,""ActualInterval"" = @ActualInterval
    ,""ActualID"" = @ActualID
WHERE ""ID"" = @ID
";

            const string updateMeasure = @"
UPDATE mon.""Measure"" SET
    ""Value"" = @Value
WHERE ""ID"" = @ID
";

            using (var con = Connection)
            {
                con.Execute(updateMetric, metric);
                con.Execute(updateMeasure, measures);
            }
        }
예제 #2
0
        public void SaveMetric(Metric_ metric, Measure_[] measures)
        {
            const string updateMetric = @"
UPDATE [mon].[Metric] SET
    Name = @Name
    ,InstanceID = @InstanceID
    ,Aggregation = @Aggregation
    
    ,RangeHeadID = @RangeHeadID
    ,RangeTailID = @RangeTailID
    
    ,ActualInterval = @ActualInterval
    ,ActualID = @ActualID
WHERE ID = @ID
";

            const string updateMeasure = @"
UPDATE [mon].[Measure] SET
    Value = @Value
WHERE ID = @ID
";

            using (var con = Connection)
            {
                con.Execute(updateMetric, metric);
                con.Execute(updateMeasure, measures);
            }
        }
예제 #3
0
        public MetricObject(IMonik monik, IRepository repository, IMessagePump pump)
        {
            _monik      = monik;
            _repository = repository;
            _pump       = pump;

            _dto      = null;
            _measures = null;

            window = null;
        }
예제 #4
0
        public Metric_ CreateMetric(string name, int aggregation, int instanceId)
        {
            const string insertMeasures = @"
insert into mon.""Measure"" (""Value"")
select 0
from generate_series(1, @Count)
returning ""ID"";
";
            const string insertMetric   = @"
insert into mon.""Metric""
(""Name"", ""InstanceID"", ""Aggregation"", ""RangeHeadID"", ""RangeTailID"", ""ActualInterval"", ""ActualID"")
values
(@Name, @InstanceID, @Aggregation, @RangeHeadID, @RangeTailID, @ActualInterval, @ActualID)
returning ""ID""
";

            using (var con = Connection)
            {
                con.Open();

                long[] ids;
                using (var tran = con.BeginTransaction())
                {
                    con.Execute("select pg_advisory_lock(@LockId);",
                                new { LockId = MeasuresCreationLockId }, tran);
                    ids = con
                          .Query <long>(insertMeasures, new { Count = MeasuresPerMetric }, tran)
                          .ToArray();
                    con.Execute("select pg_advisory_unlock(@LockId);",
                                new { LockId = MeasuresCreationLockId }, tran);
                    tran.Commit();
                }

                var lastId  = ids.Last();
                var firstId = ids.First();
                var met     = new Metric_
                {
                    Name        = name,
                    Aggregation = aggregation,
                    InstanceID  = instanceId,

                    RangeHeadID = firstId,
                    RangeTailID = lastId,

                    ActualInterval = DateTime.UtcNow.RoundUp(TimeSpan.FromMinutes(5)),
                    ActualID       = firstId
                };
                met.ID = con.ExecuteScalar <int>(insertMetric, met);
                return(met);
            }
        }
예제 #5
0
        public Metric_ CreateMetric(string name, int aggregation, int instanceId)
        {
            const string insertMeasures = @"
begin transaction;

EXEC sp_getapplock @Resource = '[mon].[Measure]', @LockMode = 'Exclusive';  

declare @i int = 1;
while (@i <= @Count)
begin
     insert into [mon].[Measure] ([Value]) values (0)
     set @i = @i + 1
end
;select SCOPE_IDENTITY() id

commit transaction;
";
            const string insertMetric   = @"
insert into [mon].[Metric]
([Name], [InstanceID], [Aggregation], [RangeHeadID], [RangeTailID], [ActualInterval], [ActualID])
VALUES
(@Name, @InstanceID, @Aggregation, @RangeHeadID, @RangeTailID, @ActualInterval, @ActualID)
;select SCOPE_IDENTITY() id    
";

            using (var con = Connection)
            {
                var lastId  = con.ExecuteScalar <long>(insertMeasures, new { Count = MeasuresPerMetric });
                var firstId = lastId - MeasuresPerMetric + 1;
                var met     = new Metric_
                {
                    Name        = name,
                    Aggregation = aggregation,
                    InstanceID  = instanceId,

                    RangeHeadID = firstId,
                    RangeTailID = lastId,

                    ActualInterval = DateTime.UtcNow.RoundUp(TimeSpan.FromMinutes(5)),
                    ActualID       = firstId
                };
                met.ID = con.ExecuteScalar <int>(insertMetric, met);
                return(met);
            }
        }
예제 #6
0
 public void Load(Metric_ metric, Measure_[] measures)
 {
     _dto      = metric;
     _measures = measures;
 }
예제 #7
0
 public void CreateNew(string name, int aggregation, Instance instance)
 {
     _dto      = _repository.CreateMetric(name, aggregation, instance.ID);
     _measures = _repository.GetMeasures(_dto.ID);
 }