@@ -154,6 +154,39 @@ func transformEventDelayMetric(delayMetric *io_prometheus_client.MetricFamily, d
154
154
delayMetric .Type = io_prometheus_client .MetricType_GAUGE .Enum ()
155
155
}
156
156
157
+ // Workaround for a bug in older syslog-ng/AxoSyslog versions where the output of STATS PROMETHEUS was overescaped.
158
+ // Escapes \ as \\ everywhere except for the allowed sequences: \\, \n, \"
159
+ func sanitizeBuggyFormat (output string ) string {
160
+ var fixedOutput strings.Builder
161
+
162
+ length := len (output )
163
+ for i := 0 ; i < length ; i ++ {
164
+ c := output [i ]
165
+
166
+ if c != '\\' {
167
+ fixedOutput .WriteByte (c )
168
+ continue
169
+ }
170
+
171
+ if i + 1 >= length {
172
+ fixedOutput .WriteString ("\\ \\ " )
173
+ break
174
+ }
175
+
176
+ next := output [i + 1 ]
177
+ if next == '\\' || next == 'n' || next == '"' {
178
+ fixedOutput .WriteByte (c )
179
+ fixedOutput .WriteByte (next )
180
+ i ++
181
+ continue
182
+ }
183
+
184
+ fixedOutput .WriteString ("\\ \\ " )
185
+ }
186
+
187
+ return fixedOutput .String ()
188
+ }
189
+
157
190
func StatsPrometheus (ctx context.Context , cc ControlChannel , lastMetricQueryTime * time.Time ) ([]* io_prometheus_client.MetricFamily , error ) {
158
191
rsp , err := cc .SendCommand (ctx , "STATS PROMETHEUS" )
159
192
if err != nil {
@@ -169,6 +202,7 @@ func StatsPrometheus(ctx context.Context, cc ControlChannel, lastMetricQueryTime
169
202
return maps .Values (mfs ), err
170
203
}
171
204
205
+ rsp = sanitizeBuggyFormat (rsp )
172
206
mfs , err = new (expfmt.TextParser ).TextToMetricFamilies (strings .NewReader (rsp ))
173
207
174
208
var delayMetric * io_prometheus_client.MetricFamily
0 commit comments