Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create prometheus client #11

Merged
merged 2 commits into from
Feb 5, 2021
Merged

Create prometheus client #11

merged 2 commits into from
Feb 5, 2021

Conversation

wangchen615
Copy link
Collaborator

This PR is to solve #10 and close #10 .

There are the following major changes:

  1. The prometheus.go was added under pkg/metricsprovider with FetchAllHostsMetrics method implemented.
  2. The pkg/watcher/watcher.go was revised to support different types of clients to fill in the datasource field.
		switch reflect.TypeOf(w.client).Name() {
		case "promClient":
			go windowWatcher(duration, "Prometheus")
		case "metricsServerClient":
			go windowWatcher(duration, "k8s_metricserver")
  1. FetchHostMetrics was commented as Prometheus client does not need to fetch host metric one by one.
  2. README.md is updated to include a guide on configuring environment variables.

@wangchen615 wangchen615 added the enhancement New feature or request label Jan 25, 2021
@wangchen615 wangchen615 requested a review from zorro786 January 25, 2021 05:58
@wangchen615 wangchen615 self-assigned this Jan 25, 2021
@wangchen615
Copy link
Collaborator Author

wangchen615 commented Jan 25, 2021

A sample output of the load watcher looks like the following:

> curl -H "Content-Type: application/json" http://127.0.0.1:2020/watcher|jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1900  100  1900    0     0  1855k      0 --:--:-- --:--:-- --:--:-- 1855k
{
  "timestamp": 1612427148,
  "window": {
    "duration": "15m",
    "start": 1612426248,
    "end": 1612427148
  },
  "source": "Prometheus",
  "data": {
    "NodeMetricsMap": {
      "10.95.102.97": {
        "metrics": [
          {
            "name": "instance:node_cpu:ratio",
            "type": "CPU",
            "operator": "avg_over_time",
            "rollup": "15m",
            "value": 0.19731935228375208
          },
          {
            "name": "instance:node_memory_utilisation:ratio",
            "type": "Memory",
            "operator": "avg_over_time",
            "rollup": "15m",
            "value": 0.08354249717493203
          },
          {
            "name": "instance:node_cpu:ratio",
            "type": "CPU",
            "operator": "stddev_over_time",
            "rollup": "15m",
            "value": 0.00048452241606516646
          },
          {
            "name": "instance:node_memory_utilisation:ratio",
            "type": "Memory",
            "operator": "stddev_over_time",
            "rollup": "15m",
            "value": 0.00013245370097128003
          }
        ],
        "tags": {},
        "metadata": {
          "dataCenter": ""
        }
      },
      "10.95.102.99": {
        "metrics": [
          {
            "name": "instance:node_cpu:ratio",
            "type": "CPU",
            "operator": "avg_over_time",
            "rollup": "15m",
            "value": 0.2048283625730656
          },
          {
            "name": "instance:node_memory_utilisation:ratio",
            "type": "Memory",
            "operator": "avg_over_time",
            "rollup": "15m",
            "value": 0.09212922586804047
          },
          {
            "name": "instance:node_cpu:ratio",
            "type": "CPU",
            "operator": "stddev_over_time",
            "rollup": "15m",
            "value": 0.0005520914622929221
          },
          {
            "name": "instance:node_memory_utilisation:ratio",
            "type": "Memory",
            "operator": "stddev_over_time",
            "rollup": "15m",
            "value": 0.0001700369598327637
          }
        ],
        "tags": {},
        "metadata": {
          "dataCenter": ""
        }
      },
      "10.95.102.90": {
        "metrics": [
          {
            "name": "instance:node_cpu:ratio",
            "type": "CPU",
            "operator": "avg_over_time",
            "rollup": "15m",
            "value": 0.05814883040935881
          },
          {
            "name": "instance:node_memory_utilisation:ratio",
            "type": "Memory",
            "operator": "avg_over_time",
            "rollup": "15m",
            "value": 0.10718011619404219
          },
          {
            "name": "instance:node_cpu:ratio",
            "type": "CPU",
            "operator": "stddev_over_time",
            "rollup": "15m",
            "value": 0.00025611915450171206
          },
          {
            "name": "instance:node_memory_utilisation:ratio",
            "type": "Memory",
            "operator": "stddev_over_time",
            "rollup": "15m",
            "value": 3.1065560195209836e-05
          }
        ],
        "tags": {},
        "metadata": {
          "dataCenter": ""
        }
      }
    }
  }
}

@zorro786 zorro786 requested a review from ridv January 25, 2021 11:48
Copy link
Contributor

@zorro786 zorro786 left a comment

Choose a reason for hiding this comment

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

Please review the comments. Also, my name in the commit message is redundant 😄 - Something like "Add Prometheus client" is fine :)

Copy link
Contributor

@zorro786 zorro786 left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes @wangchen615. LGTM.

@wangchen615 wangchen615 merged commit 251e1a0 into master Feb 5, 2021
@wangchen615 wangchen615 deleted the iss10 branch February 5, 2021 04:24
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prometheus Client is Missing
2 participants