Repository navigation
Expand file tree
/
Copy pathHAProxyModule.cs
More file actions
63 lines (57 loc) · 2.31 KB
/
Copy pathHAProxyModule.cs
File metadata and controls
63 lines (57 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;
using StackExchange.Profiling;
namespace Opserver.Data.HAProxy
{
public class HAProxyModule : StatusModule<HAProxySettings>
{
public override string Name => "HAProxy";
public override bool Enabled => Groups.Count > 0;
public List<HAProxyGroup> Groups { get; }
public HAProxyAdmin Admin { get; }
public HAProxyModule(IConfiguration config, PollingService poller) : base(config, poller)
{
var snapshot = Settings;
Groups = snapshot.Groups.Select(g => new HAProxyGroup(this, g))
.Union(snapshot.Instances.Select(c => new HAProxyGroup(this, c)))
.ToList();
Admin = new HAProxyAdmin(this);
}
public override MonitorStatus MonitorStatus => Groups.GetWorstStatus();
public override bool IsMember(string node)
{
//TODO: Get/Store Host IPs from config, compare to instance passed in
// Or based on data provider metrics, e.g. in Bosun with identifiers, hmmmm
return false;
}
/// <summary>
/// Gets the HAProxy instance with the given name, null if it doesn't exist
/// </summary>
/// <param name="name">The name of the <see cref="HAProxyGroup"/> to fetch.</param>
public HAProxyGroup GetGroup(string name)
{
return Groups.Find(e => string.Equals(e.Name, name, StringComparison.InvariantCultureIgnoreCase));
}
/// <summary>
/// Gets the list of proxies from HAProxy
/// </summary>
public List<Proxy> GetAllProxies()
{
if (!Enabled) return new List<Proxy>();
var instances = Groups.SelectMany(g => g.Instances).ToList();
return GetProxies(instances);
}
internal static List<Proxy> GetProxies(List<HAProxyInstance> instances)
{
using (MiniProfiler.Current.Step("HAProxy - GetProxies()"))
{
return instances.AsParallel().SelectMany(i => i.Proxies.Data ?? Enumerable.Empty<Proxy>())
.Where(p => p != null)
.OrderBy(p => instances.IndexOf(p.Instance))
.ToList();
}
}
}
}