Skip to content

Commit

Permalink
Adding unix socket support
Browse files Browse the repository at this point in the history
New:
 - Adding extraction of unix socket response time metrics
   which will be provided via `monit_service_port_response_times` metric.
  • Loading branch information
monofox committed Apr 14, 2024
1 parent 4281d1d commit d337a7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ These metrics are exported by `monit_exporter`:
| monit_service_mem_bytes | Monit service mem info with following labels:<br><dl><dt>`check_name`</dt><dd>Name of monit check</dd><dt>`type`</dt><dd>Specifies value type whereas value can be `kilobyte` or `kilobyte_total`</dd></dl>
| monit_service_network_link_state | Monit service link states<br><dl><dt>`check_name`</dt><dd>Name of monit check</dd></dl><br>Value can be either `-1` = Not available, `0` = down and `1` = up
| monit_service_network_link_statistics | Monit service link statistics<br><dl><dt>`check_name`</dt><dd>Name of monit check</dd><dt>`direction`</dt><dd>Specifies link direction (upload / download)</dd><dt>`unit`</dt><dd>Spcifies unit of metrics (bytes, errors, packets)</dd><dt>`type`</dt><dd>Specifies the type with either now or total. Whereas now means "per second"</dd></dl>
| monit_service_port_response_times | Monit service port checks response times<br><dl><dt>`check_name`</dt><dd>Name of monit check</dd><dt>`hostname`</dt><dd>Specifies hostname checked</dd><dt>`port`</dt><dd>Specifies port to check</dd><dt>`protocol`</dt><dd>Specifies protocol used for checking service (e.g. POP, IMAP, REDIS, etc.). Default is a RAW check.</dd><dt>`type`</dt><dd>Specifies protocol type (e.g. TCP, UDP, etc.)</dd></dl>
| monit_service_port_response_times | Monit service port and unix socket checks response times<br><dl><dt>`check_name`</dt><dd>Name of monit check</dd><dt>`hostname`</dt><dd>Specifies hostname checked</dd><dt>`path`</dt><dd>Specifies a unix socket path</dd><dt>`port`</dt><dd>Specifies port to check</dd><dt>`protocol`</dt><dd>Specifies protocol used for checking service (e.g. POP, IMAP, REDIS, etc.). Default is a RAW check.</dd><dt>`type`</dt><dd>Specifies protocol type (e.g. TCP, UDP, UNIX)</dd><dt>`uri`</dt><dd>Gives full URI for the service check including type, host and port or path.</dd></dl>
| monit_service_read_bytes | Monit service Disk Read Bytes<dl><dt>`check_name`</dt><dd>Name of monit check</dd><dt>`type`</dt><dd>Specifies type of read / write. Possible values: read_count, read_count_total. Value is given in bytes.</dd></dl>
| monit_service_write_bytes | Monit service Disk Writes Bytes<dl><dt>`check_name`</dt><dd>Name of monit check</dd><dt>`type`</dt><dd>Specifies type of read / write. Possible values: write_count, write_count_total. Value is given in bytes.</dd></dl>
| monit_up | Monit status availability. `0` = not available and `1` = available
Expand Down
24 changes: 22 additions & 2 deletions monit_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type monitService struct {
DiskRead monitServiceDisk `xml:"read"`
ServiceTimes monitServiceTime `xml:"servicetime"`
Ports []monitServicePort `xml:"port"`
UnixSockets []monitServicePort `xml:"unix"`
Link monitServiceLink `xml:"link"`
}

Expand Down Expand Up @@ -88,6 +89,7 @@ type monitServiceTime struct {

type monitServicePort struct {
Hostname string `xml:"hostname"`
Path string `xml:"path"`
Portnumber string `xml:"portnumber"`
Protocol string `xml:"protocol"`
Type string `xml:"type"`
Expand Down Expand Up @@ -273,9 +275,9 @@ func NewExporter(c *Config) (*Exporter, error) {
checkPortRespTimes: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "service_port_response_times",
Help: "Monit service port checks response times",
Help: "Monit service port and unix socket checks response times",
},
[]string{"check_name", "hostname", "port", "protocol", "type"},
[]string{"check_name", "hostname", "path", "port", "protocol", "type", "uri"},
),
checkLinkState: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Expand Down Expand Up @@ -392,13 +394,31 @@ func (e *Exporter) scrape() error {

// Port checks
for _, port := range service.Ports {
var uri = fmt.Sprintf("%s://%s:%s", strings.ToLower(port.Type), port.Hostname, port.Portnumber)
e.checkPortRespTimes.With(
prometheus.Labels{
"check_name": service.Name,
"type": port.Type,
"hostname": port.Hostname,
"path": "",
"port": port.Portnumber,
"protocol": port.Protocol,
"uri": uri,
}).Set(float64(port.Responsetime))
}

// Unix socket checks
for _, port := range service.UnixSockets {
var uri = fmt.Sprintf("unix://%s", port.Path)
e.checkPortRespTimes.With(
prometheus.Labels{
"check_name": service.Name,
"type": "UNIX",
"hostname": "",
"path": port.Path,
"port": "",
"protocol": port.Protocol,
"uri": uri,
}).Set(float64(port.Responsetime))
}
}
Expand Down

0 comments on commit d337a7d

Please sign in to comment.