FreeBSD Version of the System Module has the Uptime Metricset Disabled

I have noticed that the the FreeBSD version of metricbeat has the uptime metricset of the system module disabled (or not enabled) in the Go build tags for the metricset. Consequently, when building metricbeat on FreeBSD, the uptime metricset is not enabled & will throw errors if configured in the metricbeat configuration.

2018-12-05T00:02:02.391Z	ERROR	instance/beat.go:824	Exiting: 1 error: 1 error: metricset 'system/uptime' is not registered, metricset not found

Here is the go file for the uptime metricset:

// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.

// +build darwin linux openbsd windows

package uptime

import (
	"github.com/pkg/errors"

	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/metricbeat/mb"
	"github.com/elastic/beats/metricbeat/mb/parse"
	sigar "github.com/elastic/gosigar"
)

func init() {
	mb.Registry.MustAddMetricSet("system", "uptime", New,
		mb.WithHostParser(parse.EmptyHostParser),
		mb.DefaultMetricSet(),
	)
}

// MetricSet for fetching an OS uptime metric.
type MetricSet struct {
	mb.BaseMetricSet
}

// New is a mb.MetricSetFactory that returns a new MetricSet.
func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
	return &MetricSet{base}, nil
}

// Fetch fetches the uptime metric from the OS.
func (m *MetricSet) Fetch() (common.MapStr, error) {
	var uptime sigar.Uptime
	if err := uptime.Get(); err != nil {
		return nil, errors.Wrap(err, "failed to get uptime")
	}

	return common.MapStr{
		"duration": common.MapStr{
			"ms": int64(uptime.Length * 1000),
		},
	}, nil
}

is there any particular reason it's not enabled there? I see in gosigar's freebsd file sigar_freebsd.go that there is an uptime function using FreeBSD's clock_gettime sytem call:

func (self *Uptime) Get() error {
	ts := C.struct_timespec{}

	if _, err := C.clock_gettime(C.CLOCK_UPTIME, &ts); err != nil {
		return err
	}

	self.Length = float64(ts.tv_sec) + 1e-9*float64(ts.tv_nsec)

	return nil
}

I have enabled the build flag, built metricbeat on FreeBSD 11.2, run metricbeat, & get correct uptime events issued to logstash & stored in Elasticsearch.

    {
  "_index": "metricbeat-6.5.0-2018.49",
  "_type": "doc",
  "_id": "AoLie2cBVPJTERvK4Rmi",
  "_version": 1,
  "_score": null,
  "_source": {
    "host": {
      "name": "freebsd-11-2"
    },
    "metricset": {
      "module": "system",
      "rtt": 39,
      "name": "uptime"
    },
    "system": {
      "uptime": {
        "duration": {
          "ms": 339442389
        }
      }
    },
    "@timestamp": "2018-12-05T01:02:04.564Z",
    "tags": [
      "beats_input_raw_event"
    ],
    "beat": {
      "hostname": "freebsd-11-2",
      "version": "6.5.0",
      "name": "freebsd-11-2"
    },
    "@version": "1"
  },
  "fields": {
    "@timestamp": [
      "2018-12-05T01:02:04.564Z"
    ]
  },
  "highlight": {
    "metricset.name": [
      "@kibana-highlighted-field@uptime@/kibana-highlighted-field@"
    ]
  },
  "sort": [
    1543971724564
  ]
}

Is this an oversight, or is there a deeper reason it's not enabled for FreeBSD?

Hello! I think by default, besides system module, everything else is disabled.

I am referring to the uptime metricset, which is part of the system module. In the code, it's enabled for darwin linux openbsd, & windows, but not FreeBSD. I'm wondering why, since it appears to work fine, on FreeBSD 11 at any rate. If there isn't some underlying reason not to enable this for FreeBSD, then I believe this should be considered a bug.

@rhclayto thanks for the explanation :slight_smile: I'm glad it works! I will create a github issue to make it be enabled by default.

Thanks. Do you have a link to the Github issue? I'd like to follow it there. Or I can create an issue if you haven't already done so.

Edit:

Nevermind, found it: https://github.com/elastic/beats/pull/9413

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.