Skip to content

Commit 42dc7ee

Browse files
committed
add support for 'graph_total' attribute
1 parent 1b8715f commit 42dc7ee

File tree

2 files changed

+91
-5
lines changed

2 files changed

+91
-5
lines changed

src/Smdn.Net.MuninNode/Smdn.Net.MuninPlugin/PluginGraphAttributes.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public sealed class PluginGraphAttributes : IPluginGraphAttributes {
5252
/// <seealso href="https://guide.munin-monitoring.org/en/latest/reference/plugin.html#graph-order">Plugin reference - Global attributes - graph_order</seealso>
5353
public string? Order { get; }
5454

55+
/// <summary>Gets a value for the <c>graph_total</c>.</summary>
56+
/// <seealso href="https://guide.munin-monitoring.org/en/latest/reference/plugin.html#graph-total">Plugin reference - Global attributes - graph_total</seealso>
57+
public string? TotalValueLabel { get; }
58+
5559
public PluginGraphAttributes(
5660
string title,
5761
string category,
@@ -68,7 +72,8 @@ string arguments
6872
updateRate: null,
6973
width: null,
7074
height: null,
71-
order: null
75+
order: null,
76+
totalValueLabel: null
7277
)
7378
{
7479
}
@@ -82,7 +87,8 @@ public PluginGraphAttributes(
8287
TimeSpan? updateRate,
8388
int? width,
8489
int? height,
85-
IEnumerable<string>? order
90+
IEnumerable<string>? order,
91+
string? totalValueLabel
8692
)
8793
{
8894
if (title == null)
@@ -114,6 +120,7 @@ public PluginGraphAttributes(
114120
Width = width;
115121
Height = height;
116122
Order = order is null ? null : string.Join(" ", order);
123+
TotalValueLabel = totalValueLabel;
117124

118125
if (updateRate.HasValue && updateRate.Value < TimeSpan.FromSeconds(1.0))
119126
throw new ArgumentOutOfRangeException(nameof(updateRate), updateRate, "must be at least 1 seconds");
@@ -137,5 +144,7 @@ public IEnumerable<string> EnumerateAttributes()
137144
yield return $"graph_height {Height.Value}";
138145
if (!string.IsNullOrEmpty(Order))
139146
yield return $"graph_order {Order}";
147+
if (!string.IsNullOrEmpty(TotalValueLabel))
148+
yield return $"graph_total {TotalValueLabel}";
140149
}
141150
}

tests/Smdn.Net.MuninNode/Smdn.Net.MuninNode/NodeBase.cs

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,8 @@ private static System.Collections.IEnumerable YieldTestCases_ProcessCommandAsync
774774
updateRate: null,
775775
width: width,
776776
height: height,
777-
order: null
777+
order: null,
778+
totalValueLabel: null
778779
);
779780

780781
var plugin = PluginFactory.CreatePlugin(
@@ -817,7 +818,8 @@ private static System.Collections.IEnumerable YieldTestCases_ProcessCommandAsync
817818
updateRate: updateRate,
818819
width: null,
819820
height: null,
820-
order: null
821+
order: null,
822+
totalValueLabel: null
821823
);
822824

823825
var plugin = PluginFactory.CreatePlugin(
@@ -890,7 +892,8 @@ private static System.Collections.IEnumerable YieldTestCases_ProcessCommandAsync
890892
updateRate: TimeSpan.FromMinutes(1),
891893
width: null,
892894
height: null,
893-
order: order
895+
order: order,
896+
totalValueLabel: null
894897
);
895898

896899
var plugin = PluginFactory.CreatePlugin(
@@ -947,6 +950,80 @@ await StartSession(
947950
);
948951
}
949952

953+
private static System.Collections.IEnumerable YieldTestCases_ProcessCommandAsync_ConfigCommand_GraphTotal()
954+
{
955+
foreach (var total in new[] {
956+
null,
957+
string.Empty,
958+
"Total",
959+
}) {
960+
var graphAttrs = new PluginGraphAttributes(
961+
title: "title",
962+
category: "test",
963+
verticalLabel: "test",
964+
scale: false,
965+
arguments: "--args",
966+
updateRate: TimeSpan.FromMinutes(1),
967+
width: null,
968+
height: null,
969+
order: null,
970+
totalValueLabel: total
971+
);
972+
973+
var plugin = PluginFactory.CreatePlugin(
974+
"plugin1",
975+
graphAttrs,
976+
new[] {
977+
PluginFactory.CreateField("plugin1field1", static () => 1.1),
978+
PluginFactory.CreateField("plugin1field2", PluginFieldGraphStyle.LineWidth3, static () => 1.2)
979+
}
980+
);
981+
982+
yield return new object[] {
983+
plugin,
984+
new Action<IReadOnlyList<string>>(
985+
responseLines => {
986+
if (string.IsNullOrEmpty(total))
987+
Assert.That(responseLines, Has.No.Member("graph_total "), "graph_total");
988+
else
989+
Assert.That(responseLines, Has.Member($"graph_total {total}"), "graph_total");
990+
}
991+
)
992+
};
993+
}
994+
}
995+
996+
[TestCaseSource(nameof(YieldTestCases_ProcessCommandAsync_ConfigCommand_GraphTotal))]
997+
public async Task ProcessCommandAsync_ConfigCommand_GraphTotal(
998+
IPlugin plugin,
999+
Action<IReadOnlyList<string>> assertResponseLines
1000+
)
1001+
{
1002+
await StartSession(
1003+
plugins: new[] { plugin },
1004+
action: async (node, client, writer, reader, cancellationToken) => {
1005+
await writer.WriteLineAsync($"config {plugin.Name}", cancellationToken);
1006+
await writer.FlushAsync(cancellationToken);
1007+
1008+
var lines = new List<string>();
1009+
1010+
for (; ; ) {
1011+
var line = await reader.ReadLineAsync(cancellationToken);
1012+
1013+
if (line is null)
1014+
break;
1015+
1016+
lines.Add(line);
1017+
1018+
if (line == ".")
1019+
break;
1020+
}
1021+
1022+
assertResponseLines(lines);
1023+
}
1024+
);
1025+
}
1026+
9501027
[TestCase(PluginFieldGraphStyle.Default, null, null)]
9511028
[TestCase(PluginFieldGraphStyle.Area, "AREA", null)]
9521029
[TestCase(PluginFieldGraphStyle.Stack, "STACK", null)]

0 commit comments

Comments
 (0)