GithubHelp home page GithubHelp logo

neuvector / prometheus-exporter Goto Github PK

View Code? Open in Web Editor NEW
17.0 4.0 27.0 4.26 MB

Prometheus exporter and Grafana template for NeuVector container security platform

License: Apache License 2.0

Python 98.10% Dockerfile 1.44% Shell 0.46%

prometheus-exporter's Introduction

Prometheus exporter and Grafana template

NV_Exporter Setup:

To run the exporter as Python program

  • Clone the repository
  • Make sure you installed Python 3 and python3-pip:
$ sudo apt-get install python3
$ sudo apt-get install python3-pip
  • Install the Prometheus Python client:
$ sudo pip3 install -U setuptools
$ sudo pip3 install -U pip
$ sudo pip3 install prometheus_client requests

To run the exporter and prometheus as a container

It's easier to start NeuVector exporter as a container. The following section describe how to start the exporter in the Docker environment. A kubernetes sample yaml file, nv_exporter.yml, is also included.

Modify both docker-compose.yml and nv_exporter.yml. Specify NeuVector controller's RESTful API endpoint CTRL_API_SERVICE, login username CTRL_USERNAME, password CTRL_PASSWORD, and the port that the export listens on through environment variables EXPORTER_PORT. Optionally, you can also specify EXPORTER_METRICS to a comma-separated list of metric groups to collect and export. It's highly recommanded to create a read-only user account for the exporter.

Metric groups:

  • summary - overall NeuVector status
  • conversation - total bytes for every conversation between workloads
  • enforcer - enforcer CPU and memory usage
  • host - host memory usage
  • admission - number of allowed and denied Kubernetes admission requests
  • image_vulnerability - number of high and medium vulnerabilities for every scanned registry image
  • container_vulnerability - number of high and medium vulnerabilities for every service, reporting a single pod's status per service (excluding service mesh sidecars)
  • log - data for the latest threat, incident, and violation logs (latest 5 logs each)
Environment Variables
Variable Description Default
CTRL_API_SERVICE NeuVector controller REST API service endpoint nil
CTRL_USERNAME Username to login to controller REST API service admin
CTRL_PASSWORD Password to login to controller REST API service admin
EXPORTER_PORT The port that the export is listening on nil
ENFORCER_STATS For the performance reason, by default the exporter does NOT pull CPU/memory usage from enforcers. Enable this if you want to see the metrix in the dashboard 0
In native docker environment

Start NeuVector exporter container.

$ docker-compose up -d
  • Open browser, go to: [exporter_host:exporter_port] (example: localbost:8068)
  • If you can load the metric page, the exporter is working fine.

Add and modify the exporter target in your prometheus.yml file under scrape_configs:

scrape_configs:
  - job_name: prometheus
    scrape_interval: 10s
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: nv-exporter
    scrape_interval: 30s
    static_configs:
      - targets: ["neuvector-svc-prometheus-exporter.neuvector:8068"]

Start Prometheus container.

$ docker run -itd -p 9090:9090 -v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus prom/prometheus
  • After deployed Prometheus, open browser and go to: [prometheus_host:9090] (example: localhost:9090)
  • On the top bar go to Status -> Targets to check exporter status. If the name is blue and State is UP, the exporter is running and Prometheus is successfully connected to the exporter.
  • On the top bar go to Graph and in the Expression box type nv to view all the metrics the exporter has.
In Kubernetes

Start NeuVector exporter pod and service.

$ kubectl create -f nv_exporter.yml

Create configMap for Prometheus scrape_configs.

$ kubectl create cm prometheus-cm --from-file prom-config.yml

Start Prometheus pod and service.

$ kubectl create -f prometheus.yml

Grafana Setup:

  • Start Grafana container. "docker run" example,
$ sudo docker run -d -p 3000:3000 --name grafana grafana/grafana
  • After deployed Grafana, open browser and go to: [grafana_host:3000] (example: localhost:3000)
  • Login and add Prometheus data source from Configurations -> Data Sources
  • find the + on the left bar, select Import. Upload NeuVector dashboard templet JSON file.

Metrics

Metrics Comment
nv_summary_services Number of services
nv_summary_policy Number of network policies
nv_summary_pods Number of pods
nv_summary_runningWorkloads Number of running containers
nv_summary_totalWorkloads Total number of containers
nv_summary_hosts Number of hosts
nv_summary_controllers Number of controllers
nv_summary_enforcers Number of enforcers
nv_summary_disconnectedEnforcers Number of disconnected enforcers
nv_summary_cvedbTime Vulnerability database build time
nv_summary_cvedbVersion Vulnerability database version
nv_host_memory Memory usage of nodes (by node id)
nv_controller_cpu CPU usage of controllers (by controller id)
nv_controller_memory Memory usage of controllers (by controller id)
nv_enforcer_cpu CPU usage of enforcers (by enforcer id)
nv_enforcer_memory Memory usage of enforcers (by enforcer id)
nv_conversation_bytes Network bandwidth of applications
nv_admission_allowed Number of allowed admission control requests
nv_admission_denied Number of denied admission control requests
nv_image_vulnerabilityHigh Number of vulnerabilities of high severity (by image id)
nv_image_vulnerabilityMedium Number of vulnerabilities of medium severity (by image id)
nv_container_vulnerabilityHigh Number of vulnerabilities of high severity (by service name)
nv_container_vulnerabilityMedium Number of vulnerabilities of medium severity (by service name)
nv_log_events Lists of security events
nv_fed_master Shows the status of all the connected clusters to the federated master
nv_fed_worker Shows the status of the cluster to the federated master

prometheus-exporter's People

Contributors

achdevelop avatar achdevops avatar agcalin avatar becitsthere avatar dtzwylb avatar garyduan avatar rogue5oul avatar theobori avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

prometheus-exporter's Issues

Add namespace label

Hello,

We are building reporting based on this exporter and we need to be able to group metrics. Namespace should be a good start for this.

Best,

Matthieu

exporter stops responding properly to scraping after a while

Context is the same as #8

After a while, the exporter starts hitting an exception on every scrape :

 ----------------------------------------
 Exception happened during processing of request from ('10.42.6.76', 51088)
 Traceback (most recent call last):
   File "/usr/lib/python3.7/socketserver.py", line 650, in process_request_thread
     self.finish_request(request, client_address)
   File "/usr/lib/python3.7/socketserver.py", line 360, in finish_request
     self.RequestHandlerClass(request, client_address, self)
   File "/usr/lib/python3.7/socketserver.py", line 720, in __init__
     self.handle()
   File "/usr/lib/python3.7/http/server.py", line 426, in handle
     self.handle_one_request()
   File "/usr/lib/python3.7/http/server.py", line 414, in handle_one_request
     method()
   File "/usr/lib/python3.7/site-packages/prometheus_client/exposition.py", line 152, in do_GET
     output = encoder(registry)
   File "/usr/lib/python3.7/site-packages/prometheus_client/openmetrics/exposition.py", line 14, in generate_latest
     for metric in registry.collect():
   File "/usr/lib/python3.7/site-packages/prometheus_client/registry.py", line 75, in collect
     for metric in collector.collect():
   File "/usr/local/bin/nv_exporter.py", line 42, in collect
     value=sjson["summary"]["services"],
 KeyError: 'summary'
 ----------------------------------------

This happens after maybe 12h of operation or so. Happy to provide any extra context that could be useful for debugging.

exporter hitting exceptions when parsing data from neuvector API

We're using the neuvector prometheus exporter to expose the container scanning data into our monitoring infrastructure (p8s + grafana). It seems to work but it keeps reporting this exception in the logs over and over.

----------------------------------------
 Exception happened during processing of request from ('10.42.6.76', 54776)
 Traceback (most recent call last):
   File "/usr/lib/python3.7/socketserver.py", line 650, in process_request_thread
     self.finish_request(request, client_address)
   File "/usr/lib/python3.7/socketserver.py", line 360, in finish_request
     self.RequestHandlerClass(request, client_address, self)
   File "/usr/lib/python3.7/socketserver.py", line 720, in __init__
     self.handle()
   File "/usr/lib/python3.7/http/server.py", line 426, in handle
     self.handle_one_request()
   File "/usr/lib/python3.7/http/server.py", line 414, in handle_one_request
     method()
   File "/usr/lib/python3.7/site-packages/prometheus_client/exposition.py", line 152, in do_GET
     output = encoder(registry)
   File "/usr/lib/python3.7/site-packages/prometheus_client/openmetrics/exposition.py", line 14, in generate_latest
     for metric in registry.collect():
   File "/usr/lib/python3.7/site-packages/prometheus_client/registry.py", line 75, in collect
     self.finish_request(request, client_address)
   File "/usr/lib/python3.7/socketserver.py", line 360, in finish_request
     self.RequestHandlerClass(request, client_address, self)
   File "/usr/lib/python3.7/socketserver.py", line 720, in __init__
     self.handle()
   File "/usr/lib/python3.7/http/server.py", line 426, in handle
     self.handle_one_request()
   File "/usr/lib/python3.7/http/server.py", line 414, in handle_one_request
     method()
   File "/usr/lib/python3.7/site-packages/prometheus_client/exposition.py", line 152, in do_GET
     output = encoder(registry)
   File "/usr/lib/python3.7/site-packages/prometheus_client/openmetrics/exposition.py", line 14, in generate_latest
     for metric in registry.collect():
   File "/usr/lib/python3.7/site-packages/prometheus_client/registry.py", line 75, in collect
     for metric in collector.collect():
   File "/usr/local/bin/nv_exporter.py", line 84, in collect
     0] + ':' + dt3[1] + ':' + dt4[0] + ap
 TypeError: can only concatenate str (not "int") to str
 ----------------------------------------

Not sure what this indicates but it seems that not all data provided in the neuvector API is getting exposed as p8s metrics.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.