Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

Added monitoring function for link022 #81

Merged
merged 27 commits into from
Aug 17, 2018
Merged

Conversation

zhangtianyang
Copy link
Contributor

  1. Added a goroutine to periodically collect AP & system states.
  2. Added a Prometheus exporter for link022 to export states.

fixed a bug in reading cpu usage file
by forgeting reset prometheus
collector after every test.
@codecov-io
Copy link

codecov-io commented Aug 15, 2018

Codecov Report

Merging #81 into master will decrease coverage by 3.52%.
The diff coverage is 54.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #81      +/-   ##
==========================================
- Coverage      63%   59.48%   -3.53%     
==========================================
  Files          11       14       +3     
  Lines         638     1049     +411     
==========================================
+ Hits          402      624     +222     
- Misses        167      329     +162     
- Partials       69       96      +27
Impacted Files Coverage Δ
agent/service/hostapd.go 69.33% <ø> (ø) ⬆️
agent/syscmd/states.go 0% <0%> (ø)
agent/monitoring/prometheus/exposition_server.go 0% <0%> (ø)
...nt/monitoring/prometheus/openconfig_ap_exporter.go 55.91% <55.91%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 801eeeb...e5a46fe. Read the comment docs.

Copy link
Contributor

@boleifu boleifu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new files need license headers.

const (
statesUpdateDelay = 15 * time.Second
systemClockTick = 100
physicalMemoryPath = "/access-points/access-point[hostname=link022-pi-ap]/system/memory/state/physical"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not hard code host name here. It is not always link022-pi-ap. Same for the rest of paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

p := strings.Replace(selfMemPath, "$pid", spid, 1)
pbPath, err = xpath.ToGNMIPath(p)
if err != nil {
log.Errorf("convert %v to GNMI path failed: %v", p, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to log this, since it is already logged in caller function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
selfMemory, err := strconv.ParseInt(match[1], 10, 64)
if err != nil {
log.Errorf("failed convert string to int: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
stateOpt = gnmi.GNXIStateOptGenerator(pbPath, uint64(selfMemory*1024), gnmi.InternalUpdateState)
if err = s.InternalUpdate(stateOpt); err != nil {
log.Errorf("update state failed: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

log.Errorf("failed open %v: %v", filePath, err)
return err
}
cpuStr0 := strings.Split(string(b0), " ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use regex instead of doing spiting and using hard-coded index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file simply contains 52 numbers. Their positions are fixed. So it's better to find them by index.

p := strings.Replace(channelPath, "$id", phyIDStr, 1)
pbPath, err := xpath.ToGNMIPath(p)
if err != nil {
log.Errorf("convert %v to GNMI path failed: %v", p, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to log error before return. Same for others.


### Prerequisites

Dolnload entire Link022 repository.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Download

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,83 @@
# OpenConfig Telemetry Exporter (Prometheus)

This directory contains a exporter that periodically collects AP's info via gNMI and exposes converted metrics to a web page. Prometheus can monitor AP's status by scrape that web page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an exporter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1,83 @@
# OpenConfig Telemetry Exporter (Prometheus)

This directory contains a exporter that periodically collects AP's info via gNMI and exposes converted metrics to a web page. Prometheus can monitor AP's status by scrape that web page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by scraping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


var (
targetAddr = flag.String("target_addr", "localhost:10161", "The target address in the format of host:port")
targetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target name used to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@boleifu boleifu merged commit 60b75de into google:master Aug 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants