ofesseler / gluster_exporter

Gluster Exporter for Prometheus
Apache License 2.0
81 stars 57 forks source link

Added parsing for hostname #32

Closed ghanendaghestani closed 6 years ago

ghanendaghestani commented 6 years ago

main.go has the following condition before collecting cumulative data in line 279: if strings.HasPrefix(brick.BrickName, e.hostname)

In our case, VM has hostname as FQDN 'somehost.somedomain.tld'. However, gluster volumes have prefix somehost instead of FQDN. gluster volume info Bricks: Brick1: somehost:/var/data/brick1/gv1 Brick2: somehost:/var/data/brick1/gv1 # This is why condition is not met and profiling metrics are not scrapped. Solution is to add regex after retrieving hostname and parse only first part of the hostname. Following was added hostnameH, err := os.Hostname() var validval = regexp.MustCompile("[a-zA-Z0-9]*") hostnameE := validval.FindStringSubmatch(hostnameH) hostname := hostnameE[0]

Such case should be also considered.

ofesseler commented 6 years ago

Thanks for your PR, this is a very useful improvement. Please change your PR to fully support valid hostnames defined by [1] and [2]. A IMHO working Regex can be found on stackoverflow [3].

[1] https://tools.ietf.org/html/rfc952 [2] https://tools.ietf.org/html/rfc1123 [3] https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address#106223

ghanendaghestani commented 6 years ago

Thanks for your review and feedback. The Regex was specific for hostnames in my infra. Updated, the regexp to support valid hostnames as per [1] and [2]

ofesseler commented 6 years ago

thanks for your fast work!