Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.

Commit b886c6e

Browse files
authored
Fix metric types (#182)
* Add support for counter metrics. * Update metrics to correct types. * Fix metric naming conventions for exporter countermetrics. Fixes: #30 Signed-off-by: Ben Kochie <[email protected]>
1 parent db9370a commit b886c6e

11 files changed

+237
-208
lines changed

haproxy_exporter.go

+132-103
Large diffs are not rendered by default.

haproxy_exporter_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ func TestParseStatusField(t *testing.T) {
320320
func TestFilterServerMetrics(t *testing.T) {
321321
tests := []struct {
322322
input string
323-
want map[int]*prometheus.Desc
323+
want map[int]metricInfo
324324
}{
325-
{input: "", want: map[int]*prometheus.Desc{}},
326-
{input: "8", want: map[int]*prometheus.Desc{8: serverMetrics[8]}},
325+
{input: "", want: map[int]metricInfo{}},
326+
{input: "8", want: map[int]metricInfo{8: metricInfo{Desc: serverMetrics[8].Desc, Type: prometheus.CounterValue}}},
327327
{input: serverMetrics.String(), want: serverMetrics},
328328
}
329329

test/deadline.metrics

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# HELP haproxy_exporter_csv_parse_failures Number of errors while parsing CSV.
2-
# TYPE haproxy_exporter_csv_parse_failures counter
3-
haproxy_exporter_csv_parse_failures 0
4-
# HELP haproxy_exporter_total_scrapes Current total HAProxy scrapes.
5-
# TYPE haproxy_exporter_total_scrapes counter
6-
haproxy_exporter_total_scrapes 1
1+
# HELP haproxy_exporter_csv_parse_failures_total Number of errors while parsing CSV.
2+
# TYPE haproxy_exporter_csv_parse_failures_total counter
3+
haproxy_exporter_csv_parse_failures_total 0
4+
# HELP haproxy_exporter_scrapes_total Current total HAProxy scrapes.
5+
# TYPE haproxy_exporter_scrapes_total counter
6+
haproxy_exporter_scrapes_total 1
77
# HELP haproxy_up Was the last scrape of HAProxy successful.
88
# TYPE haproxy_up gauge
99
haproxy_up 0

test/invalid_config.metrics

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# HELP haproxy_exporter_csv_parse_failures Number of errors while parsing CSV.
2-
# TYPE haproxy_exporter_csv_parse_failures counter
3-
haproxy_exporter_csv_parse_failures 1
4-
# HELP haproxy_exporter_total_scrapes Current total HAProxy scrapes.
5-
# TYPE haproxy_exporter_total_scrapes counter
6-
haproxy_exporter_total_scrapes 1
1+
# HELP haproxy_exporter_csv_parse_failures_total Number of errors while parsing CSV.
2+
# TYPE haproxy_exporter_csv_parse_failures_total counter
3+
haproxy_exporter_csv_parse_failures_total 1
4+
# HELP haproxy_exporter_scrapes_total Current total HAProxy scrapes.
5+
# TYPE haproxy_exporter_scrapes_total counter
6+
haproxy_exporter_scrapes_total 1
77
# HELP haproxy_up Was the last scrape of HAProxy successful.
88
# TYPE haproxy_up gauge
99
haproxy_up 1

test/not_found.metrics

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# HELP haproxy_exporter_csv_parse_failures Number of errors while parsing CSV.
2-
# TYPE haproxy_exporter_csv_parse_failures counter
3-
haproxy_exporter_csv_parse_failures 0
4-
# HELP haproxy_exporter_total_scrapes Current total HAProxy scrapes.
5-
# TYPE haproxy_exporter_total_scrapes counter
6-
haproxy_exporter_total_scrapes 1
1+
# HELP haproxy_exporter_csv_parse_failures_total Number of errors while parsing CSV.
2+
# TYPE haproxy_exporter_csv_parse_failures_total counter
3+
haproxy_exporter_csv_parse_failures_total 0
4+
# HELP haproxy_exporter_scrapes_total Current total HAProxy scrapes.
5+
# TYPE haproxy_exporter_scrapes_total counter
6+
haproxy_exporter_scrapes_total 1
77
# HELP haproxy_up Was the last scrape of HAProxy successful.
88
# TYPE haproxy_up gauge
99
haproxy_up 0

test/older_haproxy_versions.metrics

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# HELP haproxy_exporter_csv_parse_failures Number of errors while parsing CSV.
2-
# TYPE haproxy_exporter_csv_parse_failures counter
3-
haproxy_exporter_csv_parse_failures 0
4-
# HELP haproxy_exporter_total_scrapes Current total HAProxy scrapes.
5-
# TYPE haproxy_exporter_total_scrapes counter
6-
haproxy_exporter_total_scrapes 1
1+
# HELP haproxy_exporter_csv_parse_failures_total Number of errors while parsing CSV.
2+
# TYPE haproxy_exporter_csv_parse_failures_total counter
3+
haproxy_exporter_csv_parse_failures_total 0
4+
# HELP haproxy_exporter_scrapes_total Current total HAProxy scrapes.
5+
# TYPE haproxy_exporter_scrapes_total counter
6+
haproxy_exporter_scrapes_total 1
77
# HELP haproxy_server_bytes_in_total Current total of incoming bytes.
8-
# TYPE haproxy_server_bytes_in_total gauge
8+
# TYPE haproxy_server_bytes_in_total counter
99
haproxy_server_bytes_in_total{backend="foo",server="BACKEND"} 0
1010
haproxy_server_bytes_in_total{backend="foo",server="FRONTEND"} 0
1111
haproxy_server_bytes_in_total{backend="foo",server="foo-instance-0"} 0
1212
# HELP haproxy_server_bytes_out_total Current total of outgoing bytes.
13-
# TYPE haproxy_server_bytes_out_total gauge
13+
# TYPE haproxy_server_bytes_out_total counter
1414
haproxy_server_bytes_out_total{backend="foo",server="BACKEND"} 0
1515
haproxy_server_bytes_out_total{backend="foo",server="FRONTEND"} 0
1616
haproxy_server_bytes_out_total{backend="foo",server="foo-instance-0"} 0
1717
# HELP haproxy_server_check_failures_total Total number of failed health checks.
18-
# TYPE haproxy_server_check_failures_total gauge
18+
# TYPE haproxy_server_check_failures_total counter
1919
haproxy_server_check_failures_total{backend="foo",server="BACKEND"} 0
2020
haproxy_server_check_failures_total{backend="foo",server="FRONTEND"} 0
2121
haproxy_server_check_failures_total{backend="foo",server="foo-instance-0"} 0
2222
# HELP haproxy_server_connection_errors_total Total of connection errors.
23-
# TYPE haproxy_server_connection_errors_total gauge
23+
# TYPE haproxy_server_connection_errors_total counter
2424
haproxy_server_connection_errors_total{backend="foo",server="BACKEND"} 0
2525
haproxy_server_connection_errors_total{backend="foo",server="FRONTEND"} 0
2626
haproxy_server_connection_errors_total{backend="foo",server="foo-instance-0"} 0
@@ -35,7 +35,7 @@ haproxy_server_current_sessions{backend="foo",server="BACKEND"} 0
3535
haproxy_server_current_sessions{backend="foo",server="FRONTEND"} 0
3636
haproxy_server_current_sessions{backend="foo",server="foo-instance-0"} 0
3737
# HELP haproxy_server_downtime_seconds_total Total downtime in seconds.
38-
# TYPE haproxy_server_downtime_seconds_total gauge
38+
# TYPE haproxy_server_downtime_seconds_total counter
3939
haproxy_server_downtime_seconds_total{backend="foo",server="BACKEND"} 0
4040
haproxy_server_downtime_seconds_total{backend="foo",server="FRONTEND"} 0
4141
haproxy_server_downtime_seconds_total{backend="foo",server="foo-instance-0"} 0
@@ -50,27 +50,27 @@ haproxy_server_max_sessions{backend="foo",server="BACKEND"} 0
5050
haproxy_server_max_sessions{backend="foo",server="FRONTEND"} 0
5151
haproxy_server_max_sessions{backend="foo",server="foo-instance-0"} 0
5252
# HELP haproxy_server_redispatch_warnings_total Total of redispatch warnings.
53-
# TYPE haproxy_server_redispatch_warnings_total gauge
53+
# TYPE haproxy_server_redispatch_warnings_total counter
5454
haproxy_server_redispatch_warnings_total{backend="foo",server="BACKEND"} 0
5555
haproxy_server_redispatch_warnings_total{backend="foo",server="FRONTEND"} 0
5656
haproxy_server_redispatch_warnings_total{backend="foo",server="foo-instance-0"} 0
5757
# HELP haproxy_server_response_errors_total Total of response errors.
58-
# TYPE haproxy_server_response_errors_total gauge
58+
# TYPE haproxy_server_response_errors_total counter
5959
haproxy_server_response_errors_total{backend="foo",server="BACKEND"} 0
6060
haproxy_server_response_errors_total{backend="foo",server="FRONTEND"} 0
6161
haproxy_server_response_errors_total{backend="foo",server="foo-instance-0"} 0
6262
# HELP haproxy_server_retry_warnings_total Total of retry warnings.
63-
# TYPE haproxy_server_retry_warnings_total gauge
63+
# TYPE haproxy_server_retry_warnings_total counter
6464
haproxy_server_retry_warnings_total{backend="foo",server="BACKEND"} 0
6565
haproxy_server_retry_warnings_total{backend="foo",server="FRONTEND"} 0
6666
haproxy_server_retry_warnings_total{backend="foo",server="foo-instance-0"} 0
6767
# HELP haproxy_server_server_selected_total Total number of times a server was selected, either for new sessions, or when re-dispatching.
68-
# TYPE haproxy_server_server_selected_total gauge
68+
# TYPE haproxy_server_server_selected_total counter
6969
haproxy_server_server_selected_total{backend="foo",server="BACKEND"} 0
7070
haproxy_server_server_selected_total{backend="foo",server="FRONTEND"} 0
7171
haproxy_server_server_selected_total{backend="foo",server="foo-instance-0"} 0
7272
# HELP haproxy_server_sessions_total Total number of sessions.
73-
# TYPE haproxy_server_sessions_total gauge
73+
# TYPE haproxy_server_sessions_total counter
7474
haproxy_server_sessions_total{backend="foo",server="BACKEND"} 0
7575
haproxy_server_sessions_total{backend="foo",server="FRONTEND"} 0
7676
haproxy_server_sessions_total{backend="foo",server="foo-instance-0"} 0

test/server_broken_csv.metrics

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# HELP haproxy_exporter_csv_parse_failures Number of errors while parsing CSV.
2-
# TYPE haproxy_exporter_csv_parse_failures counter
3-
haproxy_exporter_csv_parse_failures 1
4-
# HELP haproxy_exporter_total_scrapes Current total HAProxy scrapes.
5-
# TYPE haproxy_exporter_total_scrapes counter
6-
haproxy_exporter_total_scrapes 1
1+
# HELP haproxy_exporter_csv_parse_failures_total Number of errors while parsing CSV.
2+
# TYPE haproxy_exporter_csv_parse_failures_total counter
3+
haproxy_exporter_csv_parse_failures_total 1
4+
# HELP haproxy_exporter_scrapes_total Current total HAProxy scrapes.
5+
# TYPE haproxy_exporter_scrapes_total counter
6+
haproxy_exporter_scrapes_total 1
77
# HELP haproxy_server_bytes_in_total Current total of incoming bytes.
8-
# TYPE haproxy_server_bytes_in_total gauge
8+
# TYPE haproxy_server_bytes_in_total counter
99
haproxy_server_bytes_in_total{backend="foo",server="BACKEND"} 0
1010
haproxy_server_bytes_in_total{backend="foo",server="FRONTEND"} 0
1111
haproxy_server_bytes_in_total{backend="foo",server="foo-instance-0"} 0
1212
# HELP haproxy_server_bytes_out_total Current total of outgoing bytes.
13-
# TYPE haproxy_server_bytes_out_total gauge
13+
# TYPE haproxy_server_bytes_out_total counter
1414
haproxy_server_bytes_out_total{backend="foo",server="BACKEND"} 0
1515
haproxy_server_bytes_out_total{backend="foo",server="FRONTEND"} 0
1616
haproxy_server_bytes_out_total{backend="foo",server="foo-instance-0"} 0
@@ -20,17 +20,17 @@ haproxy_server_check_duration_milliseconds{backend="foo",server="BACKEND"} 0
2020
haproxy_server_check_duration_milliseconds{backend="foo",server="FRONTEND"} 0
2121
haproxy_server_check_duration_milliseconds{backend="foo",server="foo-instance-0"} 0
2222
# HELP haproxy_server_check_failures_total Total number of failed health checks.
23-
# TYPE haproxy_server_check_failures_total gauge
23+
# TYPE haproxy_server_check_failures_total counter
2424
haproxy_server_check_failures_total{backend="foo",server="BACKEND"} 0
2525
haproxy_server_check_failures_total{backend="foo",server="FRONTEND"} 0
2626
haproxy_server_check_failures_total{backend="foo",server="foo-instance-0"} 0
2727
# HELP haproxy_server_client_aborts_total Total number of data transfers aborted by the client.
28-
# TYPE haproxy_server_client_aborts_total gauge
28+
# TYPE haproxy_server_client_aborts_total counter
2929
haproxy_server_client_aborts_total{backend="foo",server="BACKEND"} 0
3030
haproxy_server_client_aborts_total{backend="foo",server="FRONTEND"} 0
3131
haproxy_server_client_aborts_total{backend="foo",server="foo-instance-0"} 0
3232
# HELP haproxy_server_connection_errors_total Total of connection errors.
33-
# TYPE haproxy_server_connection_errors_total gauge
33+
# TYPE haproxy_server_connection_errors_total counter
3434
haproxy_server_connection_errors_total{backend="foo",server="BACKEND"} 0
3535
haproxy_server_connection_errors_total{backend="foo",server="FRONTEND"} 0
3636
haproxy_server_connection_errors_total{backend="foo",server="foo-instance-0"} 0
@@ -50,7 +50,7 @@ haproxy_server_current_sessions{backend="foo",server="BACKEND"} 0
5050
haproxy_server_current_sessions{backend="foo",server="FRONTEND"} 0
5151
haproxy_server_current_sessions{backend="foo",server="foo-instance-0"} 0
5252
# HELP haproxy_server_downtime_seconds_total Total downtime in seconds.
53-
# TYPE haproxy_server_downtime_seconds_total gauge
53+
# TYPE haproxy_server_downtime_seconds_total counter
5454
haproxy_server_downtime_seconds_total{backend="foo",server="BACKEND"} 0
5555
haproxy_server_downtime_seconds_total{backend="foo",server="FRONTEND"} 0
5656
haproxy_server_downtime_seconds_total{backend="foo",server="foo-instance-0"} 0
@@ -70,32 +70,32 @@ haproxy_server_max_sessions{backend="foo",server="BACKEND"} 0
7070
haproxy_server_max_sessions{backend="foo",server="FRONTEND"} 0
7171
haproxy_server_max_sessions{backend="foo",server="foo-instance-0"} 0
7272
# HELP haproxy_server_redispatch_warnings_total Total of redispatch warnings.
73-
# TYPE haproxy_server_redispatch_warnings_total gauge
73+
# TYPE haproxy_server_redispatch_warnings_total counter
7474
haproxy_server_redispatch_warnings_total{backend="foo",server="BACKEND"} 0
7575
haproxy_server_redispatch_warnings_total{backend="foo",server="FRONTEND"} 0
7676
haproxy_server_redispatch_warnings_total{backend="foo",server="foo-instance-0"} 0
7777
# HELP haproxy_server_response_errors_total Total of response errors.
78-
# TYPE haproxy_server_response_errors_total gauge
78+
# TYPE haproxy_server_response_errors_total counter
7979
haproxy_server_response_errors_total{backend="foo",server="BACKEND"} 0
8080
haproxy_server_response_errors_total{backend="foo",server="FRONTEND"} 0
8181
haproxy_server_response_errors_total{backend="foo",server="foo-instance-0"} 0
8282
# HELP haproxy_server_retry_warnings_total Total of retry warnings.
83-
# TYPE haproxy_server_retry_warnings_total gauge
83+
# TYPE haproxy_server_retry_warnings_total counter
8484
haproxy_server_retry_warnings_total{backend="foo",server="BACKEND"} 0
8585
haproxy_server_retry_warnings_total{backend="foo",server="FRONTEND"} 0
8686
haproxy_server_retry_warnings_total{backend="foo",server="foo-instance-0"} 0
8787
# HELP haproxy_server_server_aborts_total Total number of data transfers aborted by the server.
88-
# TYPE haproxy_server_server_aborts_total gauge
88+
# TYPE haproxy_server_server_aborts_total counter
8989
haproxy_server_server_aborts_total{backend="foo",server="BACKEND"} 0
9090
haproxy_server_server_aborts_total{backend="foo",server="FRONTEND"} 0
9191
haproxy_server_server_aborts_total{backend="foo",server="foo-instance-0"} 0
9292
# HELP haproxy_server_server_selected_total Total number of times a server was selected, either for new sessions, or when re-dispatching.
93-
# TYPE haproxy_server_server_selected_total gauge
93+
# TYPE haproxy_server_server_selected_total counter
9494
haproxy_server_server_selected_total{backend="foo",server="BACKEND"} 0
9595
haproxy_server_server_selected_total{backend="foo",server="FRONTEND"} 0
9696
haproxy_server_server_selected_total{backend="foo",server="foo-instance-0"} 0
9797
# HELP haproxy_server_sessions_total Total number of sessions.
98-
# TYPE haproxy_server_sessions_total gauge
98+
# TYPE haproxy_server_sessions_total counter
9999
haproxy_server_sessions_total{backend="foo",server="BACKEND"} 0
100100
haproxy_server_sessions_total{backend="foo",server="FRONTEND"} 0
101101
haproxy_server_sessions_total{backend="foo",server="foo-instance-0"} 0

test/server_without_checks.metrics

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
# HELP haproxy_exporter_csv_parse_failures Number of errors while parsing CSV.
2-
# TYPE haproxy_exporter_csv_parse_failures counter
3-
haproxy_exporter_csv_parse_failures 0
4-
# HELP haproxy_exporter_total_scrapes Current total HAProxy scrapes.
5-
# TYPE haproxy_exporter_total_scrapes counter
6-
haproxy_exporter_total_scrapes 1
1+
# HELP haproxy_exporter_csv_parse_failures_total Number of errors while parsing CSV.
2+
# TYPE haproxy_exporter_csv_parse_failures_total counter
3+
haproxy_exporter_csv_parse_failures_total 0
4+
# HELP haproxy_exporter_scrapes_total Current total HAProxy scrapes.
5+
# TYPE haproxy_exporter_scrapes_total counter
6+
haproxy_exporter_scrapes_total 1
77
# HELP haproxy_server_bytes_in_total Current total of incoming bytes.
8-
# TYPE haproxy_server_bytes_in_total gauge
8+
# TYPE haproxy_server_bytes_in_total counter
99
haproxy_server_bytes_in_total{backend="test",server="127.0.0.1:8080"} 0
1010
# HELP haproxy_server_bytes_out_total Current total of outgoing bytes.
11-
# TYPE haproxy_server_bytes_out_total gauge
11+
# TYPE haproxy_server_bytes_out_total counter
1212
haproxy_server_bytes_out_total{backend="test",server="127.0.0.1:8080"} 0
1313
# HELP haproxy_server_check_failures_total Total number of failed health checks.
14-
# TYPE haproxy_server_check_failures_total gauge
14+
# TYPE haproxy_server_check_failures_total counter
1515
haproxy_server_check_failures_total{backend="test",server="127.0.0.1:8080"} 0
1616
# HELP haproxy_server_client_aborts_total Total number of data transfers aborted by the client.
17-
# TYPE haproxy_server_client_aborts_total gauge
17+
# TYPE haproxy_server_client_aborts_total counter
1818
haproxy_server_client_aborts_total{backend="test",server="127.0.0.1:8080"} 0
1919
# HELP haproxy_server_connection_errors_total Total of connection errors.
20-
# TYPE haproxy_server_connection_errors_total gauge
20+
# TYPE haproxy_server_connection_errors_total counter
2121
haproxy_server_connection_errors_total{backend="test",server="127.0.0.1:8080"} 0
2222
# HELP haproxy_server_current_queue Current number of queued requests assigned to this server.
2323
# TYPE haproxy_server_current_queue gauge
@@ -29,10 +29,10 @@ haproxy_server_current_session_rate{backend="test",server="127.0.0.1:8080"} 0
2929
# TYPE haproxy_server_current_sessions gauge
3030
haproxy_server_current_sessions{backend="test",server="127.0.0.1:8080"} 0
3131
# HELP haproxy_server_downtime_seconds_total Total downtime in seconds.
32-
# TYPE haproxy_server_downtime_seconds_total gauge
32+
# TYPE haproxy_server_downtime_seconds_total counter
3333
haproxy_server_downtime_seconds_total{backend="test",server="127.0.0.1:8080"} 0
3434
# HELP haproxy_server_http_responses_total Total of HTTP responses.
35-
# TYPE haproxy_server_http_responses_total gauge
35+
# TYPE haproxy_server_http_responses_total counter
3636
haproxy_server_http_responses_total{backend="test",code="1xx",server="127.0.0.1:8080"} 0
3737
haproxy_server_http_responses_total{backend="test",code="2xx",server="127.0.0.1:8080"} 0
3838
haproxy_server_http_responses_total{backend="test",code="3xx",server="127.0.0.1:8080"} 0
@@ -52,22 +52,22 @@ haproxy_server_max_session_rate{backend="test",server="127.0.0.1:8080"} 0
5252
# TYPE haproxy_server_max_sessions gauge
5353
haproxy_server_max_sessions{backend="test",server="127.0.0.1:8080"} 0
5454
# HELP haproxy_server_redispatch_warnings_total Total of redispatch warnings.
55-
# TYPE haproxy_server_redispatch_warnings_total gauge
55+
# TYPE haproxy_server_redispatch_warnings_total counter
5656
haproxy_server_redispatch_warnings_total{backend="test",server="127.0.0.1:8080"} 0
5757
# HELP haproxy_server_response_errors_total Total of response errors.
58-
# TYPE haproxy_server_response_errors_total gauge
58+
# TYPE haproxy_server_response_errors_total counter
5959
haproxy_server_response_errors_total{backend="test",server="127.0.0.1:8080"} 0
6060
# HELP haproxy_server_retry_warnings_total Total of retry warnings.
61-
# TYPE haproxy_server_retry_warnings_total gauge
61+
# TYPE haproxy_server_retry_warnings_total counter
6262
haproxy_server_retry_warnings_total{backend="test",server="127.0.0.1:8080"} 0
6363
# HELP haproxy_server_server_aborts_total Total number of data transfers aborted by the server.
64-
# TYPE haproxy_server_server_aborts_total gauge
64+
# TYPE haproxy_server_server_aborts_total counter
6565
haproxy_server_server_aborts_total{backend="test",server="127.0.0.1:8080"} 0
6666
# HELP haproxy_server_server_selected_total Total number of times a server was selected, either for new sessions, or when re-dispatching.
67-
# TYPE haproxy_server_server_selected_total gauge
67+
# TYPE haproxy_server_server_selected_total counter
6868
haproxy_server_server_selected_total{backend="test",server="127.0.0.1:8080"} 0
6969
# HELP haproxy_server_sessions_total Total number of sessions.
70-
# TYPE haproxy_server_sessions_total gauge
70+
# TYPE haproxy_server_sessions_total counter
7171
haproxy_server_sessions_total{backend="test",server="127.0.0.1:8080"} 0
7272
# HELP haproxy_server_up Current health status of the server (1 = UP, 0 = DOWN).
7373
# TYPE haproxy_server_up gauge

0 commit comments

Comments
 (0)