Skip to content

Commit

Permalink
Proper packaging, use CFFI and nix.
Browse files Browse the repository at this point in the history
  • Loading branch information
takeda committed Dec 9, 2018
1 parent 4ebbd90 commit 070a7ce
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 403 deletions.
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.project
.pydevproject
*.pyc
/.eggs/
/.idea/
/build/
/*.egg-info/
__pycache__/
*.c
*.o
*.pyc
*.so
build

2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include LICENSE
include mondemand_build.py
35 changes: 0 additions & 35 deletions Makefile

This file was deleted.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ REQUIREMENTS
============
* [mondemand library](https://github.com/mondemand/mondemand)
* [lwes library](https://github.com/lwes)
* [swig](https://github.com/swig/swig)

INSTALL
=======

Run `make` and `make install`.
Run `pip install .`

Example Run
===========
Expand All @@ -17,7 +16,7 @@ Start lwes-event-printing-listener to echo out all data that the lwes
receives from the mondemand client.

```shell
lwes-event-printing-listener -m 0.0.0.0 -p 42042
lwes-event-printing-listener -m 0.0.0.0 -p 10201
python demo.py
```

Expand Down
24 changes: 24 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
nixpkgs ? import <nixpkgs>,
}:

let
pkgs = nixpkgs {};
pythonPackages = pkgs.pythonPackages;
callPackage = pkgs.lib.callPackageWith (pkgs // localPkgs);
localPkgs = {
lwes = callPackage ./nix/lwes.nix {};
mondemand = callPackage ./nix/mondemand.nix {};
};
in pkgs.pythonPackages.buildPythonPackage {
pname = "mondemand";
version = "1.0.0";
src = ./.;
propagatedBuildInputs = [
localPkgs.mondemand
pythonPackages.cffi
pythonPackages.six
pythonPackages.typing
];
nativeBuildInputs = [ pkgs.pkgconfig ];
}
22 changes: 10 additions & 12 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import mondemand
from mondemand.client import MondemandClient
from mondemand.lwes_transport import LwesTransport

# create the client
client = mondemand.client_create("python_client")
client = MondemandClient("python_client")

# create a transport to send data
transport = mondemand.transport_lwes_create("127.0.0.1", 25552, None, 0, 60)
transport = LwesTransport('127.0.0.1', 10201, heartbeat_flag=0, heartbeat_frequency=60)

# attach the transport to the client
mondemand.add_transport(client, transport)
client.add_transport(transport)

# add some contextual information to the client
mondemand.set_context(client, "cluster_id", "12345")
client.set_context("cluster_id", "12345")

# set some stats
mondemand.stats_set(client, "demo.py", 1, "stat_1", 1234)
mondemand.stats_inc(client, "demo.py", 1, "stat_2", 1)
# log some stats
client.stats_set("stat_1", 1234)
client.stats_inc("stat_2", 1)

# send it to the network
mondemand.flush(client)

# send some annotations
mondemand.flush_annotation('', 1234567890, 'test', 'test desc', [], 0, client)
client.flush_stats()
Loading

0 comments on commit 070a7ce

Please sign in to comment.