-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ Tested with `AIX 7.2` on `IBM POWER 9` | |
|
||
Collectors: | ||
|
||
- cpu | ||
- cpu | ||
- memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2015 The Prometheus Authors | ||
// Licensed 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. | ||
|
||
package collector | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/common/log" | ||
) | ||
|
||
const ( | ||
memInfoSubsystem = "memory" | ||
) | ||
|
||
type meminfoCollector struct{} | ||
|
||
func init() { | ||
registerCollector("meminfo", true, NewMeminfoCollector) | ||
} | ||
|
||
// NewMeminfoCollector returns a new Collector exposing memory stats. | ||
func NewMeminfoCollector() (Collector, error) { | ||
return &meminfoCollector{}, nil | ||
} | ||
|
||
// Update calls (*meminfoCollector).getMemInfo to get the platform specific | ||
// memory metrics. | ||
func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { | ||
var metricType prometheus.ValueType | ||
memInfo, err := c.getMemInfo() | ||
if err != nil { | ||
return fmt.Errorf("couldn't get meminfo: %s", err) | ||
} | ||
log.Debugf("Set node_mem: %#v", memInfo) | ||
for k, v := range memInfo { | ||
if strings.HasSuffix(k, "_total") { | ||
metricType = prometheus.CounterValue | ||
} else { | ||
metricType = prometheus.GaugeValue | ||
} | ||
ch <- prometheus.MustNewConstMetric( | ||
prometheus.NewDesc( | ||
prometheus.BuildFQName(namespace, memInfoSubsystem, k), | ||
fmt.Sprintf("Memory information field %s.", k), | ||
nil, nil, | ||
), | ||
metricType, v, | ||
) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package collector | ||
|
||
/* | ||
#cgo LDFLAGS: -lperfstat | ||
#include <stdio.h> | ||
#include <libperfstat.h> | ||
#include <stdlib.h> | ||
int getMemInfo(perfstat_memory_total_t *mem_now) { | ||
int rc; | ||
rc = perfstat_memory_total(NULL, mem_now, sizeof(perfstat_memory_total_t), 1); | ||
if (rc <= 0 ) { | ||
return rc; | ||
} | ||
return 0; | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
"fmt" | ||
"unsafe" | ||
) | ||
|
||
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) { | ||
|
||
var memnow C.perfstat_memory_total_t | ||
|
||
if _, err := C.getMemInfo(&memnow); err != nil { | ||
return nil, fmt.Errorf("could not collect memory from getMemInfo: %v", err) | ||
} | ||
defer C.free(unsafe.Pointer(&memnow)) | ||
|
||
// perfstat_memory_total returns data in number of 4k pages | ||
ps := float64(4000) | ||
return map[string]float64{ | ||
"real_total_bytes": ps * float64(memnow.real_total), | ||
"real_free_bytes": ps * float64(memnow.real_free), | ||
"real_pinned_bytes": ps * float64(memnow.real_pinned), | ||
"real_inuse_bytes": ps * float64(memnow.real_inuse), | ||
"real_system_bytes": ps * float64(memnow.real_system), | ||
"real_user_bytes": ps * float64(memnow.real_user), | ||
"real_process_bytes": ps * float64(memnow.real_process), | ||
"real_avail_bytes": ps * float64(memnow.real_avail), | ||
"virt_total_bytes": ps * float64(memnow.virt_total), | ||
"virt_active_bytes": ps * float64(memnow.virt_active), | ||
}, nil | ||
|
||
} |