Skip to content

Commit

Permalink
Merge pull request #27 from newrelic/extra-id-attributes
Browse files Browse the repository at this point in the history
Added DBID and global name to all entities as attributes
  • Loading branch information
camdencheek authored Nov 20, 2018
2 parents 65a34dd + bc21e61 commit 19fc4f3
Show file tree
Hide file tree
Showing 5 changed files with 474 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.1.0 - 2018-11-20
### Added
- DBID and Global Name to all entities

## 1.0.0 - 2018-11-16
### Changed
- Updated to version 1.0.0
Expand Down
228 changes: 228 additions & 0 deletions src/metric_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,234 @@ var oracleTablespaceMetrics = oracleMetricGroup{
},
}

var globalNameInstanceMetric = oracleMetricGroup{
sqlQuery: func() string {
query := `SELECT
t1.INST_ID,
t2.GLOBAL_NAME
FROM (SELECT INST_ID FROM gv$instance) t1,
(SELECT GLOBAL_NAME FROM global_name) t2`
return query
},

metrics: []*oracleMetric{
{
name: "globalName",
identifier: "GLOBAL_NAME",
metricType: metric.ATTRIBUTE,
defaultMetric: true,
},
},

metricsGenerator: func(rows *sql.Rows, metrics []*oracleMetric, metricChan chan<- newrelicMetricSender) error {

type pgaRow struct {
instID int
value string
}
for rows.Next() {

// Scan the row into a struct
var tempPgaRow pgaRow
err := rows.Scan(&tempPgaRow.instID, &tempPgaRow.value)
if err != nil {
return err
}

// Match the metric to one of the metrics we want to collect
for _, metric := range metrics {
if metric.defaultMetric || args.ExtendedMetrics {
newMetric := &newrelicMetric{
name: metric.name,
value: tempPgaRow.value,
metricType: metric.metricType,
}

metadata := map[string]string{"instanceID": strconv.Itoa(tempPgaRow.instID)}

// Send the new metric down the channel
metricChan <- newrelicMetricSender{metric: newMetric, metadata: metadata}
break

}
}
}

return nil
},
}

var globalNameTablespaceMetric = oracleMetricGroup{
sqlQuery: func() string {
query := `SELECT
t1.TABLESPACE_NAME,
t2.GLOBAL_NAME
FROM (SELECT TABLESPACE_NAME FROM DBA_TABLESPACES) t1,
(SELECT GLOBAL_NAME FROM global_name) t2`
return query
},

metrics: []*oracleMetric{
{
name: "globalName",
identifier: "GLOBAL_NAME",
metricType: metric.ATTRIBUTE,
defaultMetric: true,
},
},

metricsGenerator: func(rows *sql.Rows, metrics []*oracleMetric, metricChan chan<- newrelicMetricSender) error {

type pgaRow struct {
tableName string
value string
}
for rows.Next() {

// Scan the row into a struct
var tempPgaRow pgaRow
err := rows.Scan(&tempPgaRow.tableName, &tempPgaRow.value)
if err != nil {
return err
}

// Match the metric to one of the metrics we want to collect
for _, metric := range metrics {
if metric.defaultMetric || args.ExtendedMetrics {
newMetric := &newrelicMetric{
name: metric.name,
value: tempPgaRow.value,
metricType: metric.metricType,
}

metadata := map[string]string{"tablespace": tempPgaRow.tableName}

// Send the new metric down the channel
metricChan <- newrelicMetricSender{metric: newMetric, metadata: metadata}
break

}
}
}

return nil
},
}

var dbIDInstanceMetric = oracleMetricGroup{
sqlQuery: func() string {
query := `SELECT
t1.INST_ID,
t2.DBID
FROM (SELECT INST_ID FROM gv$instance) t1,
(SELECT DBID FROM v$database) t2`
return query
},

metrics: []*oracleMetric{
{
name: "dbID",
identifier: "DBID",
metricType: metric.ATTRIBUTE,
defaultMetric: true,
},
},

metricsGenerator: func(rows *sql.Rows, metrics []*oracleMetric, metricChan chan<- newrelicMetricSender) error {

type pgaRow struct {
instID int
value string
}
for rows.Next() {

// Scan the row into a struct
var tempPgaRow pgaRow
err := rows.Scan(&tempPgaRow.instID, &tempPgaRow.value)
if err != nil {
return err
}

// Match the metric to one of the metrics we want to collect
for _, metric := range metrics {
if metric.defaultMetric || args.ExtendedMetrics {
newMetric := &newrelicMetric{
name: metric.name,
value: tempPgaRow.value,
metricType: metric.metricType,
}

metadata := map[string]string{"instanceID": strconv.Itoa(tempPgaRow.instID)}

// Send the new metric down the channel
metricChan <- newrelicMetricSender{metric: newMetric, metadata: metadata}
break

}
}
}

return nil
},
}

var dbIDTablespaceMetric = oracleMetricGroup{
sqlQuery: func() string {
query := `SELECT
t1.TABLESPACE_NAME,
t2.DBID
FROM (SELECT TABLESPACE_NAME FROM DBA_TABLESPACES) t1,
(SELECT DBID FROM v$database) t2`
return query
},

metrics: []*oracleMetric{
{
name: "dbID",
identifier: "DBID",
metricType: metric.ATTRIBUTE,
defaultMetric: true,
},
},

metricsGenerator: func(rows *sql.Rows, metrics []*oracleMetric, metricChan chan<- newrelicMetricSender) error {

type pgaRow struct {
tableName string
value string
}
for rows.Next() {

// Scan the row into a struct
var tempPgaRow pgaRow
err := rows.Scan(&tempPgaRow.tableName, &tempPgaRow.value)
if err != nil {
return err
}

// Match the metric to one of the metrics we want to collect
for _, metric := range metrics {
if metric.defaultMetric || args.ExtendedMetrics {
newMetric := &newrelicMetric{
name: metric.name,
value: tempPgaRow.value,
metricType: metric.metricType,
}

metadata := map[string]string{"tablespace": tempPgaRow.tableName}

// Send the new metric down the channel
metricChan <- newrelicMetricSender{metric: newMetric, metadata: metadata}
break

}
}
}

return nil
},
}

var oracleReadWriteMetrics = oracleMetricGroup{
sqlQuery: func() string {
return `
Expand Down
9 changes: 7 additions & 2 deletions src/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ func collectMetrics(db *sql.DB, populaterWg *sync.WaitGroup, i *integration.Inte
metricChan := make(chan newrelicMetricSender, 100) // large buffer for speed

// Create a goroutine for each of the metric groups to collect
collectorWg.Add(3)
collectorWg.Add(5)
go oracleReadWriteMetrics.Collect(db, &collectorWg, metricChan)
go oraclePgaMetrics.Collect(db, &collectorWg, metricChan)
go oracleSysMetrics.Collect(db, &collectorWg, metricChan)
go globalNameInstanceMetric.Collect(db, &collectorWg, metricChan)
go dbIDInstanceMetric.Collect(db, &collectorWg, metricChan)

// Separate logic is needed to see if we should even collect tablespaces
collectTableSpaces(db, &collectorWg, metricChan)
Expand Down Expand Up @@ -131,8 +133,11 @@ func collectTableSpaces(db *sql.DB, wg *sync.WaitGroup, metricChan chan<- newrel
return
}

wg.Add(1)
wg.Add(3)
go oracleTablespaceMetrics.Collect(db, wg, metricChan)
go globalNameTablespaceMetric.Collect(db, wg, metricChan)
go dbIDTablespaceMetric.Collect(db, wg, metricChan)

}

func queryNumTablespaces(db *sql.DB) (int, error) {
Expand Down
Loading

0 comments on commit 19fc4f3

Please sign in to comment.