This commit is contained in:
Calle Pettersson 2018-04-05 07:11:36 +02:00
parent cf792394f3
commit 63e51a554b
4 changed files with 19 additions and 21 deletions

View File

@ -26,23 +26,21 @@ type Win32_PerfRawData_MSMQ_MSMQQueueCollector struct {
BytesinQueue *prometheus.Desc
MessagesinJournalQueue *prometheus.Desc
MessagesinQueue *prometheus.Desc
queryWhereClause string
}
// NewWin32_PerfRawData_MSMQ_MSMQQueueCollector ...
func NewMSMQCollector() (Collector, error) {
const subsystem = "msmq"
var wc bytes.Buffer
if *msmqWhereClause != "" {
wc.WriteString("WHERE ")
wc.WriteString(*msmqWhereClause)
log.Println("warning: No where-clause specified for msmq collector. This will generate a very large number of metrics!")
}
// else {
// log.Println("warning: No where-clause specified for msmq collector. This will generate a very large number of metrics!")
// }
return &Win32_PerfRawData_MSMQ_MSMQQueueCollector{
BytesinJournalQueue: prometheus.NewDesc(
prometheus.BuildFQName(Namespace, subsystem, "bytes_in_journal_queue"),
@ -97,7 +95,7 @@ func (c *Win32_PerfRawData_MSMQ_MSMQQueueCollector) collect(ch chan<- prometheus
if err := wmi.Query(q, &dst); err != nil {
return nil, err
}
for _, msmq := range dst {
if msmq.Name == "Computer Queues" {
@ -128,6 +126,6 @@ func (c *Win32_PerfRawData_MSMQ_MSMQQueueCollector) collect(ch chan<- prometheus
float64(msmq.MessagesinQueue),
strings.ToLower(msmq.Name),
)
}
}
return nil, nil
}

View File

@ -6,7 +6,7 @@ package collector
import (
"log"
"time"
"github.com/StackExchange/wmi"
"github.com/prometheus/client_golang/prometheus"
)
@ -27,8 +27,8 @@ type OSCollector struct {
PagingLimitBytes *prometheus.Desc
VirtualMemoryBytes *prometheus.Desc
VisibleMemoryBytes *prometheus.Desc
Time *prometheus.Desc
Timezone *prometheus.Desc
Time *prometheus.Desc
Timezone *prometheus.Desc
}
// NewOSCollector ...
@ -132,7 +132,7 @@ type Win32_OperatingSystem struct {
SizeStoredInPagingFiles uint64
TotalVirtualMemorySize uint64
TotalVisibleMemorySize uint64
LocalDateTime time.Time
LocalDateTime time.Time
}
func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, error) {
@ -148,7 +148,7 @@ func (c *OSCollector) collect(ch chan<- prometheus.Metric) (*prometheus.Desc, er
)
time := dst[0].LocalDateTime
ch <- prometheus.MustNewConstMetric(
c.Time,
prometheus.GaugeValue,

View File

@ -28,16 +28,16 @@ import (
dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/log"
kingpin "gopkg.in/alecthomas/kingpin.v2"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
textFileDirectory = kingpin.Flag(
"collector.textfile.directory",
"Directory to read text files with metrics from.",
).Default("C:\\Program Files\\wmi_exporter\\textfile_inputs").String()
textFileDirectory = kingpin.Flag(
"collector.textfile.directory",
"Directory to read text files with metrics from.",
).Default("C:\\Program Files\\wmi_exporter\\textfile_inputs").String()
mtimeDesc = prometheus.NewDesc(
mtimeDesc = prometheus.NewDesc(
"wmi_textfile_mtime_seconds",
"Unixtime mtime of textfiles successfully read.",
[]string{"file"},
@ -149,8 +149,8 @@ func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Me
buckets, values...,
)
default:
log.Errorf("unknown metric type for file")
continue
log.Errorf("unknown metric type for file")
continue
}
if metricType == dto.MetricType_GAUGE || metricType == dto.MetricType_COUNTER || metricType == dto.MetricType_UNTYPED {
ch <- prometheus.MustNewConstMetric(

View File

@ -116,7 +116,7 @@ func expandEnabledCollectors(enabled string) []string {
}
}
result := make([]string, 0, len(unique))
for s, _ := range unique {
for s := range unique {
result = append(result, s)
}
return result